X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/4e3c905634abeaeea78747ce2be0adce06cc777a..6244bca0d4d6048c9c27e501648dbc955882d7cf:/Parser.ypp.in?ds=sidebyside diff --git a/Parser.ypp.in b/Parser.ypp.in index 26d73c8..5b0c18b 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -42,11 +42,13 @@ %union { bool bool_; } +%union { CYMember *access_; } %union { CYArgument *argument_; } %union { CYAssignment *assignment_; } %union { CYBoolean *boolean_; } %union { CYClause *clause_; } %union { cy::Syntax::Catch *catch_; } +%union { CYClassTail *classTail_; } %union { CYComprehension *comprehension_; } %union { CYDeclaration *declaration_; } %union { CYDeclarations *declarations_; } @@ -61,7 +63,7 @@ %union { CYIdentifier *identifier_; } %union { CYInfix *infix_; } %union { CYLiteral *literal_; } -%union { CYMember *member_; } +%union { CYMethod *method_; } %union { CYModule *module_; } %union { CYNull *null_; } %union { CYNumber *number_; } @@ -72,6 +74,7 @@ %union { CYSpan *span_; } %union { CYStatement *statement_; } %union { CYString *string_; } +%union { CYTarget *target_; } %union { CYThis *this_; } %union { CYTrue *true_; } %union { CYWord *word_; } @@ -84,10 +87,9 @@ @end @begin ObjectiveC -%union { CYClassName *className_; } -%union { CYClassField *classField_; } %union { CYMessage *message_; } %union { CYMessageParameter *messageParameter_; } +%union { CYImplementationField *implementationField_; } %union { CYProtocol *protocol_; } %union { CYSelectorPart *selector_; } @end @@ -111,6 +113,8 @@ int cylex(YYSTYPE *, CYLocation *, void *); %code { +typedef cy::parser::token tk; + #undef yylex _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) { if (driver.mark_ == CYMarkIgnore); @@ -122,27 +126,74 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY return cy::parser::token::MarkModule; } + lex: + if (driver.newline_ == CYDriver::NewLineHere) + driver.newline_ = CYDriver::NewLineLast; + else if (driver.newline_ == CYDriver::NewLineLast) + driver.newline_ = CYDriver::NewLineNone; + YYSTYPE data; int token(cylex(&data, location, driver.scanner_)); *semantic = data.semantic_; + + switch (token) { + case tk::_in_: + if (driver.in_.top()) + token = tk::_in__; + break; + + case tk::_yield_: + if (driver.yield_.top()) + token = tk::_yield__; + break; + + case tk::NewLine: + driver.newline_ = CYDriver::NewLineHere; + if (!driver.next_) + goto lex; + break; + } + + driver.next_ = false; return token; } +#define CYLEX() do if (yyla.empty()) { \ + YYCDEBUG << "Mapping a token: "; \ + yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + YY_SYMBOL_PRINT("Next token is", yyla); \ +} while (false) + #define CYMAP(to, from) do { \ - if (yyla.empty()) \ - yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + CYLEX(); \ if (yyla.type == yytranslate_(token::from)) \ yyla.type = yytranslate_(token::to); \ } while (false) +#define CYLIN(from) do { \ + CYLEX(); \ + if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \ + yyla.type = yytranslate_(token::from ## _); \ +} while (false) + #define CYERR(location, message) do { \ error(location, message); \ YYABORT; \ } while (false) +#define CYEOK() do { \ + yyerrok; \ + driver.errors_.pop_back(); \ +} while (false) + #define CYNOT(location) \ CYERR(location, "unimplemented feature") +#define CYMPT(location) do { \ + if (!yyla.empty() && yyla.type_get() != yyeof_) \ + CYERR(location, "unexpected lookahead"); \ +} while (false) + } %name-prefix "cy" @@ -253,9 +304,11 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token OpenBrace "{" %token OpenBrace_ "\n{" %token OpenBrace__ ";{" +%token OpenBrace_let "let {" %token CloseBrace "}" %token OpenBracket "[" +%token OpenBracket_let "let [" %token CloseBracket "]" %token At_error_ "@error" @@ -316,12 +369,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _import_ "import" %token _in_ "in" %token _in__ "!in" +%token _Infinity_ "Infinity" %token _instanceof_ "instanceof" %token _new_ "new" %token _return_ "return" -%token _return__ "!return" %token _super_ "super" %token _switch_ "switch" +%token _target_ "target" %token _this_ "this" %token _throw_ "throw" %token _try_ "try" @@ -336,7 +390,9 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _boolean_ "boolean" %token _byte_ "byte" %token _char_ "char" +%token _constructor_ "constructor" %token _double_ "double" +%token _eval_ "eval" %token _final_ "final" %token _float_ "float" %token _from_ "from" @@ -346,11 +402,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _int_ "int" %token _interface_ "interface" %token _let_ "let" +%token _let__ "!let" %token _long_ "long" %token _native_ "native" %token _package_ "package" %token _private_ "private" %token _protected_ "protected" +%token _prototype_ "prototype" %token _public_ "public" %token _set_ "set" %token _short_ "short" @@ -376,6 +434,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _auto_ "auto" %token _each_ "each" %token _of_ "of" +%token _of__ "!of" @begin E4X %token _namespace_ "namespace" @@ -395,12 +454,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token TemplateMiddle %token TemplateTail +%type AccessExpression %type AdditiveExpression %type ArgumentList_ %type ArgumentList %type ArgumentListOpt %type Arguments -%type ArrayComprehension +%type ArrayComprehension %type ArrayLiteral %type ArrowFunction %type ArrowParameters @@ -420,19 +480,22 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type BreakStatement %type BreakableStatement %type CallExpression_ -%type CallExpression +%type CallExpression %type CaseBlock %type CaseClause %type CaseClausesOpt %type Catch %type CatchParameter %type ClassDeclaration -%type ClassExpression -%type Comprehension +%type ClassExpression +%type ClassHeritage +%type ClassHeritageOpt +%type ClassTail +%type Comprehension %type ComprehensionFor %type ComprehensionIf %type ComprehensionTail -%type ComputedPropertyName +%type ComputedPropertyName %type ConditionalExpression %type ContinueStatement %type ConciseBody @@ -445,14 +508,15 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type ElementList %type ElementListOpt %type ElseStatementOpt -%type EmptyStatement +%type EmptyStatement %type EqualityExpression %type Expression %type ExpressionOpt +%type ExpressionStatement_ %type ExpressionStatement %type Finally %type ForBinding -%type ForDeclaration +%type ForDeclaration %type ForInStatementInitializer %type ForStatementInitializer %type FormalParameter @@ -461,42 +525,45 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type FormalParameters %type FunctionBody %type FunctionDeclaration -%type FunctionExpression +%type FunctionExpression %type FunctionStatementList %type GeneratorBody %type GeneratorDeclaration -%type GeneratorExpression -%type GeneratorMethod +%type GeneratorExpression +%type GeneratorMethod %type HoistableDeclaration %type Identifier %type IdentifierType %type IdentifierName %type IdentifierReference %type IfStatement +%type IndirectExpression %type Initializer %type InitializerOpt %type IterationStatement %type LabelIdentifier %type LabelledItem %type LabelledStatement -%type LeftHandSideExpression -%type LetStatement +%type LeftHandSideAssignment +%type LeftHandSideExpression +%type LetOrConst %type LexicalBinding +%type LexicalDeclaration_ %type LexicalDeclaration %type Literal %type LiteralPropertyName %type LogicalANDExpression %type LogicalORExpression -%type MemberAccess -%type MemberExpression -%type MethodDefinition +%type MemberAccess +%type MemberExpression +%type MethodDefinition %type ModulePath %type MultiplicativeExpression -%type NewExpression +%type NewExpression %type NullLiteral %type ObjectLiteral %type PostfixExpression -%type PrimaryExpression +%type PrimaryExpression %type PropertyName %type PropertyDefinition %type PropertyDefinitionList_ @@ -522,8 +589,10 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type StatementListOpt %type StatementListItem %type StrictFormalParameters +%type SuperCall +%type SuperProperty %type SwitchStatement -%type TemplateLiteral +%type TemplateLiteral %type TemplateSpans %type ThrowStatement %type TryStatement @@ -532,6 +601,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type VariableDeclaration %type VariableDeclarationList_ %type VariableDeclarationList +%type VariableStatement_ %type VariableStatement %type WithStatement %type Word @@ -556,19 +626,20 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY @end @begin ObjectiveC +%type AssignmentExpressionClassic %type BoxableExpression %type CategoryStatement -%type ClassFieldListOpt -%type ClassFields -%type ClassStatement %type ClassSuperOpt +%type ConditionalExpressionClassic +%type ImplementationFieldListOpt +%type ImplementationFields %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt -%type ClassName %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt -%type MessageExpression +%type ImplementationStatement +%type MessageExpression %type MessageParameter %type MessageParameters %type MessageParameterList @@ -607,9 +678,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY @end /* }}} */ /* Token Priorities {{{ */ -%nonassoc "" -%left "++" "--" "{" - %nonassoc "if" %nonassoc "else" /* }}} */ @@ -633,16 +701,24 @@ LexPopIn: { driver.in_.pop(); }; LexPushReturnOn: { driver.return_.push(true); }; LexPopReturn: { driver.return_.pop(); }; +LexPushSuperOn: { driver.super_.push(true); }; +LexPushSuperOff: { driver.super_.push(false); }; +LexPopSuper: { driver.super_.pop(); }; + LexPushYieldOn: { driver.yield_.push(true); }; LexPushYieldOff: { driver.yield_.push(false); }; LexPopYield: { driver.yield_.pop(); }; +LexOf + : { CYMAP(_of__, _of_); } + ; + LexSetRegExp - : { driver.SetCondition(CYDriver::RegExpCondition); } + : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } } LexOf ; LexNewLine - : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; } + : { CYMPT(@$); driver.next_ = true; } ; LexNoStar @@ -716,7 +792,6 @@ Word | "new" LexSetRegExp { $$ = CYNew CYWord("new"); } | "null" { $$ = CYNew CYWord("null"); } | "return" { $$ = CYNew CYWord("return"); } - | "!return" { $$ = CYNew CYWord("return"); } | "super" { $$ = CYNew CYWord("super"); } | "switch" { $$ = CYNew CYWord("switch"); } | "this" { $$ = CYNew CYWord("this"); } @@ -731,9 +806,6 @@ Word | "yield" { $$ = CYNew CYIdentifier("yield"); } | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); } - - // XXX: should be Identifier - | "let" { $$ = CYNew CYIdentifier("let"); } ; @begin ObjectiveC @@ -767,7 +839,7 @@ TerminatorSoft Terminator : ";" - | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi + | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) CYERR(@1, "required semi-colon"); else CYEOK(); } StrictSemi ; TerminatorOpt @@ -803,23 +875,33 @@ IdentifierType | "await" { $$ = CYNew CYIdentifier("await"); } | "boolean" { $$ = CYNew CYIdentifier("boolean"); } | "byte" { $$ = CYNew CYIdentifier("byte"); } + | "constructor" { $$ = CYNew CYIdentifier("constructor"); } | "double" { $$ = CYNew CYIdentifier("double"); } | "each" { $$ = CYNew CYIdentifier("each"); } + | "eval" { $$ = CYNew CYIdentifier("eval"); } | "final" { $$ = CYNew CYIdentifier("final"); } | "float" { $$ = CYNew CYIdentifier("float"); } + | "from" { $$ = CYNew CYIdentifier("from"); } + | "get" { $$ = CYNew CYIdentifier("get"); } | "goto" { $$ = CYNew CYIdentifier("goto"); } | "implements" { $$ = CYNew CYIdentifier("implements"); } + | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); } | "interface" { $$ = CYNew CYIdentifier("interface"); } + | "let" { $$ = CYNew CYIdentifier("let"); } + | "!let" LexBind { $$ = CYNew CYIdentifier("let"); } | "native" { $$ = CYNew CYIdentifier("native"); } - | "of" { $$ = CYNew CYIdentifier("of"); } + | "!of" { $$ = CYNew CYIdentifier("of"); } | "package" { $$ = CYNew CYIdentifier("package"); } | "private" { $$ = CYNew CYIdentifier("private"); } | "protected" { $$ = CYNew CYIdentifier("protected"); } + | "prototype" { $$ = CYNew CYIdentifier("prototype"); } | "public" { $$ = CYNew CYIdentifier("public"); } - | "static" { $$ = CYNew CYIdentifier("static"); } + | "set" { $$ = CYNew CYIdentifier("set"); } | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); } + | "target" { $$ = CYNew CYIdentifier("target"); } | "throws" { $$ = CYNew CYIdentifier("throws"); } | "transient" { $$ = CYNew CYIdentifier("transient"); } + | "undefined" { $$ = CYNew CYIdentifier("undefined"); } @begin ObjectiveC | "bool" { $$ = CYNew CYIdentifier("bool"); } | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); } @@ -831,13 +913,10 @@ IdentifierType Identifier : IdentifierType | "char" { $$ = CYNew CYIdentifier("char"); } - | "from" { $$ = CYNew CYIdentifier("from"); } - | "get" { $$ = CYNew CYIdentifier("get"); } | "int" { $$ = CYNew CYIdentifier("int"); } | "long" { $$ = CYNew CYIdentifier("long"); } - | "set" { $$ = CYNew CYIdentifier("set"); } | "short" { $$ = CYNew CYIdentifier("short"); } - | "undefined" { $$ = CYNew CYIdentifier("undefined"); } + | "static" { $$ = CYNew CYIdentifier("static"); } | "volatile" { $$ = CYNew CYIdentifier("volatile"); } @begin C | "extern" { $$ = CYNew CYIdentifier("extern"); } @@ -920,15 +999,15 @@ PropertyDefinitionListOpt ; PropertyDefinition - : IdentifierReference { $$ = CYNew CYProperty($1->name_, $1); } + : IdentifierReference { $$ = CYNew CYPropertyValue($1->name_, $1); } | CoverInitializedName { CYNOT(@$); } - | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); } + | PropertyName ":" AssignmentExpression { $$ = CYNew CYPropertyValue($1, $3); } | MethodDefinition { $$ = $1; } ; PropertyName : LiteralPropertyName { $$ = $1; } - | ComputedPropertyName { CYNOT(@$); /* $$ = $1; */ } + | ComputedPropertyName { $$ = $1; } ; LiteralPropertyName @@ -938,7 +1017,7 @@ LiteralPropertyName ; ComputedPropertyName - : "[" AssignmentExpression "]" { $$ = $2; } + : "[" AssignmentExpression "]" { $$ = CYNew CYComputed($2); } ; CoverInitializedName @@ -977,14 +1056,14 @@ MemberAccess MemberExpression : LexSetRegExp PrimaryExpression { $$ = $2; } | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } - | SuperProperty { CYNOT(@$); } + | SuperProperty { $$ = $1; } | MetaProperty { CYNOT(@$); } | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); } ; SuperProperty - : LexSetRegExp "super" "[" Expression "]" - | LexSetRegExp "super" "." IdentifierName + : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "[" Expression "]" { $$ = CYNew CYSuperAccess($5); } + | LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($5)); } ; MetaProperty @@ -1001,18 +1080,18 @@ NewExpression ; CallExpression_ - : MemberExpression - | CallExpression + : MemberExpression { $$ = $1; } + | CallExpression { $$ = $1; } ; CallExpression - : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); } - | SuperCall { CYNOT(@$); } + : CallExpression_ Arguments { if (!$1->Eval()) $$ = CYNew CYCall($1, $2); else $$ = CYNew CYEval($2); } + | SuperCall { $$ = $1; } | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } ; SuperCall - : LexSetRegExp "super" Arguments + : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } Arguments { $$ = CYNew CYSuperCall($4); } ; Arguments @@ -1034,16 +1113,25 @@ ArgumentListOpt | LexSetRegExp { $$ = NULL; } ; -LeftHandSideExpression +AccessExpression : NewExpression { $$ = $1; } | CallExpression { $$ = $1; } ; + +LeftHandSideExpression + : AccessExpression LexCrement { $$ = $1; } + | LexSetRegExp IndirectExpression { $$ = $2; } + ; /* }}} */ /* 12.4 Postfix Expressions {{{ */ +LexCrement + : { CYLIN(PlusPlus); CYLIN(HyphenHyphen); } + ; + PostfixExpression - : %prec "" LeftHandSideExpression { $$ = $1; } - | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); } - | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); } + : AccessExpression LexCrement { $$ = $1; } + | AccessExpression LexCrement "++" { $$ = CYNew CYPostIncrement($1); } + | AccessExpression LexCrement "--" { $$ = CYNew CYPostDecrement($1); } ; /* }}} */ /* 12.5 Unary Operators {{{ */ @@ -1062,7 +1150,7 @@ UnaryExpression_ ; UnaryExpression - : PostfixExpression { $$ = $1; } + : PostfixExpression LexOpenBrace { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } ; /* }}} */ @@ -1137,28 +1225,46 @@ LogicalORExpression ; /* }}} */ /* 12.13 Conditional Operator ( ? : ) {{{ */ +@begin ObjectiveC +ConditionalExpressionClassic + : LogicalORExpression { $$ = $1; } + | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpressionClassic { $$ = CYNew CYCondition($1, $4, $7); } + ; +@end + ConditionalExpression : LogicalORExpression { $$ = $1; } | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); } ; /* }}} */ /* 12.14 Assignment Operators {{{ */ +LeftHandSideAssignment + : LeftHandSideExpression "=" { $$ = CYNew CYAssign($1, NULL); } + | LeftHandSideExpression "*=" { $$ = CYNew CYMultiplyAssign($1, NULL); } + | LeftHandSideExpression "/=" { $$ = CYNew CYDivideAssign($1, NULL); } + | LeftHandSideExpression "%=" { $$ = CYNew CYModulusAssign($1, NULL); } + | LeftHandSideExpression "+=" { $$ = CYNew CYAddAssign($1, NULL); } + | LeftHandSideExpression "-=" { $$ = CYNew CYSubtractAssign($1, NULL); } + | LeftHandSideExpression "<<=" { $$ = CYNew CYShiftLeftAssign($1, NULL); } + | LeftHandSideExpression ">>=" { $$ = CYNew CYShiftRightSignedAssign($1, NULL); } + | LeftHandSideExpression ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($1, NULL); } + | LeftHandSideExpression "&=" { $$ = CYNew CYBitwiseAndAssign($1, NULL); } + | LeftHandSideExpression "^=" { $$ = CYNew CYBitwiseXOrAssign($1, NULL); } + | LeftHandSideExpression "|=" { $$ = CYNew CYBitwiseOrAssign($1, NULL); } + ; + +@begin ObjectiveC +AssignmentExpressionClassic + : ConditionalExpressionClassic { $$ = $1; } + | LeftHandSideAssignment AssignmentExpressionClassic { $1->SetRight($2); $$ = $1; } + ; +@end + AssignmentExpression : ConditionalExpression { $$ = $1; } | LexSetRegExp YieldExpression { $$ = $2; } | ArrowFunction { $$ = $1; } - | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); } - | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); } - | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); } - | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); } - | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); } - | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); } - | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); } - | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); } - | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); } - | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); } - | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); } - | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); } + | LeftHandSideAssignment AssignmentExpression { $1->SetRight($2); $$ = $1; } ; AssignmentExpressionOpt @@ -1201,17 +1307,17 @@ Statement_ ; Statement - : LexSetStatement Statement_ { $$ = $2; } + : LexSetStatement LexLet Statement_ { $$ = $3; } ; Declaration__ : HoistableDeclaration { $$ = $1; } | ClassDeclaration { $$ = $1; } - | LexicalDeclaration { $$ = $1; } ; Declaration_ - : LexSetRegExp Declaration__ { $$ = $2; } + : LexLet LexSetRegExp Declaration__ { $$ = $3; } + | LexicalDeclaration { $$ = $1; } ; Declaration @@ -1243,7 +1349,7 @@ StatementList StatementListOpt : StatementList { $$ = $1; } - | LexSetStatement LexSetRegExp { $$ = NULL; } + | LexSetStatement LexLet LexSetRegExp { $$ = NULL; } ; StatementListItem @@ -1252,17 +1358,29 @@ StatementListItem ; /* }}} */ /* 13.3 Let and Const Declarations {{{ */ +LexicalDeclaration_ + : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); } + ; + LexicalDeclaration - : LetOrConst BindingList Terminator { $$ = CYNew CYVar($2); } + : LexicalDeclaration_ Terminator { $$ = $1; } + ; + +LexLet + : { CYMAP(_let__, _let_); } + ; + +LexBind + : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf ; LetOrConst - : "let" - | "const" + : LexLet LexSetRegExp "!let" LexBind { $$ = false; } + | LexLet LexSetRegExp "const" { $$ = true; } ; BindingList_ - : "," BindingList { $$ = $2; } + : "," LexBind BindingList { $$ = $3; } | { $$ = NULL; } ; @@ -1276,8 +1394,12 @@ LexicalBinding ; /* }}} */ /* 13.3.2 Variable Statement {{{ */ +VariableStatement_ + : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); } + ; + VariableStatement - : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } + : VariableStatement_ Terminator { $$ = $1; } ; VariableDeclarationList_ @@ -1286,7 +1408,7 @@ VariableDeclarationList_ ; VariableDeclarationList - : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); } + : LexBind VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($2, $3); } ; VariableDeclaration @@ -1301,11 +1423,11 @@ BindingPattern ; ObjectBindingPattern - : BRACE BindingPropertyListOpt "}" + : "let {" BindingPropertyListOpt "}" ; ArrayBindingPattern - : "[" { CYNOT(@$); } + : "let [" { CYNOT(@$); } ; BindingPropertyList_ @@ -1328,8 +1450,8 @@ BindingProperty ; BindingElement - : SingleNameBinding { $$ = $1; } - | BindingPattern InitializerOpt { CYNOT(@$); } + : LexBind SingleNameBinding { $$ = $2; } + | LexBind BindingPattern InitializerOpt { CYNOT(@$); } ; SingleNameBinding @@ -1346,8 +1468,11 @@ EmptyStatement ; /* }}} */ /* 13.5 Expression Statement {{{ */ +ExpressionStatement_ + : Expression { $$ = CYNew CYExpress($1); } + ExpressionStatement - : Expression Terminator { $$ = CYNew CYExpress($1); } + : ExpressionStatement_ Terminator { $$ = $1; } ; /* }}} */ /* 13.6 The if Statement {{{ */ @@ -1364,25 +1489,28 @@ IfStatement IterationStatement : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); } | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); } - | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); } + | "for" "(" LexPushInOn ForStatementInitializer LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $6, $8, $10); } + | "for" "(" LexPushInOn LexLet LexSetRegExp Var_ LexBind BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($8, $9), $12, $14); } | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); } - | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } + | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } ; ForStatementInitializer - : ExpressionOpt { $$ = $1; } - | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); } - | LexSetRegExp LexicalDeclaration { CYNOT(@$); } + : LexLet LexSetRegExp EmptyStatement { $$ = $3; } + | LexLet ExpressionStatement_ ";" { $$ = $2; } + | LexLet LexSetRegExp VariableStatement_ ";" { $$ = $3; } + | LexicalDeclaration_ ";" { $$ = $1; } ; ForInStatementInitializer - : LeftHandSideExpression { $$ = $1; } - | LexSetRegExp Var_ ForBinding { $$ = $3; } - | LexSetRegExp ForDeclaration { $$ = $2; } + : LexLet AccessExpression LexCrement { $$ = $2; } + | LexLet LexSetRegExp IndirectExpression { $$ = $3; } + | LexLet LexSetRegExp Var_ LexBind ForBinding { $$ = CYNew CYForVariable($5); } + | ForDeclaration { $$ = $1; } ; ForDeclaration - : LetOrConst ForBinding { $$ = $2; } + : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); } ; ForBinding @@ -1412,7 +1540,7 @@ BreakStatement /* }}} */ /* 13.10 The return Statement {{{ */ Return - : "!return" LexNewLine + : "return" { if (!driver.return_.top()) CYERR(@1, "invalid return"); } LexNewLine ; ReturnStatement @@ -1456,7 +1584,7 @@ LabelledStatement LabelledItem : Statement { $$ = $1; } - | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; } + | LexSetStatement LexLet LexSetRegExp FunctionDeclaration { $$ = $4; } ; /* }}} */ /* 13.14 The throw Statement {{{ */ @@ -1477,7 +1605,7 @@ TryStatement ; Catch - : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); } + : "catch" "(" LexBind CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($4, $6); } ; Finally @@ -1497,11 +1625,11 @@ DebuggerStatement /* 14.1 Function Definitions {{{ */ FunctionDeclaration - : ";function" BindingIdentifier "(" FormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } + : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); } ; FunctionExpression - : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); } + : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); } ; StrictFormalParameters @@ -1509,7 +1637,7 @@ StrictFormalParameters ; FormalParameters - : { $$ = NULL; } + : LexBind { $$ = NULL; } | FormalParameterList ; @@ -1519,7 +1647,7 @@ FormalParameterList_ ; FormalParameterList - : FunctionRestParameter { CYNOT(@$); } + : LexBind FunctionRestParameter { CYNOT(@$); } | FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } ; @@ -1540,13 +1668,17 @@ FunctionStatementList ; /* }}} */ /* 14.2 Arrow Function Definitions {{{ */ +LexEqualRight + : { CYLIN(EqualRight); } + ; + ArrowFunction - : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); } + : LexSetRegExp ArrowParameters LexEqualRight "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $6); } ; ArrowParameters : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); } - | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); } + | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) $$ = NULL; else { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); } } ; ConciseBody @@ -1556,10 +1688,10 @@ ConciseBody /* }}} */ /* 14.3 Method Definitions {{{ */ MethodDefinition - : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYFunctionMethod($1, $3, $6); */ } + : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyMethod($1, $3, $6); } | GeneratorMethod { $$ = $1; } - | "get" PropertyName "(" ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodGet($2, $6); */ } - | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodSet($2, $4); */ } + | "get" PropertyName "(" ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyGetter($2, $6); } + | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertySetter($2, CYNew CYFunctionParameter($4), $7); } ; PropertySetParameterList @@ -1588,31 +1720,31 @@ Yield ; YieldExpression - : Yield LexSetRegExp "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } + : Yield LexSetRegExp NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } | Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ } | Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ } ; /* }}} */ /* 14.5 Class Definitions {{{ */ ClassDeclaration - : ";class" BindingIdentifier ClassTail { CYNOT(@$); } + : ";class" BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($2, $3); } ; ClassExpression - : "class" BindingIdentifierOpt ClassTail { CYNOT(@$); } + : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); } ; ClassTail - : ClassHeritageOpt BRACE ClassBodyOpt "}" + : ClassHeritageOpt { driver.class_.push($1); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $1; } ; ClassHeritage - : "extends" LeftHandSideExpression + : "extends" AccessExpression { $$ = CYNew CYClassTail($2); } ; ClassHeritageOpt - : ClassHeritage - | + : ClassHeritage { $$ = $1; } + | { $$ = CYNew CYClassTail(NULL); } ; ClassBody @@ -1634,8 +1766,8 @@ ClassElementListOpt ; ClassElement - : MethodDefinition - | "static" MethodDefinition + : MethodDefinition { if (CYFunctionExpression *constructor = $1->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$1; } + | "static" MethodDefinition { driver.class_.top()->static_->*$2; } | ";" ; /* }}} */ @@ -1651,7 +1783,7 @@ ScriptBody ScriptBodyOpt : ScriptBody { $$ = $1; } - | LexSetStatement LexSetRegExp { $$ = NULL; } + | LexSetStatement LexLet LexSetRegExp { $$ = NULL; } ; /* }}} */ /* 15.2 Modules {{{ */ @@ -1678,8 +1810,8 @@ ModuleItemListOpt ; ModuleItem - : LexSetStatement LexSetRegExp ImportDeclaration - | LexSetStatement LexSetRegExp ExportDeclaration + : LexSetStatement LexLet LexSetRegExp ImportDeclaration + | LexSetStatement LexLet LexSetRegExp ExportDeclaration | StatementListItem ; /* }}} */ @@ -1752,7 +1884,7 @@ ExportDeclaration_ ; ExportDeclaration - : "export" LexSetStatement LexSetRegExp ExportDeclaration_ + : "export" LexSetStatement LexLet LexSetRegExp ExportDeclaration_ | "export" Declaration ; @@ -1853,13 +1985,13 @@ ClassSuperOpt | { $$ = NULL; } ; -ClassFieldListOpt - : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); } +ImplementationFieldListOpt + : LexSetRegExp TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($2, $4); } | LexSetRegExp { $$ = NULL; } ; -ClassFields - : BRACE ClassFieldListOpt "}" { $$ = $2; } +ImplementationFields + : BRACE ImplementationFieldListOpt "}" { $$ = $2; } ; MessageScope @@ -1891,7 +2023,7 @@ MessageParameters ; ClassMessageDeclaration - : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); } + : MessageScope TypeOpt MessageParameters BRACE LexPushSuperOn FunctionBody "}" LexPopSuper { $$ = CYNew CYMessage($1, $2, $3, $6); } ; ClassMessageDeclarationListOpt @@ -1899,11 +2031,6 @@ ClassMessageDeclarationListOpt | { $$ = NULL; } ; -ClassName - : Identifier { $$ = $1; } - | "(" AssignmentExpression ")" { $$ = $2; } - ; - // XXX: this should be AssignmentExpressionNoRight ClassProtocols : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); } @@ -1919,8 +2046,8 @@ ClassProtocolListOpt | { $$ = NULL; } ; -ClassStatement - : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } +ImplementationStatement + : "@implementation" Identifier ClassSuperOpt ClassProtocolListOpt ImplementationFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYImplementation($2, $3, $4, $5, $6); } ; CategoryName @@ -1928,17 +2055,17 @@ CategoryName ; CategoryStatement - : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } + : "@implementation" Identifier CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } ; Statement__ - : ClassStatement { $$ = $1; } + : ImplementationStatement { $$ = $1; } | CategoryStatement { $$ = $1; } ; /* }}} */ /* Cycript (Objective-C): Send Message {{{ */ VariadicCall - : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); } + : "," AssignmentExpressionClassic VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); } | { $$ = NULL; } ; @@ -1953,7 +2080,7 @@ SelectorCall_ ; SelectorCall - : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); } + : SelectorWordOpt ":" AssignmentExpressionClassic SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); } ; SelectorList @@ -1962,7 +2089,7 @@ SelectorList ; MessageExpression - : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); } + : "[" LexPushInOff AssignmentExpressionClassic { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); } | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); } ; @@ -2035,8 +2162,12 @@ PrimaryExpression @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ -LeftHandSideExpression - : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); } +UnaryExpression_ + : IndirectExpression { $$ = $1; } + ; + +IndirectExpression + : "*" UnaryExpression { $$ = CYNew CYIndirect($2); } ; UnaryExpression_ @@ -2266,7 +2397,7 @@ Comprehension ; ComprehensionFor - : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); } + : "for" "each" "(" LexPushInOn LexBind ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($6, $9); } ; /* }}} */ /* JavaScript FTL: for each {{{ */ @@ -2274,15 +2405,6 @@ IterationStatement : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); } ; /* }}} */ -/* JavaScript FTL: let Statements {{{ */ -LetStatement - : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } - ; - -Statement__ - : LetStatement - ; -/* }}} */ /* JavaScript FTW: Array Comprehensions {{{ */ PrimaryExpression @@ -2304,8 +2426,8 @@ ComprehensionTail ; ComprehensionFor - : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); } - | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); } + : "for" "(" LexPushInOn LexBind ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($5, $8); } + | "for" "(" LexPushInOn LexBind ForBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); } ; ComprehensionIf @@ -2340,7 +2462,11 @@ RubyProcParameters RubyProcParametersOpt : RubyProcParameters { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } + ; + +LexOpenBrace + : { CYLIN(OpenBrace); } ; RubyProcExpression @@ -2352,7 +2478,7 @@ PrimaryExpression ; PostfixExpression - : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } + : PostfixExpression LexOpenBrace RubyProcExpression { $$ = CYNew CYRubyBlock($1, $3); } ; /* }}} */