]> git.saurik.com Git - cycript.git/commitdiff
Support parenthesized "fat arrow" parameter lists.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 18 Nov 2015 23:06:59 +0000 (15:06 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 18 Nov 2015 23:06:59 +0000 (15:06 -0800)
Cycript.yy.in
Parser.hpp
Replace.cpp

index efa6aa3e70216187d4fc543f4274dbe91c032e9a..0c5d04461a5f075e10b6f48454d52fefd8a27247 100644 (file)
@@ -435,7 +435,6 @@ int cylex(YYSTYPE *, CYLocation *, void *);
 %type <null_> NullLiteral
 %type <literal_> ObjectLiteral
 %type <compound_> Parenthetical
 %type <null_> NullLiteral
 %type <literal_> ObjectLiteral
 %type <compound_> Parenthetical
-//%type <compound_> ParentheticalOpt
 %type <expression_> PostfixExpression
 %type <expression_> PrimaryExpression
 %type <statement_> Program
 %type <expression_> PostfixExpression
 %type <expression_> PrimaryExpression
 %type <statement_> Program
@@ -770,11 +769,6 @@ Parenthetical
     : "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; }
     ;
 
     : "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; }
     ;
 
-/*ParentheticalOpt
-    : Parenthetical { $$ = $1; }
-    | { $$ = NULL; }
-    ;*/
-
 Variable
     : Identifier { $$ = CYNew CYVariable($1); }
     ;
 Variable
     : Identifier { $$ = CYNew CYVariable($1); }
     ;
@@ -1380,7 +1374,8 @@ ArrowFunction
 
 ArrowParameters
     : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
 
 ArrowParameters
     : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
-    //| ParentheticalOpt { $$ = $1; }
+    | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
+    | Parenthetical { $$ = $1->Parameters(); if ($$ == NULL) error(@1, "invalid parameter list"); }
     ;
 
 ConciseBody
     ;
 
 ConciseBody
index 01a510fdd9a89e8f556e62d978a4f9e59550547e..de8d5a5c0156f43dd5b7556ddea9e4aa4557ce08 100644 (file)
@@ -482,6 +482,8 @@ struct CYForInInitialiser {
     virtual void Output(CYOutput &out, CYFlags flags) const = 0;
 };
 
     virtual void Output(CYOutput &out, CYFlags flags) const = 0;
 };
 
+struct CYFunctionParameter;
+
 struct CYNumber;
 struct CYString;
 
 struct CYNumber;
 struct CYString;
 
@@ -516,6 +518,9 @@ struct CYExpression :
         return NULL;
     }
 
         return NULL;
     }
 
+    virtual CYFunctionParameter *Parameter() const;
+    virtual CYFunctionParameter *Parameters() const;
+
     virtual CYNumber *Number(CYContext &context) {
         return NULL;
     }
     virtual CYNumber *Number(CYContext &context) {
         return NULL;
     }
@@ -566,6 +571,7 @@ struct CYCompound :
     void Output(CYOutput &out, CYFlags flags) const;
 
     virtual CYExpression *Primitive(CYContext &context);
     void Output(CYOutput &out, CYFlags flags) const;
 
     virtual CYExpression *Primitive(CYContext &context);
+    virtual CYFunctionParameter *Parameters() const;
 };
 
 struct CYDeclaration;
 };
 
 struct CYDeclaration;
@@ -911,6 +917,8 @@ struct CYVariable :
 
     virtual CYExpression *Replace(CYContext &context);
     virtual void Output(CYOutput &out, CYFlags flags) const;
 
     virtual CYExpression *Replace(CYContext &context);
     virtual void Output(CYOutput &out, CYFlags flags) const;
+
+    virtual CYFunctionParameter *Parameter() const;
 };
 
 struct CYPrefix :
 };
 
 struct CYPrefix :
index 34c5cabf8c1af227a05f80759bd84c02946d8946..bcaffca8cd39ad9e3376c3ff0c43a3907ea55e7c 100644 (file)
@@ -169,6 +169,24 @@ CYExpression *CYCompound::Primitive(CYContext &context) {
     return expression->Primitive(context);
 }
 
     return expression->Primitive(context);
 }
 
+CYFunctionParameter *CYCompound::Parameters() const {
+    CYFunctionParameter *next;
+    if (next_ == NULL)
+        next = NULL;
+    else {
+        next = next_->Parameters();
+        if (next == NULL)
+            return NULL;
+    }
+
+    CYFunctionParameter *parameter(expression_->Parameter());
+    if (parameter == NULL)
+        return NULL;
+
+    parameter->SetNext(next);
+    return parameter;
+}
+
 CYFunctionParameter *CYComprehension::Parameters(CYContext &context) const { $T(NULL)
     CYFunctionParameter *next(next_->Parameters(context));
     if (CYFunctionParameter *parameter = Parameter(context)) {
 CYFunctionParameter *CYComprehension::Parameters(CYContext &context) const { $T(NULL)
     CYFunctionParameter *next(next_->Parameters(context));
     if (CYFunctionParameter *parameter = Parameter(context)) {
@@ -327,6 +345,14 @@ CYAssignment *CYExpression::Assignment(CYContext &context) {
     return NULL;
 }
 
     return NULL;
 }
 
+CYFunctionParameter *CYExpression::Parameter() const {
+    return NULL;
+}
+
+CYFunctionParameter *CYExpression::Parameters() const {
+    return NULL;
+}
+
 CYStatement *CYExternal::Replace(CYContext &context) {
     return $E($ CYAssign($V(typed_->identifier_), $C1(typed_->Replace(context), $C2($V("dlsym"), $V("RTLD_DEFAULT"), $S(typed_->identifier_->Word())))));
 }
 CYStatement *CYExternal::Replace(CYContext &context) {
     return $E($ CYAssign($V(typed_->identifier_), $C1(typed_->Replace(context), $C2($V("dlsym"), $V("RTLD_DEFAULT"), $S(typed_->identifier_->Word())))));
 }
@@ -996,6 +1022,10 @@ CYExpression *CYVariable::Replace(CYContext &context) {
     return this;
 }
 
     return this;
 }
 
+CYFunctionParameter *CYVariable::Parameter() const {
+    return $ CYFunctionParameter($ CYDeclaration(name_));
+}
+
 CYStatement *CYWhile::Replace(CYContext &context) {
     context.Replace(test_);
     context.Replace(code_);
 CYStatement *CYWhile::Replace(CYContext &context) {
     context.Replace(test_);
     context.Replace(code_);