]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Implemented initial support for Ruby Blocks.
[cycript.git] / Cycript.yy.in
index ecfbba104edee8c89bef2d29be9b3c8a3fff5d7f..53a6336467debbc178d5c580e589ca95439a7c14 100644 (file)
@@ -90,6 +90,7 @@ typedef struct {
         CYProgram *program_;
         CYProperty *property_;
         CYPropertyName *propertyName_;
+        CYRubyProc *rubyProc_;
         CYStatement *statement_;
         CYString *string_;
         CYThis *this_;
@@ -223,6 +224,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token CloseParen ")"
 
 %token OpenBrace "{"
+%token OpenBrace_ "\n{"
 %token CloseBrace "}"
 
 %token OpenBracket "["
@@ -444,6 +446,10 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %type <expression_> RelationalExpressionNoIn
 %type <infix_> RelationalExpressionNoIn_
 %type <statement_> ReturnStatement
+%type <rubyProc_> RubyProcExpression
+%type <functionParameter_> RubyProcParameterList
+%type <functionParameter_> RubyProcParameterList_
+%type <functionParameter_> RubyProcParametersOpt
 %type <expression_> ShiftExpression
 %type <expression_> ShiftExpressionNoBF
 %type <statement_> SourceElement
@@ -564,6 +570,11 @@ LexSetRegExp
     ;
 /* }}} */
 
+Brace
+    : "{"
+    | "\n{"
+    ;
+
 StrictSemi
     : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
     ;
@@ -758,7 +769,7 @@ ElementList
 /* }}} */
 /* 11.1.5 Object Initialiser {{{ */
 ObjectLiteral
-    : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
+    : OpenBrace PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
     ;
 
 PropertyNameAndValueList_
@@ -1259,7 +1270,7 @@ Statement
 /* }}} */
 /* 12.1 Block {{{ */
 Block_
-    : "{" StatementListOpt "}" { $$ = $2; }
+    : Brace StatementListOpt "}" { $$ = $2; }
     ;
 
 Block
@@ -1411,7 +1422,7 @@ SwitchStatement
     ;
 
 CaseBlock
-    : "{" CaseClausesOpt "}" { $$ = $2; }
+    : Brace CaseClausesOpt "}" { $$ = $2; }
     ;
 
 CaseClausesOpt
@@ -1456,11 +1467,11 @@ FinallyOpt
 
 /* 13 Function Definition {{{ */
 FunctionDeclaration
-    : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
+    : "function" Identifier "(" FormalParameterList ")" Brace FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
     ;
 
 FunctionExpression
-    : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
+    : "function" IdentifierOpt "(" FormalParameterList ")" Brace FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
     ;
 
 FormalParameterList_
@@ -1506,7 +1517,7 @@ ClassSuperOpt
     ;
 
 ClassFieldList
-    : "{" "}" { $$ = NULL; }
+    : Brace "}" { $$ = NULL; }
     ;
 
 MessageScope
@@ -1538,7 +1549,7 @@ MessageParameters
     ;
 
 ClassMessageDeclaration
-    : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
+    : MessageScope TypeOpt MessageParameters Brace FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
     ;
 
 ClassMessageDeclarationListOpt
@@ -1771,7 +1782,7 @@ XMLTagContent
     ;
 
 XMLExpression
-    : "{" LexPushRegExp Expression "}" LexPop
+    : Brace LexPushRegExp Expression "}" LexPop
     ;
 
 XMLTagName
@@ -1843,6 +1854,7 @@ PropertyNameAndValueList_
     : "," { $$ = NULL; }
     ;
 /* }}} */
+
 /* JavaScript 1.7: Array Comprehensions {{{ */
 IfComprehension
     : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
@@ -1881,10 +1893,50 @@ 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_ { $$ = new(driver.pool_) CYOptionalFunctionParameter($1, $3, $4); }
+    ;
+/* }}} */
+/* JavaScript FTW: Ruby Blocks {{{ */
+RubyProcParameterList_
+    : "," RubyProcParameterList { $$ = $2; }
+    | { $$ = NULL; }
+    ;
+
+RubyProcParameterList
+    : Identifier RubyProcParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
+    | { $$ = NULL; }
+    ;
+
+RubyProcParametersOpt
+    : "|" RubyProcParameterList "|" { $$ = $2; }
+    | { $$ = NULL; }
+    ;
+
+RubyProcExpression
+    : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = new(driver.pool_) CYRubyProc($2, $3); }
+    ;
+
+LeftHandSideExpression
+    : LeftHandSideExpression RubyProcExpression { $$ = new(driver.pool_) CYRubyBlock($1, $2); }
+    ;
+
+LeftHandSideExpressionNoBF
+    : LeftHandSideExpressionNoBF RubyProcExpression { $$ = new(driver.pool_) CYRubyBlock($1, $2); }
+    ;
+
+@begin C
+LeftHandSideExpressionNoRE
+    : LeftHandSideExpressionNoRE RubyProcExpression { $$ = new(driver.pool_) CYRubyBlock($1, $2); }
+    ;
+@end
+/* }}} */
 
 %%