From: Jay Freeman (saurik) Date: Fri, 8 Jun 2012 20:40:47 +0000 (-0700) Subject: Implement (modified) ECMA6 array comprehensions. X-Git-Tag: v0.9.458~15 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/c252950279eadefe8cd5ceb41f0eaa0d20153a56 Implement (modified) ECMA6 array comprehensions. --- diff --git a/Cycript.yy.in b/Cycript.yy.in index 6eb6e10..e735597 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -333,6 +333,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ArrowFunction %type ArrowParameters %type AssignmentExpression +%type Binding %type BindingIdentifier %type BitwiseANDExpression %type Block_ @@ -349,6 +350,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type CaseClause %type CaseClausesOpt %type CatchOpt +%type ComprehensionForList +%type ComprehensionForListOpt %type ComprehensionList %type ComprehensionListOpt %type ConditionalExpression @@ -739,6 +742,22 @@ ElementListOpt | LexSetRegExp { $$ = NULL; } ; /* }}} */ +/* 11.1.4.2 Array Comprehension {{{ */ +PrimaryExpression + : "[" LexPushInOff AssignmentExpression ComprehensionForList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); } + ; + +ComprehensionForList + : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); } + | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); } + ; + +ComprehensionForListOpt + : ComprehensionForList { $$ = $1; } + | "if" Expression { $$ = CYNew CYIfComprehension($2); } + | { $$ = NULL; } + ; +/* }}} */ /* 11.1.5 Object Initialiser {{{ */ ObjectLiteral : BRACE LexPushInOff PropertyDefinitionListOpt LexPopIn "}" { $$ = CYNew CYObject($3); } @@ -1043,6 +1062,10 @@ BindingIdentifier : Identifier { $$ = $1; } ; +Binding + : BindingIdentifier + ; + // XXX: BindingPattern /* }}} */ /* 12.2.1 Let and Const Declarations {{{ */ diff --git a/Parser.hpp b/Parser.hpp index 7197428..c53d132 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -653,6 +653,11 @@ struct CYComprehension : CYNext, CYThing { + CYComprehension(CYComprehension *next = NULL) : + CYNext(next) + { + } + virtual const char *Name() const = 0; virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; @@ -667,7 +672,8 @@ struct CYForInComprehension : CYIdentifier *name_; CYExpression *set_; - CYForInComprehension(CYIdentifier *name, CYExpression *set) : + CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) : + CYComprehension(next), name_(name), set_(set) { @@ -688,7 +694,8 @@ struct CYForOfComprehension : CYIdentifier *name_; CYExpression *set_; - CYForOfComprehension(CYIdentifier *name, CYExpression *set) : + CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) : + CYComprehension(next), name_(name), set_(set) {