]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Expose the internal Type of Pointers through type.
[cycript.git] / Cycript.yy.in
index c4af37250847f0a1d50ebd0b700f986f716495bf..a11643f13e89573e01cd27a71c9538af67afaaf4 100644 (file)
@@ -72,6 +72,7 @@ typedef struct {
         CYInfix *infix_;
         CYLiteral *literal_;
         CYMember *member_;
+        CYModule *module_;
         CYNull *null_;
         CYNumber *number_;
         CYProgram *program_;
@@ -91,7 +92,7 @@ typedef struct {
         CYMessageParameter *messageParameter_;
         CYProtocol *protocol_;
         CYSelectorPart *selector_;
-        CYTypeModifier *type_;
+        CYTypeModifier *modifier_;
         CYTypedIdentifier *typedIdentifier_;
         CYTypedParameter *typedParameter_;
 @end
@@ -159,6 +160,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 
 @begin E4X ObjectiveC
 %token At "@"
+%token Pound "#"
 @end
 
 %token Ampersand "&"
@@ -241,6 +243,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token AtEncode "@encode"
 %token AtEnd "@end"
 %token AtSelector "@selector"
+%token <identifier_> Yes "YES"
+%token <identifier_> No "NO"
 @end
 
 %token <false_> False "false"
@@ -344,6 +348,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <argument_> ArgumentList
 %type <argument_> ArgumentListOpt
 %type <argument_> Arguments
+%type <expression_> ArrayComprehension
+%type <expression_> ArrayInitialiser
 %type <literal_> ArrayLiteral
 %type <expression_> ArrowFunction
 %type <functionParameter_> ArrowParameters
@@ -365,10 +371,10 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <clause_> CaseClause
 %type <clause_> CaseClausesOpt
 %type <catch_> CatchOpt
-%type <comprehension_> ComprehensionForList
-%type <comprehension_> ComprehensionForListOpt
-%type <comprehension_> ComprehensionList
-%type <comprehension_> ComprehensionListOpt
+%type <expression_> Comprehension
+%type <comprehension_> ComprehensionFor
+%type <comprehension_> ComprehensionIf
+%type <comprehension_> ComprehensionTail
 %type <expression_> ConditionalExpression
 %type <statement_> ContinueStatement
 %type <statement_> ConciseBody
@@ -389,7 +395,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <expression_> ExpressionOpt
 %type <statement_> ExpressionStatement
 %type <finally_> FinallyOpt
-%type <comprehension_> ForComprehension
 %type <for_> ForStatementInitialiser
 %type <forin_> ForInStatementInitialiser
 %type <declaration_> FormalParameter
@@ -402,7 +407,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <identifier_> Identifier
 %type <identifier_> IdentifierOpt
 %type <word_> IdentifierName
-%type <comprehension_> IfComprehension
 %type <statement_> IfStatement
 %type <expression_> Initialiser
 %type <expression_> InitialiserOpt
@@ -480,16 +484,16 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <protocol_> ClassProtocolListOpt
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
-%type <type_> ConcreteType
 %type <expression_> EncodedType
+%type <modifier_> FunctionedType
 %type <expression_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
 %type <messageParameter_> MessageParameterList
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
-%type <type_> ModifiedType_
-%type <type_> ModifiedType
+%type <typedIdentifier_> ModifiedType
+%type <module_> Module
 %type <typedIdentifier_> PrefixedType
 %type <expression_> PrimitiveType
 %type <argument_> SelectorCall_
@@ -502,8 +506,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <typedIdentifier_> SuffixedType
 %type <expression_> TypeOpt
 %type <typedIdentifier_> TypeParenthetical
-%type <type_> TypeQualifierLeft
-%type <type_> TypeQualifierRight
+%type <modifier_> TypeQualifierLeft
+%type <typedIdentifier_> TypeQualifierRight
 %type <typedIdentifier_> TypeSignifier
 %type <typedIdentifier_> TypedIdentifier
 %type <typedParameter_> TypedParameterList_
@@ -657,6 +661,8 @@ Identifier
 
 @begin C
     | "typedef" { $$ = $1; }
+    | "YES" { $$ = $1; }
+    | "NO" { $$ = $1; }
 @end
 
     | "implements" { $$ = $1; }
@@ -758,13 +764,19 @@ PrimaryExpression
     : "this" { $$ = $1; }
     | Variable { $$ = $1; }
     | Literal { $$ = $1; }
-    | ArrayLiteral { $$ = $1; }
+    | ArrayInitialiser { $$ = $1; }
     | ObjectLiteral { $$ = $1; }
     | Parenthetical { $$ = $1; }
     | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
     ;
 /* }}} */
-/* 11.1.4.1 Array Initialiser {{{ */
+/* 11.1.4 Array Initializer {{{ */
+ArrayInitialiser
+    : ArrayLiteral { $$ = $1; }
+    | ArrayComprehension { $$ = $1; }
+    ;
+/* }}} */
+/* 11.1.4.1 Array Literal {{{ */
 ArrayLiteral
     : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
     ;
@@ -789,19 +801,26 @@ ElementListOpt
     ;
 /* }}} */
 /* 11.1.4.2 Array Comprehension {{{ */
-PrimaryExpression
-    : "[" LexPushInOff AssignmentExpression ComprehensionForList "]" LexPopIn { $$ = CYNew CYArrayComprehension($3, $4); }
+ArrayComprehension
+    : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
     ;
 
-ComprehensionForList
-    : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); }
-    | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); }
+Comprehension
+    : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
     ;
 
