X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/0508916952b3c0f050adfa26d25d5af447aa98b5..aea76473fa673adddb206e34d675e59c298e3581:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index 02d2f01..9b9a05c 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -161,6 +161,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %token Equal "=" %token EqualEqual "==" %token EqualEqualEqual "===" +%token EqualRight "=>" %token Exclamation "!" %token ExclamationEqual "!=" %token ExclamationEqualEqual "!==" @@ -307,6 +308,7 @@ int cylex(YYSTYPE *, cy::location *, void *); // Woah?! %token Each "each" +%token Of "of" @begin E4X // E4X Conditional @@ -327,6 +329,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ArgumentListOpt %type Arguments %type ArrayLiteral +%type ArrowFunction +%type ArrowParameters %type AssignmentExpression %type BindingIdentifier %type BitwiseANDExpression @@ -348,12 +352,12 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ComprehensionListOpt %type ConditionalExpression %type ContinueStatement +%type ConciseBody %type DebuggerStatement %type Declaration__ %type Declaration_ %type Declaration %type DefaultClause -%type DoWhileStatement %type Element %type ElementOpt %type ElementList @@ -362,14 +366,12 @@ int cylex(YYSTYPE *, cy::location *, void *); %type EmptyStatement %type EqualityExpression %type Expression_ -%type Expression +%type Expression %type ExpressionOpt %type ExpressionStatement %type FinallyOpt %type ForComprehension -%type ForStatement %type ForStatementInitialiser -%type ForInStatement %type ForInStatementInitialiser %type FormalParameter %type FormalParameterList_ @@ -380,6 +382,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type FunctionExpression %type Identifier %type IdentifierOpt +%type IdentifierName %type IfComprehension %type IfStatement %type Initialiser @@ -400,7 +403,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type NewExpression %type NullLiteral %type ObjectLiteral -%type Parenthetical +%type Parenthetical +%type ParentheticalOpt %type PostfixExpression %type PrimaryExpression %type Program @@ -408,9 +412,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ProgramBodyOpt %type PropertyName_ %type PropertyName -%type PropertyNameAndValueList_ -%type PropertyNameAndValueList -%type PropertyNameAndValueListOpt +%type PropertyDefinition +%type PropertyDefinitionList_ +%type PropertyDefinitionList +%type PropertyDefinitionListOpt %type RelationalExpression %type ReturnStatement %type RubyProcExpression @@ -435,8 +440,9 @@ int cylex(YYSTYPE *, cy::location *, void *); %type VariableDeclarationList_ %type VariableDeclarationList %type VariableStatement -%type WhileStatement %type WithStatement +%type Word +%type WordOpt @begin ObjectiveC %type CategoryStatement @@ -466,8 +472,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorWordOpt %type TypeOpt %type VariadicCall -%type Word -%type WordOpt @end @begin E4X @@ -518,17 +522,16 @@ LexSetRegExp : { 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 ; /* }}} */ @@ -541,18 +544,13 @@ StrictSemi : { 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 ; @@ -561,12 +559,15 @@ TerminatorOpt | ;*/ -@begin ObjectiveC NewLineOpt : "\n" | ; +IdentifierName + : Word { $$ = $1; } + ; + Word : Identifier { $$ = $1; } | "break" NewLineOpt { $$ = $1; } @@ -590,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; } @@ -612,6 +618,7 @@ WordOpt | { $$ = NULL; } ; +@begin ObjectiveC PrimaryExpression : "@" LiteralNoRE { $$ = CYNew CYBox($2); } | "@" ArrayLiteral { $$ = CYNew CYBox($2); } @@ -648,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 @@ -685,6 +695,11 @@ Parenthetical : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; } ; +ParentheticalOpt + : Parenthetical { $$ = $1; } + | { $$ = NULL; } + ; + PrimaryExpression : "this" { $$ = $1; } | Identifier { $$ = CYNew CYVariable($1); } @@ -722,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; } ; @@ -753,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; } ; @@ -912,6 +934,7 @@ ConditionalExpression /* 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); } @@ -928,12 +951,12 @@ AssignmentExpression /* }}} */ /* 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 @@ -1086,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); } ; @@ -1114,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 @@ -1127,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 {{{ */ @@ -1176,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 {{{ */ @@ -1200,7 +1220,7 @@ DebuggerStatement ; /* }}} */ -/* 13 Function Definition {{{ */ +/* 13.1 Function Definitions {{{ */ FunctionDeclaration : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } ; @@ -1236,6 +1256,21 @@ FunctionBody : 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); } @@ -1441,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; } ; /* }}} */ @@ -1624,12 +1659,6 @@ Statement__ /* }}} */ @end -/* ECMAScript5: Object Literal Trailing Comma {{{ */ -PropertyNameAndValueList_ - : "," { $$ = NULL; } - ; -/* }}} */ - /* JavaScript 1.7: Array Comprehensions {{{ */ IfComprehension : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); } @@ -1637,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 @@ -1655,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 {{{ */