]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Rename NameAndValue and add trailing-, per ECMA6.
[cycript.git] / Cycript.yy.in
index 410730af0d411330e40caf52a4c43fd8b7ade770..9b9a05c09157f4d3e1004c3834bc9216a9aa6ade 100644 (file)
@@ -250,7 +250,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token <word_> In_ "!in"
 %token <word_> InstanceOf "instanceof"
 %token <word_> New "new"
-%token <word_> Of "of"
 %token <word_> Return "return"
 %token <word_> Switch "switch"
 %token <this_> This "this"
@@ -309,6 +308,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 
 // Woah?!
 %token <identifier_> Each "each"
+%token <identifier_> Of "of"
 
 @begin E4X
 // E4X Conditional
@@ -382,6 +382,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <expression_> FunctionExpression
 %type <identifier_> Identifier
 %type <identifier_> IdentifierOpt
+%type <word_> IdentifierName
 %type <comprehension_> IfComprehension
 %type <statement_> IfStatement
 %type <expression_> Initialiser
@@ -411,9 +412,10 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <statement_> ProgramBodyOpt
 %type <propertyName_> PropertyName_
 %type <propertyName_> PropertyName
-%type <property_> PropertyNameAndValueList_
-%type <property_> PropertyNameAndValueList
-%type <property_> PropertyNameAndValueListOpt
+%type <property_> PropertyDefinition
+%type <property_> PropertyDefinitionList_
+%type <property_> PropertyDefinitionList
+%type <property_> PropertyDefinitionListOpt
 %type <expression_> RelationalExpression
 %type <statement_> ReturnStatement
 %type <rubyProc_> RubyProcExpression
@@ -439,6 +441,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <declarations_> VariableDeclarationList
 %type <statement_> VariableStatement
 %type <statement_> WithStatement
+%type <word_> Word
+%type <word_> WordOpt
 
 @begin ObjectiveC
 %type <statement_> CategoryStatement
@@ -468,8 +472,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <word_> SelectorWordOpt
 %type <expression_> TypeOpt
 %type <argument_> VariadicCall
-%type <word_> Word
-%type <word_> WordOpt
 @end
 
 @begin E4X
@@ -542,18 +544,13 @@ StrictSemi
     : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
     ;
 
-Terminator_
-    : ";"
-    | "\n" StrictSemi
-    ;
-
 Terminator
-    : Terminator_
+    : ";"
     | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
     ;
 
 TerminatorOpt
-    : Terminator_
+    : ";"
     | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
     ;
 
@@ -562,12 +559,15 @@ TerminatorOpt
     |
     ;*/
 
-@begin ObjectiveC
 NewLineOpt
     : "\n"
     |
     ;
 
+IdentifierName
+    : Word { $$ = $1; }
+    ;
+
 Word
     : Identifier { $$ = $1; }
     | "break" NewLineOpt { $$ = $1; }
@@ -591,10 +591,14 @@ Word
     | "if" { $$ = $1; }
     | "import" { $$ = $1; }
     /* XXX: | "in" { $$ = $1; } */
+    | "!in" { $$ = $1; }
     /* XXX: | "instanceof" { $$ = $1; } */
+
+    // XXX: as it currently is not an Identifier
+    | "let" { $$ = $1; }
+
     | "new" { $$ = $1; }
     | "null" { $$ = $1; }
-    | "of" { $$ = $1; }
     | "return" NewLineOpt { $$ = $1; }
     | "super" { $$ = $1; }
     | "switch" { $$ = $1; }
@@ -614,6 +618,7 @@ WordOpt
     | { $$ = NULL; }
     ;
 
+@begin ObjectiveC
 PrimaryExpression
     : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
     | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
@@ -650,10 +655,13 @@ Identifier
     | "transient" { $$ = $1; }
     | "volatile" { $$ = $1; }
 
-    // XXX: is this allowed?! | "let" { $$ = $1; }
+    // XXX: currently I only have this as Word
+    // | "let" { $$ = $1; }
+
     | "yield" { $$ = $1; }
 
     | "each" { $$ = $1; }
+    | "of" { $$ = $1; }
     ;
 
 IdentifierOpt
@@ -729,25 +737,32 @@ ElementListOpt
 /* }}} */
 /* 11.1.5 Object Initialiser {{{ */
 ObjectLiteral
-    : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
+    : BRACE LexPushInOff PropertyDefinitionListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
     ;
 
-PropertyNameAndValueList_
-    : "," PropertyNameAndValueList { $$ = $2; }
+PropertyDefinitionList_
+    : "," PropertyDefinitionList { $$ = $2; }
+    | "," { $$ = NULL; }
     | { $$ = NULL; }
     ;
 
-PropertyNameAndValueList
-    : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
+PropertyDefinitionList
+    : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
     ;
 
-PropertyNameAndValueListOpt
-    : PropertyNameAndValueList { $$ = $1; }
+PropertyDefinitionListOpt
+    : PropertyDefinitionList { $$ = $1; }
     | { $$ = NULL; }
     ;
 
+PropertyDefinition
+    //: IdentifierName { $$ = CYNew CYProperty($1, CYNew CYVariable($1)); }
+    : PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
+    //| MethodDefinition
+    ;
+
 PropertyName_
-    : Identifier { $$ = $1; }
+    : IdentifierName { $$ = $1; }
     | StringLiteral { $$ = $1; }
     | NumericLiteral { $$ = $1; }
     ;
@@ -760,7 +775,7 @@ PropertyName
 /* 11.2 Left-Hand-Side Expressions {{{ */
 MemberAccess
     : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
-    | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
+    | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
     | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
     ;
 
@@ -1128,17 +1143,20 @@ ForInStatementInitialiser
 
 /* 12.7 The continue Statement {{{ */
 ContinueStatement
-    : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
+    : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
+    | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
     ;
 /* }}} */
 /* 12.8 The break Statement {{{ */
 BreakStatement
-    : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
+    : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
+    | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
     ;
 /* }}} */
 /* 12.9 The return Statement {{{ */
 ReturnStatement
-    : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
+    : "return" "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
+    | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
     ;
 /* }}} */
 /* 12.10 The with Statement {{{ */
@@ -1177,7 +1195,8 @@ LabelledStatement
 /* }}} */
 /* 12.13 The throw Statement {{{ */
 ThrowStatement
-    : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
+    : "throw" "\n" StrictSemi { YYABORT; }
+    | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
     ;
 /* }}} */
 /* 12.14 The try Statement {{{ */
@@ -1457,7 +1476,7 @@ UnaryExpression_
 
 MemberAccess
     : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
-    | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
+    | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
     | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
     ;
 /* }}} */
@@ -1640,12 +1659,6 @@ Statement__
 /* }}} */
 @end
 
-/* ECMAScript5: Object Literal Trailing Comma {{{ */
-PropertyNameAndValueList_
-    : "," { $$ = NULL; }
-    ;
-/* }}} */
-
 /* JavaScript 1.7: Array Comprehensions {{{ */
 IfComprehension
     : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }