]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Parse bison output to prevent LexSetRegExp mistakes.
[cycript.git] / Cycript.yy.in
index 90588f78237c3aa455e1675fb36f747f63973200..fe1873fe13f763d346b633f53c86547433746283 100644 (file)
@@ -82,7 +82,8 @@ typedef struct {
         CYThis *this_;
         CYTrue *true_;
         CYTypeModifier *type_;
-        CYTypedIdentifier *typed_;
+        CYTypedIdentifier *typedIdentifier_;
+        CYTypedParameter *typedParameter_;
         CYWord *word_;
 
 @begin ObjectiveC
@@ -479,7 +480,9 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <messageParameter_> MessageParameterListOpt
 %type <bool_> MessageScope
 %type <type_> ModifiedType
-%type <typed_> 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 <typed_> SuffixedType
+%type <typedIdentifier_> SuffixedType
 %type <expression_> TypeOpt
-%type <typed_> 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 {{{ */
@@ -1342,7 +1348,7 @@ ProgramBodyOpt
 /* Cycript (Objective-C): Type Encoding {{{ */
 SuffixedType
     : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
-    | "(" PrefixedType ")" { $$ = $2; }
+    | "(" LexPushInOff PrefixedType LexPopIn ")" { $$ = $3; }
     | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
     ;
 
@@ -1352,13 +1358,24 @@ PrefixedType
     | "*" 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 CYTypeVariable($1); }
-    | "const" ModifiedType { $$ = CYNew CYTypeConstant($2); }
+    : QualifiedType { $$ = $1; }
+    | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); }
+    | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); }
     ;
 
 TypedIdentifier
-    : ModifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
+    : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
     ;
 
 EncodedType
@@ -1378,7 +1395,7 @@ ClassSuperOpt
 
 ClassFieldListOpt
     : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
-    | { $$ = NULL; }
+    | LexSetRegExp { $$ = NULL; }
     ;
 
 ClassFields
@@ -1391,8 +1408,7 @@ MessageScope
     ;
 
 TypeOpt
-    : "(" EncodedType ")" { $$ = $2; }
-    | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
+    : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
     | { $$ = NULL; }
     ;
 
@@ -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