}
void CYForOfComprehension::Output(CYOutput &out) const {
- out << "for" << ' ' << "each" << ' ' << '(' << *name_ << ' ' << "in" << ' ' << *set_ << ')' << next_;
+ out << "for" << ' ' << "each" << ' ' << '(';
+ declaration_->Output(out, CYNoIn);
+ out << ' ' << "in" << ' ' << *set_ << ')' << next_;
}
void CYForIn::Output(CYOutput &out, CYFlags flags) const {
}
void CYForInComprehension::Output(CYOutput &out) const {
- out << "for" << ' ' << '(' << *name_ << ' ' << "in" << ' ' << *set_ << ')';
+ out << "for" << ' ' << '(';
+ declaration_->Output(out, CYNoIn);
+ out << ' ' << "in" << ' ' << *set_ << ')';
}
void CYFunction::Output(CYOutput &out, CYFlags flags) const {
%type <functionParameter_> ArrowParameters
%type <expression_> AssignmentExpression
%type <expression_> AssignmentExpressionOpt
-%type <identifier_> Binding
%type <identifier_> BindingIdentifier
%type <identifier_> BindingIdentifierOpt
+%type <declarations_> BindingList_
+%type <declarations_> BindingList
%type <expression_> BitwiseANDExpression
%type <statement_> Block
%type <statement_> BlockStatement
%type <expression_> ExpressionOpt
%type <statement_> ExpressionStatement
%type <finally_> Finally
-%type <for_> ForStatementInitializer
+%type <declaration_> ForBinding
+%type <declaration_> ForDeclaration
%type <forin_> ForInStatementInitializer
+%type <for_> ForStatementInitializer
%type <declaration_> FormalParameter
%type <functionParameter_> FormalParameterList_
%type <functionParameter_> FormalParameterList
%type <statement_> LabelledStatement
%type <expression_> LeftHandSideExpression
%type <statement_> LetStatement
+%type <declaration_> LexicalBinding
%type <statement_> LexicalDeclaration
%type <literal_> Literal
%type <propertyName_> LiteralPropertyName
| Declaration { $$ = $1; }
;
/* }}} */
-/* 13.3+ Let and Const Declarations {{{ */
+/* 13.3 Let and Const Declarations {{{ */
LexicalDeclaration
- : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
+ : LetOrConst BindingList Terminator { $$ = CYNew CYVar($2); }
;
LetOrConst
| "const"
;
-Binding
- : BindingIdentifier
+BindingList_
+ : "," BindingList { $$ = $2; }
+ | { $$ = NULL; }
+ ;
+
+BindingList
+ : LexicalBinding BindingList_ { $$ = CYNew CYDeclarations($1, $2); }
;
-// XXX: lots of binding stuff
+LexicalBinding
+ : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
+ | BindingPattern Initializer { CYNOT(@1); }
+ ;
/* }}} */
-/* 13.3.2+ Variable Statement {{{ */
+/* 13.3.2 Variable Statement {{{ */
VariableStatement
: Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
;
VariableDeclaration
: BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
- // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
+ | BindingPattern Initializer { CYNOT(@1); }
;
/* }}} */
/* 13.3.3 Destructuring Binding Patterns {{{ */
: "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
;
/* }}} */
-/* 13.7+ Iteration Statements {{{ */
+/* 13.7 Iteration Statements {{{ */
IterationStatement
: "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
| "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
ForStatementInitializer
: ExpressionOpt { $$ = $1; }
| LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
+ | LexSetRegExp LexicalDeclaration { CYNOT(@$); }
;
ForInStatementInitializer
: LeftHandSideExpression { $$ = $1; }
- | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
+ | LexSetRegExp Var_ ForBinding { $$ = $3; }
+ | LexSetRegExp ForDeclaration { $$ = $2; }
+ ;
+
+ForDeclaration
+ : LetOrConst ForBinding { $$ = $2; }
+ ;
+
+ForBinding
+ : BindingIdentifier { $$ = CYNew CYDeclaration($1, NULL); }
+ | BindingPattern { CYNOT(@1); }
;
/* }}} */
/* 13.8 The continue Statement {{{ */
;
ComprehensionFor
- : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
- | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
+ : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
;
/* }}} */
/* JavaScript FTL: for each {{{ */
;
ComprehensionFor
- : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
+ : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
+ | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); }
;
ComprehensionIf
}
CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const {
- return $ CYFunctionParameter($ CYDeclaration(name_));
+ return $ CYFunctionParameter(declaration_);
}
CYStatement *CYForInComprehension::Replace(CYContext &context, CYStatement *statement) const {
- return $ CYForIn($V(name_), set_, CYComprehension::Replace(context, statement));
+ return $ CYForIn(declaration_->Variable(context), set_, CYComprehension::Replace(context, statement));
}
CYStatement *CYForOf::Replace(CYContext &context) {
}
CYFunctionParameter *CYForOfComprehension::Parameter(CYContext &context) const {
- return $ CYFunctionParameter($ CYDeclaration(name_));
+ return $ CYFunctionParameter(declaration_);
}
CYStatement *CYForOfComprehension::Replace(CYContext &context, CYStatement *statement) const {
return $E($C0($F(NULL, $P1($L("$cys")), $$->*
$E($ CYAssign($V(cys), set_))->*
- $ CYForIn($V(name_), $V(cys), $ CYBlock($$->*
- $E($ CYAssign($V(name_), $M($V(cys), $V(name_))))->*
+ $ CYForIn(declaration_->Variable(context), $V(cys), $ CYBlock($$->*
+ $E($ CYAssign(declaration_->Variable(context), $M($V(cys), declaration_->Variable(context))))->*
CYComprehension::Replace(context, statement)
))
)));
return this;
}
- virtual const char *Name() const = 0;
-
virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
CYFunctionParameter *Parameters(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
struct CYForInComprehension :
CYComprehension
{
- CYIdentifier *name_;
+ CYDeclaration *declaration_;
CYExpression *set_;
- CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
+ CYForInComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) :
CYComprehension(next),
- name_(name),
+ declaration_(declaration),
set_(set)
{
}
- virtual const char *Name() const {
- return name_->Word();
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
virtual void Output(CYOutput &out) const;
struct CYForOfComprehension :
CYComprehension
{
- CYIdentifier *name_;
+ CYDeclaration *declaration_;
CYExpression *set_;
- CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
+ CYForOfComprehension(CYDeclaration *declaration, CYExpression *set, CYComprehension *next = NULL) :
CYComprehension(next),
- name_(name),
+ declaration_(declaration),
set_(set)
{
}
- virtual const char *Name() const {
- return name_->Word();
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
virtual void Output(CYOutput &out) const;
{
}
- virtual const char *Name() const {
- return NULL;
- }
-
virtual CYFunctionParameter *Parameter(CYContext &context) const;
virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
virtual void Output(CYOutput &out) const;