X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/2eb8215d4156f442f856026f1714aef7ed185752..55fc1817b91ea69a393f7d149ea6848be5abbfed:/Cycript.yy.in?ds=sidebyside diff --git a/Cycript.yy.in b/Cycript.yy.in index 7cc9ef9..d8ec64a 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -1,40 +1,22 @@ -/* Cycript - Inlining/Optimizing JavaScript Compiler - * Copyright (C) 2009 Jay Freeman (saurik) +/* Cycript - Optimizing JavaScript Compiler/Runtime + * Copyright (C) 2009-2010 Jay Freeman (saurik) */ -/* Modified BSD License {{{ */ +/* GNU Lesser General Public License, Version 3 {{{ */ /* - * Redistribution and use in source and binary - * forms, with or without modification, are permitted - * provided that the following conditions are met: + * Cycript is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. * - * 1. Redistributions of source code must retain the - * above copyright notice, this list of conditions - * and the following disclaimer. - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions - * and the following disclaimer in the documentation - * and/or other materials provided with the - * distribution. - * 3. The name of the author may not be used to endorse - * or promote products derived from this software - * without specific prior written permission. + * Cycript is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + * You should have received a copy of the GNU Lesser General Public License + * along with Cycript. If not, see . +**/ /* }}} */ @if Bison23 %{ @@ -194,6 +176,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %token Percent "%" %token PercentEqual "%=" %token Period "." +%token PeriodPeriodPeriod "..." %token Pipe "|" %token PipeEqual "|=" %token PipePipe "||" @@ -336,23 +319,25 @@ int cylex(YYSTYPE *, cy::location *, void *); %type AdditiveExpression %type AdditiveExpressionNoBF -%type ArgumentList %type ArgumentList_ +%type ArgumentList %type ArgumentListOpt %type Arguments %type ArrayLiteral %type AssigneeExpression %type AssigneeExpressionNoBF -%type AssignmentExpression %type AssignmentExpression_ +%type AssignmentExpression %type AssignmentExpressionNoBF %type AssignmentExpressionNoIn +%type BindingIdentifier %type BitwiseANDExpression %type BitwiseANDExpressionNoBF %type BitwiseANDExpressionNoIn -%type Block %type Block_ +%type Block %type BooleanLiteral +%type BindingElement %type BitwiseORExpression %type BitwiseORExpressionNoBF %type BitwiseORExpressionNoIn @@ -360,6 +345,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type BitwiseXORExpressionNoBF %type BitwiseXORExpressionNoIn %type BreakStatement +%type BreakableStatement %type CallExpression %type CallExpressionNoBF %type CaseBlock @@ -372,6 +358,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ConditionalExpressionNoBF %type ConditionalExpressionNoIn %type ContinueStatement +%type DebuggerStatement +%type Declaration %type DefaultClause %type DoWhileStatement %type Element @@ -383,12 +371,12 @@ int cylex(YYSTYPE *, cy::location *, void *); %type EqualityExpression %type EqualityExpressionNoBF %type EqualityExpressionNoIn +%type Expression_ %type Expression %type ExpressionOpt -%type Expression_ %type ExpressionNoBF -%type ExpressionNoIn %type ExpressionNoIn_ +%type ExpressionNoIn %type ExpressionNoInOpt %type ExpressionStatement %type FinallyOpt @@ -397,8 +385,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ForStatementInitialiser %type ForInStatement %type ForInStatementInitialiser -%type FormalParameterList +%type FormalParameter %type FormalParameterList_ +%type FormalParameterList +%type FormalParameterListOpt %type FunctionBody %type FunctionDeclaration %type FunctionExpression @@ -414,7 +404,9 @@ int cylex(YYSTYPE *, cy::location *, void *); %type LabelledStatement %type LeftHandSideExpression %type LeftHandSideExpressionNoBF -//%type LetStatement +//%type LetExpression +%type LetStatement +%type LexicalDeclaration %type Literal %type LiteralNoRE %type LiteralRE @@ -425,13 +417,13 @@ int cylex(YYSTYPE *, cy::location *, void *); %type LogicalORExpressionNoBF %type LogicalORExpressionNoIn %type MemberAccess -%type MemberExpression %type MemberExpression_ +%type MemberExpression %type MemberExpressionNoBF %type MultiplicativeExpression %type MultiplicativeExpressionNoBF -%type NewExpression %type NewExpression_ +%type NewExpression %type NewExpressionNoBF %type NullLiteral %type ObjectLiteral @@ -443,42 +435,45 @@ int cylex(YYSTYPE *, cy::location *, void *); %type PrimaryExpressionNoRE %type PrimaryExpressionBF %type Program -%type PropertyName +%type ProgramBody +%type ProgramBodyOpt %type PropertyName_ -%type PropertyNameAndValueList +%type PropertyName %type PropertyNameAndValueList_ +%type PropertyNameAndValueList %type PropertyNameAndValueListOpt -%type RelationalExpression %type RelationalExpression_ +%type RelationalExpression %type RelationalExpressionNoBF -%type RelationalExpressionNoIn %type RelationalExpressionNoIn_ +%type RelationalExpressionNoIn %type ReturnStatement %type RubyProcExpression -%type RubyProcParameterList +%type RubyProcExpressionNoOA %type RubyProcParameterList_ +%type RubyProcParameterList +%type RubyProcParameters %type RubyProcParametersOpt %type ShiftExpression %type ShiftExpressionNoBF -%type SourceElement -%type SourceElement_ -%type SourceElements -%type Statement +%type SingleNameBinding %type Statement_ +%type Statement %type StatementList %type StatementListOpt +%type StatementListItem %type SwitchStatement %type ThrowStatement %type TryStatement -%type UnaryExpression %type UnaryExpression_ +%type UnaryExpression %type UnaryExpressionNoBF %type VariableDeclaration %type VariableDeclarationNoIn -%type VariableDeclarationList %type VariableDeclarationList_ -%type VariableDeclarationListNoIn +%type VariableDeclarationList %type VariableDeclarationListNoIn_ +%type VariableDeclarationListNoIn %type VariableStatement %type WhileStatement %type WithStatement @@ -513,10 +508,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MessageParameterList %type MessageParameterListOpt %type MessageScope -%type SelectorCall %type SelectorCall_ -%type SelectorExpression +%type SelectorCall %type SelectorExpression_ +%type SelectorExpression %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt @@ -528,10 +523,10 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin E4X %type PropertyIdentifier_ -%type PropertySelector %type PropertySelector_ -%type QualifiedIdentifier +%type PropertySelector %type QualifiedIdentifier_ +%type QualifiedIdentifier %type WildcardIdentifier %type XMLComment %type XMLCDATA @@ -592,14 +587,14 @@ Terminator_ | "\n" StrictSemi ; -TerminatorOpt +Terminator : Terminator_ - | error { yyerrok; driver.errors_.pop_back(); } StrictSemi + | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi ; -Terminator +TerminatorOpt : Terminator_ - | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi + | error { yyerrok; driver.errors_.pop_back(); } StrictSemi ; /*CommaOpt @@ -613,11 +608,6 @@ NewLineOpt | ; -WordOpt - : Word { $$ = $1; } - | { $$ = NULL; } - ; - Word : Identifier { $$ = $1; } | "break" NewLineOpt { $$ = $1; } @@ -657,6 +647,18 @@ Word | "while" { $$ = $1; } | "with" { $$ = $1; } ; + +WordOpt + : Word { $$ = $1; } + | { $$ = NULL; } + ; + +PrimaryExpressionNo + : "@" LiteralNoRE { $$ = CYNew CYBox($2); } + | "@" ArrayLiteral { $$ = CYNew CYBox($2); } + | "@" ObjectLiteral { $$ = CYNew CYBox($2); } + | "@" "(" Expression ")" { $$ = CYNew CYBox($3); } + ; @end Identifier @@ -687,7 +689,7 @@ Identifier | "transient" { $$ = $1; } | "volatile" { $$ = $1; } - | "let" { $$ = $1; } + // XXX: is this allowed?! | "let" { $$ = $1; } | "yield" { $$ = $1; } | "each" { $$ = $1; } @@ -703,7 +705,6 @@ LiteralNoRE | BooleanLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } | StringLiteral { $$ = $1; } - | "@" StringLiteral { $$ = $2; } ; LiteralRE @@ -765,19 +766,19 @@ ElementOpt | LexSetRegExp { $$ = NULL; } ; -ElementListOpt - : ElementList { $$ = $1; } - | LexSetRegExp { $$ = NULL; } - ; - ElementList : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); } | Element { $$ = CYNew CYElement($1, NULL); } ; + +ElementListOpt + : ElementList { $$ = $1; } + | LexSetRegExp { $$ = NULL; } + ; /* }}} */ /* 11.1.5 Object Initialiser {{{ */ ObjectLiteral - : OpenBrace PropertyNameAndValueListOpt "}" { $$ = CYNew CYObject($2); } + : Brace PropertyNameAndValueListOpt "}" { $$ = CYNew CYObject($2); } ; PropertyNameAndValueList_ @@ -785,15 +786,15 @@ PropertyNameAndValueList_ | { $$ = NULL; } ; +PropertyNameAndValueList + : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); } + ; + PropertyNameAndValueListOpt : PropertyNameAndValueList { $$ = $1; } | { $$ = NULL; } ; -PropertyNameAndValueList - : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); } - ; - PropertyName_ : Identifier { $$ = $1; } | StringLiteral { $$ = $1; } @@ -806,16 +807,16 @@ PropertyName /* }}} */ /* 11.2 Left-Hand-Side Expressions {{{ */ -MemberExpression_ - : "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($2, $3); } - ; - MemberAccess : "[" Expression "]" { $$ = CYNew CYDirectMember(NULL, $2); } | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); } | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } ; +MemberExpression_ + : "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($2, $3); } + ; + MemberExpression : PrimaryExpression { $$ = $1; } | LexSetRegExp FunctionExpression { $$ = $2; } @@ -884,15 +885,15 @@ ArgumentList_ | { $$ = NULL; } ; +ArgumentList + : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); } + ; + ArgumentListOpt : ArgumentList { $$ = $1; } | LexSetRegExp { $$ = NULL; } ; -ArgumentList - : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); } - ; - Arguments : "(" ArgumentListOpt ")" { $$ = $2; } ; @@ -1011,14 +1012,6 @@ ShiftExpressionNoBF ; /* }}} */ /* 11.8 Relational Operators {{{ */ -RelationalExpressionNoIn_ - : "<" ShiftExpression { $$ = CYNew CYLess(NULL, $2); } - | ">" ShiftExpression { $$ = CYNew CYGreater(NULL, $2); } - | "<=" ShiftExpression { $$ = CYNew CYLessOrEqual(NULL, $2); } - | ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual(NULL, $2); } - | "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf(NULL, $2); } - ; - RelationalExpression_ : RelationalExpressionNoIn_ { $$ = $1; } | "in" ShiftExpression { $$ = CYNew CYIn(NULL, $2); } @@ -1029,6 +1022,14 @@ RelationalExpression | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; } ; +RelationalExpressionNoIn_ + : "<" ShiftExpression { $$ = CYNew CYLess(NULL, $2); } + | ">" ShiftExpression { $$ = CYNew CYGreater(NULL, $2); } + | "<=" ShiftExpression { $$ = CYNew CYLessOrEqual(NULL, $2); } + | ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual(NULL, $2); } + | "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf(NULL, $2); } + ; + RelationalExpressionNoIn : ShiftExpression { $$ = $1; } | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; } @@ -1226,9 +1227,8 @@ Expression_ | { $$ = NULL; } ; -ExpressionNoIn_ - : "," ExpressionNoIn { $$ = CYNew CYCompound($2); } - | { $$ = NULL; } +Expression + : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } ; ExpressionOpt @@ -1236,19 +1236,20 @@ ExpressionOpt | LexSetRegExp { $$ = NULL; } ; -ExpressionNoInOpt - : ExpressionNoIn { $$ = $1; } - | LexSetRegExp { $$ = NULL; } - ; - -Expression - : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } +ExpressionNoIn_ + : "," ExpressionNoIn { $$ = CYNew CYCompound($2); } + | { $$ = NULL; } ; ExpressionNoIn : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } ; +ExpressionNoInOpt + : ExpressionNoIn { $$ = $1; } + | LexSetRegExp { $$ = NULL; } + ; + ExpressionNoBF : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } ; @@ -1261,20 +1262,30 @@ Statement_ | EmptyStatement { $$ = $1; } | ExpressionStatement { $$ = $1; } | IfStatement { $$ = $1; } - | IterationStatement { $$ = $1; } + | BreakableStatement { $$ = $1; } | ContinueStatement { $$ = $1; } | BreakStatement { $$ = $1; } | ReturnStatement { $$ = $1; } | WithStatement { $$ = $1; } | LabelledStatement { $$ = $1; } - | SwitchStatement { $$ = $1; } | ThrowStatement { $$ = $1; } | TryStatement { $$ = $1; } + | DebuggerStatement { $$ = $1; } ; Statement : LexSetRegExp Statement_ { $$ = $2; } ; + +Declaration + : FunctionDeclaration { $$ = $1; } + | LexicalDeclaration { $$ = $1; } + ; + +BreakableStatement + : IterationStatement { $$ = $1; } + | SwitchStatement { $$ = $1; } + ; /* }}} */ /* 12.1 Block {{{ */ Block_ @@ -1282,19 +1293,41 @@ Block_ ; Block - : Block_ { if ($1) $$ = CYNew CYBlock($1); else $$ = CYNew CYEmpty(); } + : Block_ { $$ = CYNew CYBlock($1); } ; StatementList - : Statement StatementListOpt { $1->SetNext($2); $$ = $1; } + : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; } ; StatementListOpt : StatementList { $$ = $1; } | LexSetRegExp { $$ = NULL; } ; + +StatementListItem + : Statement { $$ = $1; } + | LexSetRegExp Declaration { $$ = $2; } + ; +/* }}} */ +/* 12.2 Declarations {{{ */ +BindingIdentifier + : Identifier { $$ = $1; } + ; + +// XXX: BindingPattern +/* }}} */ +/* 12.2.1 Let and Const Declarations {{{ */ +LexicalDeclaration + : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } + ; + +LetOrConst + : "let" + | "const" + ; /* }}} */ -/* 12.2 Variable Statement {{{ */ +/* 12.2.2 Variable Statement {{{ */ VariableStatement : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); } ; @@ -1304,25 +1337,31 @@ VariableDeclarationList_ | { $$ = NULL; } ; +VariableDeclarationList + : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); } + ; + VariableDeclarationListNoIn_ : "," VariableDeclarationListNoIn { $$ = $2; } | { $$ = NULL; } ; -VariableDeclarationList - : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); } - ; - VariableDeclarationListNoIn : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = CYNew CYDeclarations($1, $2); } ; VariableDeclaration - : Identifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } + : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } + // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); } ; VariableDeclarationNoIn - : Identifier InitialiserNoInOpt { $$ = CYNew CYDeclaration($1, $2); } + : BindingIdentifier InitialiserNoInOpt { $$ = CYNew CYDeclaration($1, $2); } + // XXX: | BindingPattern InitialiserNoIn { $$ = CYNew CYDeclaration($1, $2); } + ; + +Initialiser + : "=" AssignmentExpression { $$ = $2; } ; InitialiserOpt @@ -1330,17 +1369,24 @@ InitialiserOpt | { $$ = NULL; } ; +InitialiserNoIn + : "=" AssignmentExpressionNoIn { $$ = $2; } + ; + InitialiserNoInOpt : InitialiserNoIn { $$ = $1; } | { $$ = NULL; } ; +/* }}} */ +/* 12.2.4 Destructuring Binding Patterns {{{ */ +// XXX: * -Initialiser - : "=" AssignmentExpression { $$ = $2; } +BindingElement + : SingleNameBinding { $$ = $1; } ; -InitialiserNoIn - : "=" AssignmentExpressionNoIn { $$ = $2; } +SingleNameBinding + : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } ; /* }}} */ /* 12.3 Empty Statement {{{ */ @@ -1389,7 +1435,7 @@ ForStatement ForStatementInitialiser : ExpressionNoInOpt { $$ = $1; } - | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = $3; } + | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = CYNew CYForDeclarations($3); } ; /* }}} */ /* 12.6.4 The for-in Statement {{{ */ @@ -1433,16 +1479,16 @@ CaseBlock : Brace CaseClausesOpt "}" { $$ = $2; } ; +CaseClause + : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); } + ; + CaseClausesOpt : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; } | { $$ = NULL; } ; -CaseClause - : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); } - ; - DefaultClause : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); } ; @@ -1472,14 +1518,19 @@ FinallyOpt | { $$ = NULL; } ; /* }}} */ +/* 12.14 The debugger Statement {{{ */ +DebuggerStatement + : "debugger" Terminator { $$ = CYNew CYDebugger(); } + ; +/* }}} */ /* 13 Function Definition {{{ */ FunctionDeclaration - : "function" Identifier "(" FormalParameterList ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } + : "function" Identifier "(" FormalParameterListOpt ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } ; FunctionExpression - : "function" IdentifierOpt "(" FormalParameterList ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionExpression($2, $4, $7); } + : "function" IdentifierOpt "(" FormalParameterListOpt ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionExpression($2, $4, $7); } ; FormalParameterList_ @@ -1488,31 +1539,39 @@ FormalParameterList_ ; FormalParameterList - : Identifier FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } + // XXX: : FunctionRestParameter { $$ = $1; } + : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } + ; + +FormalParameterListOpt + : FormalParameterList | { $$ = NULL; } ; +/* XXX: FunctionRestParameter + : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); } + ;*/ + +FormalParameter + : BindingElement { $$ = $1; } + ; + FunctionBody - : SourceElements { $$ = $1; } + : StatementListOpt { $$ = $1; } ; /* }}} */ /* 14 Program {{{ */ Program - : SourceElements { driver.program_ = CYNew CYProgram($1); } - ; - -SourceElements - : SourceElement SourceElements { $1->SetNext($2); $$ = $1; } - | LexSetRegExp { $$ = NULL; } + : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); } ; -SourceElement_ - : Statement_ { $$ = $1; } - | FunctionDeclaration { $$ = $1; } +ProgramBody + : StatementList { $$ = $1; } ; -SourceElement - : LexSetRegExp SourceElement_ { $$ = $2; } +ProgramBodyOpt + : ProgramBody { $$ = $1; } + | { $$ = NULL; } ; /* }}} */ @@ -1528,15 +1587,15 @@ ClassField : Expression Identifier ";" ; +ClassFieldList + : Brace ClassFieldListOpt "}" { $$ = NULL; } + ; + ClassFieldListOpt : ClassFieldListOpt ClassField | ; -ClassFieldList - : Brace ClassFieldListOpt "}" { $$ = NULL; } - ; - MessageScope : "+" { $$ = false; } | "-" { $$ = true; } @@ -1552,15 +1611,15 @@ MessageParameter : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); } ; +MessageParameterList + : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; } + ; + MessageParameterListOpt : MessageParameterList { $$ = $1; } | { $$ = NULL; } ; -MessageParameterList - : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; } - ; - MessageParameters : MessageParameterList { $$ = $1; } | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); } @@ -1610,7 +1669,7 @@ ClassStatement ; CategoryName - : "(" Word ")" + : "(" WordOpt ")" ; CategoryStatement @@ -1632,16 +1691,16 @@ VariadicCall | { $$ = NULL; } ; -SelectorCall_ - : SelectorCall { $$ = $1; } - | VariadicCall { $$ = $1; } - ; - SelectorWordOpt : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; } | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; } ; +SelectorCall_ + : SelectorCall { $$ = $1; } + | VariadicCall { $$ = $1; } + ; + SelectorCall : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); } ; @@ -1656,11 +1715,6 @@ MessageExpression | "[" LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" { $$ = CYNew CYSendSuper($5); } ; -SelectorExpressionOpt - : SelectorExpression_ { $$ = $1; } - | { $$ = NULL; } - ; - SelectorExpression_ : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); } ; @@ -1670,6 +1724,11 @@ SelectorExpression | Word { $$ = CYNew CYSelectorPart($1, false, NULL); } ; +SelectorExpressionOpt + : SelectorExpression_ { $$ = $1; } + | { $$ = NULL; } + ; + PrimaryExpressionNo : MessageExpression { $$ = $1; } | "@selector" "(" SelectorExpression ")" { $$ = CYNew CYSelector($3); } @@ -1688,7 +1747,7 @@ ImportPath | StringLiteral ; -SourceElement_ +StatementListItem : "@import" ImportPath { $$ = CYNew CYImport(); } ; /* }}} */ @@ -1905,16 +1964,16 @@ ForComprehension | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForEachInComprehension($4, $6); } ; +ComprehensionList + : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } + ; + ComprehensionListOpt : ComprehensionList { $$ = $1; } | IfComprehension { $$ = $1; } | { $$ = NULL; } ; -ComprehensionList - : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } - ; - PrimaryExpressionNo : "[" AssignmentExpression ComprehensionList "]" { $$ = CYNew CYArrayComprehension($2, $3); } ; @@ -1924,26 +1983,25 @@ ForInStatement : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = CYNew CYForEachIn($4, $6, $8); } ; /* }}} */ -/* JavaScript 1.7: let Statements {{{ *//* +/* JavaScript 1.7: let Expressions {{{ */ +/*LetExpression + : "let" "(" VariableDeclarationList ")" Expression { $$ = CYNew CYLetExpression($3, $5); } + ; + +MemberExpression + : LexSetRegExp LetExpression { $$ = $2; } + ;*/ +/* }}} */ +/* JavaScript 1.7: let Statements {{{ */ LetStatement - : "let" "(" VariableDeclarationList ")" Block_ { $$ = CYNew CYLet($3, $5); } + : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } ; Statement_ : LetStatement ; -*//* }}} */ - -/* JavaScript FTW: Function Statements {{{ */ -Statement - : LexSetRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; } - ; -/* }}} */ -/* JavaScript FTW: Optional Arguments {{{ */ -FormalParameterList - : Identifier "=" AssignmentExpression FormalParameterList_ { $$ = CYNew CYOptionalFunctionParameter($1, $3, $4); } - ; /* }}} */ + /* JavaScript FTW: Ruby Blocks {{{ */ RubyProcParameterList_ : "," RubyProcParameterList { $$ = $2; } @@ -1951,12 +2009,17 @@ RubyProcParameterList_ ; RubyProcParameterList - : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); } + : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); } | { $$ = NULL; } ; -RubyProcParametersOpt +RubyProcParameters : "|" RubyProcParameterList "|" { $$ = $2; } + | "||" { $$ = NULL; } + ; + +RubyProcParametersOpt + : RubyProcParameters | { $$ = NULL; } ; @@ -1964,6 +2027,14 @@ RubyProcExpression : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } ; +RubyProcExpressionNoOA + : "{" RubyProcParameters StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } + ; + +PrimaryExpressionNo + : RubyProcExpressionNoOA { $$ = $1; } + ; + LeftHandSideExpression : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } ;