]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Theoretically fix bug with in operators in messages.
[cycript.git] / Cycript.yy.in
index b6f355c865f96cb50ab283163d2c67c38f045412..7399651819b11bb23d9a8708dc99a0a3af77ffd2 100644 (file)
@@ -73,7 +73,6 @@ typedef struct {
         CYMember *member_;
         CYNull *null_;
         CYNumber *number_;
-        CYEncodedPart *part_;
         CYProgram *program_;
         CYProperty *property_;
         CYPropertyName *propertyName_;
@@ -82,7 +81,9 @@ typedef struct {
         CYString *string_;
         CYThis *this_;
         CYTrue *true_;
-        CYEncodedType *type_;
+        CYTypeModifier *type_;
+        CYTypedIdentifier *typedIdentifier_;
+        CYTypedParameter *typedParameter_;
         CYWord *word_;
 
 @begin ObjectiveC
@@ -471,6 +472,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <protocol_> ClassProtocolListOpt
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
+%type <expression_> EncodedType
 %type <expression_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
@@ -478,8 +480,9 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
 %type <type_> ModifiedType
-%type <part_> NamedTypeOpt
-%type <part_> PrefixedType
+%type <typedIdentifier_> PrefixedType
+%type <expression_> PrimitiveType
+%type <type_> QualifiedType
 %type <argument_> SelectorCall_
 %type <argument_> SelectorCall
 %type <selector_> SelectorExpression_
@@ -487,9 +490,12 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <selector_> SelectorExpressionOpt
 %type <argument_> SelectorList
 %type <word_> SelectorWordOpt
-%type <part_> SuffixedType
+%type <typedIdentifier_> SuffixedType
 %type <expression_> TypeOpt
-%type <type_> TypedIdentifier
+%type <typedIdentifier_> TypedIdentifier
+%type <typedParameter_> TypedParameterList_
+%type <typedParameter_> TypedParameterList
+%type <typedParameter_> TypedParameterListOpt
 %type <argument_> VariadicCall
 @end
 
@@ -787,7 +793,7 @@ ObjectLiteral
 
 PropertyDefinitionList_
     : "," PropertyDefinitionList { $$ = $2; }
-    | "," { $$ = NULL; }
+    | "," LexSetRegExp { $$ = NULL; }
     | { $$ = NULL; }
     ;
 
@@ -797,7 +803,7 @@ PropertyDefinitionList
 
 PropertyDefinitionListOpt
     : PropertyDefinitionList { $$ = $1; }
-    | { $$ = NULL; }
+    | LexSetRegExp { $$ = NULL; }
     ;
 
 PropertyDefinition
@@ -1207,7 +1213,7 @@ BreakStatement
 /* }}} */
 /* 12.9 The return Statement {{{ */
 ReturnStatement
-    : "return" "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
+    : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
     | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
     ;
 /* }}} */
@@ -1247,7 +1253,7 @@ LabelledStatement
 /* }}} */
 /* 12.13 The throw Statement {{{ */
 ThrowStatement
-    : "throw" "\n" StrictSemi { YYABORT; }
+    : "throw" LexSetRegExp "\n" StrictSemi { YYABORT; }
     | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
     ;
 /* }}} */
@@ -1320,7 +1326,7 @@ ArrowParameters
 
 ConciseBody
     : AssignmentExpression { $$ = CYNew CYReturn($1); }
-    | ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $3; }
+    | LexSetRegExp ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $4; }
     ;
 /* }}} */
 /* 14 Program {{{ */
@@ -1340,33 +1346,44 @@ ProgramBodyOpt
 
 @begin ObjectiveC
 /* Cycript (Objective-C): Type Encoding {{{ */
-NamedTypeOpt
-    : Identifier { $$ = CYNew CYEncodedPart(NULL, "withName", CYNew CYArgument(CYNew CYString($1->word_))); }
-    | { $$ = NULL; }
-    ;
-
 SuffixedType
-    : NamedTypeOpt { $$ = $1; }
-    | "(" PrefixedType ")" { $$ = $2; }
-    | SuffixedType "[" NumericLiteral "]" { $$ = CYNew CYEncodedPart($1, "arrayOf", CYNew CYArgument($3)); }
+    : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
+    | "(" LexPushInOff PrefixedType LexPopIn ")" { $$ = $3; }
+    | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
     ;
 
 PrefixedType
     : SuffixedType { $$ = $1; }
-    | "*" PrefixedType { $$ = CYNew CYEncodedPart($2, "pointerTo"); }
+    | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; }
+    | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; }
+    ;
+
+PrimitiveType
+    : Variable { $$ = $1; }
+    | "void" { $$  = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
+    ;
+
+QualifiedType
+    : PrimitiveType { $$ = CYNew CYTypeVariable($1); }
+    | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); }
     ;
 
 ModifiedType
-    : Variable { $$ = CYNew CYEncodedType($1); }
-    | "const" ModifiedType { $2->base_ = CYNew CYCall(CYNew CYDirectMember($2->base_, CYNew CYString("constant"))); $$ = $2; }
+    : QualifiedType { $$ = $1; }
+    | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); }
+    | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); }
     ;
 
 TypedIdentifier
-    : ModifiedType PrefixedType { $1->parts_ = $2; $$ = $1;}
+    : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
+    ;
+
+EncodedType
+    : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); }
     ;
 
 PrimaryExpression
-    : AtEncode "(" TypedIdentifier ")" { $$ = $3; }
+    : AtEncode "(" EncodedType ")" { $$ = $3; }
     ;
 /* }}} */
 /* Cycript (Objective-C): @class Declaration {{{ */
@@ -1378,7 +1395,7 @@ ClassSuperOpt
 
 ClassFieldListOpt
     : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
-    | { $$ = NULL; }
+    | LexSetRegExp { $$ = NULL; }
     ;
 
 ClassFields
@@ -1391,8 +1408,7 @@ MessageScope
     ;
 
 TypeOpt
-    : "(" TypedIdentifier ")" { $$ = $2; }
-    | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
+    : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
     | { $$ = NULL; }
     ;
 
@@ -1450,7 +1466,7 @@ ClassProtocolListOpt
     ;
 
 ClassExpression
-    : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
+    : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields LexPopIn ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $8); }
     ;
 
 ClassStatement
@@ -1555,6 +1571,25 @@ PrimaryExpression
     : "@" BoxableExpression { $$ = CYNew CYBox($2); }
     ;
 /* }}} */
+/* Cycript (Objective-C): Block Expressions {{{ */
+TypedParameterList_
+    : "," TypedParameterList { $$ = $2; }
+    | { $$ = NULL; }
+    ;
+
+TypedParameterList
+    : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+    ;
+
+TypedParameterListOpt
+    : TypedParameterList { $$ = $1; }
+    | { $$ = NULL; }
+    ;
+
+PrimaryExpression
+    : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYObjCBlock($2, $5, $10); }
+    ;
+/* }}} */
 @end
 
 @begin C