-ComprehensionForListOpt
-    : ComprehensionForList { $$ = $1; }
-    | "if" Expression { $$ = CYNew CYIfComprehension($2); }
-    | { $$ = NULL; }
+ComprehensionTail
+    : { $$ = NULL; }
+    | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
+    | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
+    ;
+
+ComprehensionFor
+    : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
+    ;
+
+ComprehensionIf
+    : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
     ;
 /* }}} */
 /* 11.1.5 Object Initialiser {{{ */
@@ -1366,42 +1385,45 @@ ProgramBodyOpt
 @begin ObjectiveC
 /* Cycript (Objective-C): Type Encoding {{{ */
 TypeParenthetical
-    : "(" PrefixedType ")" { $$ = $2; }
+    : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
     ;
 
 TypeSignifier
     : Identifier { $$ = CYNew CYTypedIdentifier($1); }
-    | TypeParenthetical
+    | TypeParenthetical { $$ = $1; }
     ;
 
 ArrayedType
-    : ArrayedType "[" NumericLiteral "]" { $$ = $1; CYSetLast($$->type_) = CYNew CYTypeArrayOf($3); }
+    : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
     | TypeSignifier { $$ = $1; }
-    | { $$ = CYNew CYTypedIdentifier(NULL); }
+    | { $$ = CYNew CYTypedIdentifier(); }
+    ;
+
+FunctionedType
+    : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); }
     ;
 
 SuffixedType
     : ArrayedType { $$ = $1; }
-    | TypeParenthetical "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; CYSetLast($$->type_) = CYNew CYTypeFunctionWith($4); }
+    | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
+    | TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
+    | FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
 PrefixedType
-    : "*" TypeQualifierRight PrefixedType { $$ = $3; CYSetLast($$->type_) = $2; CYSetLast($$->type_) = CYNew CYTypePointerTo(); }
-    | SuffixedType { $$ = $1; }
+    : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
     ;
 
 TypeQualifierLeft
-    : "const" TypeQualifierLeft { $$ = CYNew CYTypeConstant(); CYSetLast($$) = $2; }
+    : "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
+    /* XXX: | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } */
     | { $$ = NULL; }
     ;
 
 TypeQualifierRight
-    : TypeQualifierRight "const" { $$ = CYNew CYTypeConstant($1); }
-    | { $$ = NULL; }
-    ;
-
-ConcreteType
-    : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; CYSetLast($$) = $1; CYSetLast($$) = CYNew CYTypeVariable($2); }
+    : "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
+    | PrefixedType { $$ = $1; }
+    | SuffixedType { $$ = $1; }
     ;
 
 PrimitiveType
@@ -1410,20 +1432,11 @@ PrimitiveType
     ;
 
 TypedIdentifier
-    : ConcreteType PrefixedType { $$ = $2; CYSetLast($$->type_) = $1; }
+    : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->type_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
     ;
 
 EncodedType
-    : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); }
-    ;
-
-ModifiedType_
-    : TypeQualifierLeft PrimitiveType { $$ = $1; CYSetLast($$) = CYNew CYTypeVariable($2); }
-    | ModifiedType "*" { $$ = CYNew CYTypePointerTo($1); }
-    ;
-
-ModifiedType
-    : ModifiedType_ TypeQualifierRight { $$ = $2; CYSetLast($$) = $1; }
+    : TypedIdentifier { $$ = CYNew CYEncodedType($1); }
     ;
 
 PrimaryExpression
@@ -1584,20 +1597,13 @@ PrimaryExpression
     ;
 /* }}} */
 /* Cycript (Objective-C): @import Directive {{{ */
-PathName
-    : "/" PathName
-    | "." PathName
-    | Word PathName
-    |
-    ;
-
-ImportPath
-    : "<" PathName ">"
-    | StringLiteral
+Module
+    : Module "." Word { $$ = CYNew CYModule($3, $1); }
+    | Word { $$ = CYNew CYModule($1); }
     ;
 
-StatementListItem
-    : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); }
+Declaration__
+    : "@import" Module { $$ = CYNew CYImport($2); }
     ;
 /* }}} */
 /* Cycript (Objective-C): Boxed Expressions {{{ */
@@ -1609,6 +1615,8 @@ BoxableExpression
     | ArrayLiteral { $$ = $1; }
     | ObjectLiteral { $$ = $1; }
     | Parenthetical { $$ = $1; }
+    | "YES" { $$ = CYNew CYTrue(); }
+    | "NO" { $$ = CYNew CYFalse(); }
     ;
 
 PrimaryExpression
@@ -1616,6 +1624,11 @@ PrimaryExpression
     ;
 /* }}} */
 /* Cycript (Objective-C): Block Expressions {{{ */
+ModifiedType
+    : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->type_ = $2; $$->modifier_ = $1; }
+    | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
+    ;
+
 PrimaryExpression
     : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
     ;
@@ -1659,7 +1672,7 @@ TypedParameterListOpt
     ;
 
 PrimaryExpression
-    : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14->type_, $10, $17); }
+    : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
     ;
 /* }}} */
 /* Cycript (C): Type Definitions {{{ */
@@ -1850,27 +1863,13 @@ Statement__
 @end
 
 /* JavaScript 1.7: Array Comprehensions {{{ */
-IfComprehension
-    : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
-    ;
-
-ForComprehension
-    : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
-    | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
-    ;
-
-ComprehensionList
-    : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
+Comprehension
+    : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
     ;
 
-ComprehensionListOpt
-    : ComprehensionList { $$ = $1; }
-    | IfComprehension { $$ = $1; }
-    | { $$ = NULL; }
-    ;
-
-PrimaryExpression
-    : "[" LexPushInOff AssignmentExpression ComprehensionList "]" LexPopIn { $$ = CYNew CYArrayComprehension($3, $4); }
+ComprehensionFor
+    : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
+    | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
     ;
 /* }}} */
 /* JavaScript 1.7: for each {{{ */