X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/8b77acf10ecd1824cfd522f090e2288acead7384..b0fa27613239b5653fe8daf554a15993a015d4ea:/Parser.ypp.in diff --git a/Parser.ypp.in b/Parser.ypp.in index b895588..0c7b505 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -113,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); @@ -124,9 +126,48 @@ _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::OpenBrace: + case tk::OpenBracket: + case tk::OpenParen: + driver.in_.push(false); + break; + + case tk::_in_: + if (driver.in_.top()) + token = tk::_in__; + break; + + case tk::CloseBrace: + case tk::CloseBracket: + case tk::CloseParen: + driver.in_.pop(); + 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; } @@ -142,14 +183,30 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY 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" @@ -260,9 +317,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" @@ -327,10 +386,9 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _instanceof_ "instanceof" %token _new_ "new" %token _return_ "return" -%token _return__ "!return" %token _super_ "super" -%token _super__ "!super" %token _switch_ "switch" +%token _target_ "target" %token _this_ "this" %token _throw_ "throw" %token _try_ "try" @@ -357,6 +415,7 @@ _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" @@ -388,6 +447,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" @@ -400,13 +460,14 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token Identifier_ %token NumericLiteral %token StringLiteral -%token RegularExpressionLiteral +%token RegularExpressionLiteral_ %token NoSubstitutionTemplate %token TemplateHead %token TemplateMiddle %token TemplateTail +%type AccessExpression %type AdditiveExpression %type ArgumentList_ %type ArgumentList @@ -485,10 +546,13 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type GeneratorMethod %type HoistableDeclaration %type Identifier +%type IdentifierNoOf %type IdentifierType +%type IdentifierTypeNoOf %type IdentifierName %type IdentifierReference %type IfStatement +%type IndirectExpression %type Initializer %type InitializerOpt %type IterationStatement @@ -521,6 +585,8 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type PropertyDefinitionList %type PropertyDefinitionListOpt %type PropertySetParameterList +%type RegularExpressionLiteral +%type RegularExpressionSlash %type RelationalExpression %type ReturnStatement %type RubyProcExpression @@ -629,9 +695,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY @end /* }}} */ /* Token Priorities {{{ */ -%nonassoc "" -%left "++" "--" "{" - %nonassoc "if" %nonassoc "else" /* }}} */ @@ -664,11 +727,11 @@ LexPushYieldOff: { driver.yield_.push(false); }; LexPopYield: { driver.yield_.pop(); }; LexSetRegExp - : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } } + : ; LexNewLine - : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; } + : { CYMPT(@$); driver.next_ = true; } ; LexNoStar @@ -707,7 +770,6 @@ IdentifierName : Word { $$ = $1; } | "for" { $$ = CYNew CYWord("for"); } | "in" { $$ = CYNew CYWord("in"); } - | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); } | "instanceof" { $$ = CYNew CYWord("instanceof"); } ; @@ -717,12 +779,12 @@ NewLineOpt ; Word - : Identifier { $$ = $1; } + : IdentifierNoOf { $$ = $1; } | "auto" { $$ = CYNew CYWord("auto"); } | "break" { $$ = CYNew CYWord("break"); } | "case" { $$ = CYNew CYWord("case"); } | "catch" { $$ = CYNew CYWord("catch"); } - | "class" { $$ = CYNew CYWord("class"); } + | "class" LexOf { $$ = CYNew CYWord("class"); } | ";class" { $$ = CYNew CYWord("class"); } | "const" { $$ = CYNew CYWord("const"); } | "continue" { $$ = CYNew CYWord("continue"); } @@ -736,16 +798,15 @@ Word | "extends" { $$ = CYNew CYWord("extends"); } | "false" { $$ = CYNew CYWord("false"); } | "finally" { $$ = CYNew CYWord("finally"); } - | "function" { $$ = CYNew CYWord("function"); } + | "function" LexOf { $$ = CYNew CYWord("function"); } | "if" { $$ = CYNew CYWord("if"); } | "import" { $$ = CYNew CYWord("import"); } | "!in" { $$ = CYNew CYWord("in"); } + | "!of" { $$ = CYNew CYWord("of"); } | "new" LexSetRegExp { $$ = CYNew CYWord("new"); } | "null" { $$ = CYNew CYWord("null"); } | "return" { $$ = CYNew CYWord("return"); } - | "!return" { $$ = CYNew CYWord("return"); } | "super" { $$ = CYNew CYWord("super"); } - | "!super" { $$ = CYNew CYWord("super"); } | "switch" { $$ = CYNew CYWord("switch"); } | "this" { $$ = CYNew CYWord("this"); } | "throw" { $$ = CYNew CYWord("throw"); } @@ -759,9 +820,6 @@ Word | "yield" { $$ = CYNew CYIdentifier("yield"); } | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); } - - // XXX: should be Identifier - | "let" { $$ = CYNew CYIdentifier("let"); } ; @begin ObjectiveC @@ -782,6 +840,16 @@ BooleanLiteral | "false" { $$ = CYNew CYFalse(); } ; /* }}} */ +/* 11.8.5 Regular Expression Literals {{{ */ +RegularExpressionSlash + : "/" { $$ = false; } + | "/=" { $$ = true; } + ; + +RegularExpressionLiteral + : RegularExpressionSlash { CYMPT(@$); driver.SetRegEx($1); } RegularExpressionLiteral_ { $$ = $3; } + ; +/* }}} */ /* 11.9 Automatic Semicolon Insertion {{{ */ StrictSemi @@ -795,7 +863,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 @@ -811,7 +879,8 @@ IdentifierReference ; BindingIdentifier - : Identifier { $$ = $1; } + : IdentifierNoOf { $$ = $1; } + | "!of" { $$ = CYNew CYIdentifier("of"); } | "yield" { $$ = CYNew CYIdentifier("yield"); } ; @@ -825,7 +894,7 @@ LabelIdentifier | "yield" { $$ = CYNew CYIdentifier("yield"); } ; -IdentifierType +IdentifierTypeNoOf : Identifier_ { $$ = $1; } | "abstract" { $$ = CYNew CYIdentifier("abstract"); } | "await" { $$ = CYNew CYIdentifier("await"); } @@ -841,9 +910,11 @@ IdentifierType | "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"); } | "package" { $$ = CYNew CYIdentifier("package"); } | "private" { $$ = CYNew CYIdentifier("private"); } | "protected" { $$ = CYNew CYIdentifier("protected"); } @@ -851,6 +922,7 @@ IdentifierType | "public" { $$ = CYNew CYIdentifier("public"); } | "set" { $$ = CYNew CYIdentifier("set"); } | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); } + | "target" { $$ = CYNew CYIdentifier("target"); } | "throws" { $$ = CYNew CYIdentifier("throws"); } | "transient" { $$ = CYNew CYIdentifier("transient"); } | "undefined" { $$ = CYNew CYIdentifier("undefined"); } @@ -862,8 +934,13 @@ IdentifierType @end ; -Identifier - : IdentifierType +IdentifierType + : IdentifierTypeNoOf { $$ = $1; } + | "of" { $$ = CYNew CYIdentifier("of"); } + ; + +IdentifierNoOf + : IdentifierTypeNoOf | "char" { $$ = CYNew CYIdentifier("char"); } | "int" { $$ = CYNew CYIdentifier("int"); } | "long" { $$ = CYNew CYIdentifier("long"); } @@ -883,6 +960,11 @@ Identifier | "YES" { $$ = CYNew CYIdentifier("YES"); } @end ; + +Identifier + : IdentifierNoOf { $$ = $1; } + | "of" { $$ = CYNew CYIdentifier("of"); } + ; /* }}} */ /* 12.2 Primary Expression {{{ */ PrimaryExpression @@ -901,10 +983,10 @@ PrimaryExpression ; CoverParenthesizedExpressionAndArrowParameterList - : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); } - | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; } - | "(" LexPushInOff LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); } - | "(" LexPushInOff Expression "," LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); } + : "(" Expression ")" { $$ = CYNew CYParenthetical($2); } + | "(" LexSetRegExp ")" { $$ = NULL; } + | "(" LexSetRegExp "..." BindingIdentifier ")" { CYNOT(@$); } + | "(" Expression "," LexSetRegExp "..." BindingIdentifier ")" { CYNOT(@$); } ; /* }}} */ /* 12.2.4 Literals {{{ */ @@ -912,13 +994,12 @@ Literal : NullLiteral { $$ = $1; } | BooleanLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } - | "Infinity" { $$ = CYNew CYNumber(std::numeric_limits::infinity()); } | StringLiteral { $$ = $1; } ; /* }}} */ /* 12.2.5 Array Initializer {{{ */ ArrayLiteral - : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); } + : "[" ElementListOpt "]" { $$ = CYNew CYArray($2); } ; ElementList @@ -934,7 +1015,7 @@ ElementListOpt /* }}} */ /* 12.2.6 Object Initializer {{{ */ ObjectLiteral - : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); } + : BRACE PropertyDefinitionListOpt "}" { $$ = CYNew CYObject($2); } ; PropertyDefinitionList_ @@ -1000,7 +1081,7 @@ TemplateSpans /* 12.3 Left-Hand-Side Expressions {{{ */ MemberAccess - : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); } + : "[" Expression "]" { $$ = CYNew CYDirectMember(NULL, $2); } | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); } | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } | TemplateLiteral { CYNOT(@$); } @@ -1015,8 +1096,8 @@ MemberExpression ; SuperProperty - : LexSetRegExp "!super" "[" Expression "]" { $$ = CYNew CYSuperAccess($4); } - | LexSetRegExp "!super" "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($4)); } + : 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 @@ -1044,11 +1125,11 @@ CallExpression ; SuperCall - : LexSetRegExp "!super" Arguments { $$ = CYNew CYSuperCall($3); } + : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } Arguments { $$ = CYNew CYSuperCall($4); } ; Arguments - : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; } + : "(" ArgumentListOpt ")" { $$ = $2; } ; ArgumentList_ @@ -1066,16 +1147,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 {{{ */ @@ -1094,7 +1184,7 @@ UnaryExpression_ ; UnaryExpression - : %prec "" PostfixExpression { $$ = $1; } + : PostfixExpression LexOpenBrace { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } ; /* }}} */ @@ -1251,17 +1341,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 @@ -1293,7 +1383,7 @@ StatementList StatementListOpt : StatementList { $$ = $1; } - | LexSetStatement LexSetRegExp { $$ = NULL; } + | LexSetStatement LexLet LexSetRegExp { $$ = NULL; } ; StatementListItem @@ -1310,13 +1400,25 @@ LexicalDeclaration : LexicalDeclaration_ Terminator { $$ = $1; } ; +LexLet + : { CYMAP(_let__, _let_); } + ; + +LexOf + : { CYMAP(_of__, _of_); } + ; + +LexBind + : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf + ; + LetOrConst - : "let" { $$ = false; } - | "const" { $$ = true; } + : LexLet LexSetRegExp "!let" LexBind { $$ = false; } + | LexLet LexSetRegExp "const" { $$ = true; } ; BindingList_ - : "," BindingList { $$ = $2; } + : "," LexBind BindingList { $$ = $3; } | { $$ = NULL; } ; @@ -1344,7 +1446,7 @@ VariableDeclarationList_ ; VariableDeclarationList - : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); } + : LexBind VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($2, $3); } ; VariableDeclaration @@ -1359,11 +1461,11 @@ BindingPattern ; ObjectBindingPattern - : BRACE BindingPropertyListOpt "}" + : "let {" BindingPropertyListOpt "}" ; ArrayBindingPattern - : "[" { CYNOT(@$); } + : "let [" { CYNOT(@$); } ; BindingPropertyList_ @@ -1386,8 +1488,8 @@ BindingProperty ; BindingElement - : SingleNameBinding { $$ = $1; } - | BindingPattern InitializerOpt { CYNOT(@$); } + : LexBind SingleNameBinding { $$ = $2; } + | LexBind BindingPattern InitializerOpt { CYNOT(@$); } ; SingleNameBinding @@ -1426,22 +1528,23 @@ 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, $6, $8, $10); } - | "for" "(" LexPushInOn LexSetRegExp Var_ BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($6, $7), $10, $12); } + | "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 AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } ; ForStatementInitializer - : LexSetRegExp EmptyStatement { $$ = $2; } - | ExpressionStatement_ ";" { $$ = $1; } - | LexSetRegExp VariableStatement_ ";" { $$ = $2; } - | LexSetRegExp LexicalDeclaration_ ";" { $$ = $2; } + : LexLet LexSetRegExp EmptyStatement { $$ = $3; } + | LexLet ExpressionStatement_ ";" { $$ = $2; } + | LexLet LexSetRegExp VariableStatement_ ";" { $$ = $3; } + | LexicalDeclaration_ ";" { $$ = $1; } ; ForInStatementInitializer - : LeftHandSideExpression { $$ = $1; } - | LexSetRegExp Var_ ForBinding { $$ = CYNew CYForVariable($3); } - | LexSetRegExp ForDeclaration { $$ = $2; } + : LexLet AccessExpression LexCrement { $$ = $2; } + | LexLet LexSetRegExp IndirectExpression { $$ = $3; } + | LexLet LexSetRegExp Var_ LexBind ForBinding { $$ = CYNew CYForVariable($5); } + | ForDeclaration { $$ = $1; } ; ForDeclaration @@ -1475,7 +1578,7 @@ BreakStatement /* }}} */ /* 13.10 The return Statement {{{ */ Return - : "!return" LexNewLine + : "return" { if (!driver.return_.top()) CYERR(@1, "invalid return"); } LexNewLine ; ReturnStatement @@ -1519,7 +1622,7 @@ LabelledStatement LabelledItem : Statement { $$ = $1; } - | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; } + | LexSetStatement LexLet LexSetRegExp FunctionDeclaration { $$ = $4; } ; /* }}} */ /* 13.14 The throw Statement {{{ */ @@ -1540,7 +1643,7 @@ TryStatement ; Catch - : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); } + : "catch" "(" LexBind CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($4, $6); } ; Finally @@ -1560,11 +1663,11 @@ DebuggerStatement /* 14.1 Function Definitions {{{ */ FunctionDeclaration - : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); } + : ";function" LexOf BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($3, $5, $9); } ; FunctionExpression - : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); } + : "function" LexOf BindingIdentifierOpt "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionExpression($3, $5, $9); } ; StrictFormalParameters @@ -1572,7 +1675,7 @@ StrictFormalParameters ; FormalParameters - : { $$ = NULL; } + : LexBind { $$ = NULL; } | FormalParameterList ; @@ -1582,7 +1685,7 @@ FormalParameterList_ ; FormalParameterList - : FunctionRestParameter { CYNOT(@$); } + : LexBind FunctionRestParameter { CYNOT(@$); } | FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } ; @@ -1603,8 +1706,12 @@ 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 @@ -1614,7 +1721,7 @@ ArrowParameters ConciseBody : AssignmentExpression { $$ = CYNew CYReturn($1); } - | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; } + | LexSetRegExp ";{" FunctionBody "}" { $$ = $3; } ; /* }}} */ /* 14.3 Method Definitions {{{ */ @@ -1635,11 +1742,11 @@ GeneratorMethod ; GeneratorDeclaration - : ";function" "*" BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ } + : ";function" LexOf "*" LexOf BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ } ; GeneratorExpression - : "function" "*" BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ } + : "function" LexOf "*" LexOf BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ } ; GeneratorBody @@ -1658,11 +1765,11 @@ YieldExpression /* }}} */ /* 14.5 Class Definitions {{{ */ ClassDeclaration - : ";class" BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($2, $3); } + : ";class" LexOf BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($3, $4); } ; ClassExpression - : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); } + : "class" LexOf BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($3, $4); } ; ClassTail @@ -1670,7 +1777,7 @@ ClassTail ; ClassHeritage - : "extends" LeftHandSideExpression { $$ = CYNew CYClassTail($2); } + : "extends" AccessExpression { $$ = CYNew CYClassTail($2); } ; ClassHeritageOpt @@ -1714,7 +1821,7 @@ ScriptBody ScriptBodyOpt : ScriptBody { $$ = $1; } - | LexSetStatement LexSetRegExp { $$ = NULL; } + | LexSetStatement LexLet LexSetRegExp { $$ = NULL; } ; /* }}} */ /* 15.2 Modules {{{ */ @@ -1741,8 +1848,8 @@ ModuleItemListOpt ; ModuleItem - : LexSetStatement LexSetRegExp ImportDeclaration - | LexSetStatement LexSetRegExp ExportDeclaration + : LexSetStatement LexLet LexSetRegExp ImportDeclaration + | LexSetStatement LexLet LexSetRegExp ExportDeclaration | StatementListItem ; /* }}} */ @@ -1815,7 +1922,7 @@ ExportDeclaration_ ; ExportDeclaration - : "export" LexSetStatement LexSetRegExp ExportDeclaration_ + : "export" LexSetStatement LexLet LexSetRegExp ExportDeclaration_ | "export" Declaration ; @@ -1847,14 +1954,14 @@ ExportSpecifier /* Cycript (C): Type Encoding {{{ */ TypeSignifier : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); } - | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; } + | "(" "*" TypeQualifierRight ")" { $$ = $3; } ; SuffixedType : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); } - | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); } - | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); } - | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); } + | "(" "^" TypeQualifierRight ")" "(" TypedParameterListOpt ")" { $$ = $3; $$->modifier_ = CYNew CYTypeBlockWith($6, $$->modifier_); } + | TypeSignifier "(" TypedParameterListOpt ")" { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); } + | "(" TypedParameterListOpt ")" { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($2, $$->modifier_); } | TypeSignifier { $$ = $1; } | { $$ = CYNew CYTypedIdentifier(@$); } ; @@ -1917,7 +2024,7 @@ ClassSuperOpt ; ImplementationFieldListOpt - : TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($1, $3); } + : LexSetRegExp TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($2, $4); } | LexSetRegExp { $$ = NULL; } ; @@ -1936,7 +2043,7 @@ TypeOpt ; MessageParameter - : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); } + : Word ":" TypeOpt BindingIdentifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); } ; MessageParameterList @@ -2020,8 +2127,8 @@ SelectorList ; MessageExpression - : "[" 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); } + : "[" AssignmentExpressionClassic { driver.contexts_.push_back($2); } SelectorList "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($2, $4); } + | "[" LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" { $$ = CYNew CYSendSuper($5); } ; SelectorExpression_ @@ -2040,7 +2147,7 @@ SelectorExpressionOpt PrimaryExpression : MessageExpression { $$ = $1; } - | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); } + | "@selector" "(" SelectorExpression ")" { $$ = CYNew CYSelector($3); } ; /* }}} */ @end @@ -2081,7 +2188,7 @@ PrimaryExpression /* }}} */ /* Cycript (Objective-C): Block Expressions {{{ */ PrimaryExpression - : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else CYERR($2->location_, "expected parameters"); } + : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE FunctionBody "}" { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $5); else CYERR($2->location_, "expected parameters"); } ; /* }}} */ /* Cycript (Objective-C): Instance Literals {{{ */ @@ -2093,8 +2200,12 @@ PrimaryExpression @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ -LeftHandSideExpression - : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); } +UnaryExpression_ + : IndirectExpression { $$ = $1; } + ; + +IndirectExpression + : "*" UnaryExpression { $$ = CYNew CYIndirect($2); } ; UnaryExpression_ @@ -2128,7 +2239,7 @@ TypedParameterListOpt ; PrimaryExpression - : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); } + : "[" LexSetRegExp "&" LexSetRegExp "]" "(" TypedParameterListOpt ")" "->" TypedIdentifier BRACE FunctionBody "}" { $$ = CYNew CYLambda($10, $7, $12); } ; /* }}} */ /* Cycript (C): Type Definitions {{{ */ @@ -2211,7 +2322,7 @@ AttributeIdentifier PropertySelector_ : PropertySelector { $$ = $1; } - | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); } + | "[" Expression "]" { $$ = CYNew CYSelector($2); } ; PropertySelector @@ -2324,7 +2435,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 {{{ */ @@ -2339,7 +2450,7 @@ PrimaryExpression ; ArrayComprehension - : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; } + : "[" Comprehension "]" { $$ = $2; } ; Comprehension @@ -2353,8 +2464,8 @@ ComprehensionTail ; ComprehensionFor - : "for" "(" LexPushInOn ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); } - | "for" "(" LexPushInOn ForBinding "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 @@ -2378,7 +2489,7 @@ RubyProcParameterList_ ; RubyProcParameterList - : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); } + : BindingIdentifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); } | { $$ = NULL; } ; @@ -2389,7 +2500,11 @@ RubyProcParameters RubyProcParametersOpt : RubyProcParameters { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } + ; + +LexOpenBrace + : { CYLIN(OpenBrace); } ; RubyProcExpression @@ -2397,11 +2512,11 @@ RubyProcExpression ; PrimaryExpression - : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); } + : BRACE RubyProcParameters StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } ; PostfixExpression - : PostfixExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } + : PostfixExpression LexOpenBrace RubyProcExpression { $$ = CYNew CYRubyBlock($1, $3); } ; /* }}} */