]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Rename NameAndValue and add trailing-, per ECMA6.
[cycript.git] / Cycript.yy.in
index aeb15cd1579f23397290b1a078c0855d4a1155e4..9b9a05c09157f4d3e1004c3834bc9216a9aa6ade 100644 (file)
@@ -308,6 +308,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 
 // Woah?!
 %token <identifier_> Each "each"
+%token <identifier_> Of "of"
 
 @begin E4X
 // E4X Conditional
@@ -357,7 +358,6 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <statement_> Declaration_
 %type <statement_> Declaration
 %type <clause_> DefaultClause
-%type <statement_> DoWhileStatement
 %type <expression_> Element
 %type <expression_> ElementOpt
 %type <element_> ElementList
@@ -371,9 +371,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <statement_> ExpressionStatement
 %type <finally_> FinallyOpt
 %type <comprehension_> ForComprehension
-%type <statement_> ForStatement
 %type <for_> ForStatementInitialiser
-%type <statement_> ForInStatement
 %type <forin_> ForInStatementInitialiser
 %type <declaration_> FormalParameter
 %type <functionParameter_> FormalParameterList_
@@ -384,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
@@ -413,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
@@ -440,8 +440,9 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <declarations_> VariableDeclarationList_
 %type <declarations_> VariableDeclarationList
 %type <statement_> VariableStatement
-%type <statement_> WhileStatement
 %type <statement_> WithStatement
+%type <word_> Word
+%type <word_> WordOpt
 
 @begin ObjectiveC
 %type <statement_> CategoryStatement
@@ -471,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
@@ -524,7 +523,7 @@ LexSetRegExp
     ;
 
 LexNoBrace
-    : { if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
+    : { if (yychar == yyempty_) driver.nobrace_ = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
     ;
 
 LexNoFunction
@@ -545,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
     ;
 
@@ -565,12 +559,15 @@ TerminatorOpt
     |
     ;*/
 
-@begin ObjectiveC
 NewLineOpt
     : "\n"
     |
     ;
 
+IdentifierName
+    : Word { $$ = $1; }
+    ;
+
 Word
     : Identifier { $$ = $1; }
     | "break" NewLineOpt { $$ = $1; }
@@ -594,7 +591,12 @@ 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; }
     | "return" NewLineOpt { $$ = $1; }
@@ -616,6 +618,7 @@ WordOpt
     | { $$ = NULL; }
     ;
 
+@begin ObjectiveC
 PrimaryExpression
     : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
     | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
@@ -652,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
@@ -731,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; }
     ;
@@ -762,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; }
     ;
 
@@ -1096,26 +1109,18 @@ IfStatement
     ;
 /* }}} */
 
-/* 12.6 Iteration Statements {{{ */
-IterationStatement
-    : DoWhileStatement { $$ = $1; }
-    | WhileStatement { $$ = $1; }
-    | ForStatement { $$ = $1; }
-    | ForInStatement { $$ = $1; }
-    ;
-/* }}} */
 /* 12.6.1 The do-while Statement {{{ */
-DoWhileStatement
+IterationStatement
     : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
     ;
 /* }}} */
 /* 12.6.2 The while Statement {{{ */
-WhileStatement
+IterationStatement
     : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
     ;
 /* }}} */
 /* 12.6.3 The for Statement {{{ */
-ForStatement
+IterationStatement
     : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
     ;
 
@@ -1124,9 +1129,10 @@ ForStatementInitialiser
     | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
     ;
 /* }}} */
-/* 12.6.4 The for-in Statement {{{ */
-ForInStatement
+/* 12.6.4 The for-in and for-of Statements {{{ */
+IterationStatement
     : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
+    | "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "of" Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
     ;
 
 ForInStatementInitialiser
@@ -1137,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 {{{ */
@@ -1186,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 {{{ */
@@ -1466,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; }
     ;
 /* }}} */
@@ -1649,12 +1659,6 @@ Statement__
 /* }}} */
 @end
 
-/* ECMAScript5: Object Literal Trailing Comma {{{ */
-PropertyNameAndValueList_
-    : "," { $$ = NULL; }
-    ;
-/* }}} */
-
 /* JavaScript 1.7: Array Comprehensions {{{ */
 IfComprehension
     : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
@@ -1662,7 +1666,7 @@ IfComprehension
 
 ForComprehension
     : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
-    | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); }
+    | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
     ;
 
 ComprehensionList
@@ -1680,8 +1684,8 @@ PrimaryExpression
     ;
 /* }}} */
 /* JavaScript 1.7: for each {{{ */
-ForInStatement
-    : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); }
+IterationStatement
+    : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
     ;
 /* }}} */
 /* JavaScript 1.7: let Statements {{{ */