%token Equal "="
%token EqualEqual "=="
%token EqualEqualEqual "==="
+%token EqualRight "=>"
%token Exclamation "!"
%token ExclamationEqual "!="
%token ExclamationEqualEqual "!=="
// Woah?!
%token <identifier_> Each "each"
+%token <identifier_> Of "of"
@begin E4X
// E4X Conditional
%type <argument_> ArgumentListOpt
%type <argument_> Arguments
%type <literal_> ArrayLiteral
+%type <expression_> ArrowFunction
+%type <functionParameter_> ArrowParameters
%type <expression_> AssignmentExpression
%type <identifier_> BindingIdentifier
%type <expression_> BitwiseANDExpression
%type <comprehension_> ComprehensionListOpt
%type <expression_> ConditionalExpression
%type <statement_> ContinueStatement
+%type <statement_> ConciseBody
%type <statement_> DebuggerStatement
%type <statement_> Declaration__
%type <statement_> Declaration_
%type <statement_> Declaration
%type <clause_> DefaultClause
-%type <statement_> DoWhileStatement
%type <expression_> Element
%type <expression_> ElementOpt
%type <element_> ElementList
%type <statement_> EmptyStatement
%type <expression_> EqualityExpression
%type <compound_> Expression_
-%type <expression_> Expression
+%type <compound_> Expression
%type <expression_> ExpressionOpt
%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_
%type <expression_> FunctionExpression
%type <identifier_> Identifier
%type <identifier_> IdentifierOpt
+%type <word_> IdentifierName
%type <comprehension_> IfComprehension
%type <statement_> IfStatement
%type <expression_> Initialiser
%type <expression_> NewExpression
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
-%type <expression_> Parenthetical
+%type <compound_> Parenthetical
+%type <compound_> ParentheticalOpt
%type <expression_> PostfixExpression
%type <expression_> PrimaryExpression
%type <statement_> Program
%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
%type <word_> SelectorWordOpt
%type <expression_> TypeOpt
%type <argument_> VariadicCall
-%type <word_> Word
-%type <word_> WordOpt
@end
@begin E4X
: { driver.SetCondition(CYDriver::RegExpCondition); }
;
-LexSetStatement
- : { switch (yychar) {
- case token::Function:
- yychar = token::Function_;
- break;
+LexNoBrace
+ : { if (yychar == yyempty_) driver.nobrace_ = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
+ ;
- case token::OpenBrace:
- case token::OpenBrace_:
- yychar = token::OpenBrace__;
- break;
- } }
+LexNoFunction
+ : { if (yychar == token::Function) yychar = token::Function_; }
+ ;
+
+LexSetStatement
+ : LexNoBrace LexNoFunction
;
/* }}} */
: { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
;
-Terminator_
- : ";"
- | "\n" StrictSemi
- ;
-
Terminator
- : Terminator_
- | error { if (yychar != 0 && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
+ : ";"
+ | 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
;
|
;*/
-@begin ObjectiveC
NewLineOpt
: "\n"
|
;
+IdentifierName
+ : Word { $$ = $1; }
+ ;
+
Word
: Identifier { $$ = $1; }
| "break" NewLineOpt { $$ = $1; }
| "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; }
| { $$ = NULL; }
;
+@begin ObjectiveC
PrimaryExpression
: "@" LiteralNoRE { $$ = CYNew CYBox($2); }
| "@" ArrayLiteral { $$ = CYNew CYBox($2); }
| "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
: "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
;
+ParentheticalOpt
+ : Parenthetical { $$ = $1; }
+ | { $$ = NULL; }
+ ;
+
PrimaryExpression
: "this" { $$ = $1; }
| Identifier { $$ = CYNew CYVariable($1); }
;
PropertyName_
- : Identifier { $$ = $1; }
+ : IdentifierName { $$ = $1; }
| StringLiteral { $$ = $1; }
| NumericLiteral { $$ = $1; }
;
/* 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; }
;
/* 11.13 Assignment Operators {{{ */
AssignmentExpression
: ConditionalExpression { $$ = $1; }
+ | ArrowFunction { $$ = $1; }
| LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
| LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
| LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
/* }}} */
/* 11.14 Comma Operator {{{ */
Expression_
- : "," Expression { $$ = CYNew CYCompound($2); }
- | { $$ = NULL; }
+ : "," Expression { $$ = $2; }
+ | { $$ = CYNew CYCompound(); }
;
Expression
- : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
+ : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
;
ExpressionOpt
;
/* }}} */
-/* 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); }
;
| 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
/* 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 {{{ */
/* }}} */
/* 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 {{{ */
;
/* }}} */
-/* 13 Function Definition {{{ */
+/* 13.1 Function Definitions {{{ */
FunctionDeclaration
: ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
;
: StatementListOpt { $$ = $1; }
;
/* }}} */
+/* 13.2 Arrow Function Definitions {{{ */
+ArrowFunction
+ : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFunctionExpression(NULL, $2, $5); }
+ ;
+
+ArrowParameters
+ : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
+ //| ParentheticalOpt { $$ = $1; }
+ ;
+
+ConciseBody
+ : AssignmentExpression { $$ = CYNew CYReturn($1); }
+ | ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $3; }
+ ;
+/* }}} */
/* 14 Program {{{ */
Program
: ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
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; }
;
/* }}} */
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
;
/* }}} */
/* 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 {{{ */