]> git.saurik.com Git - cycript.git/blobdiff - Cycript.yy.in
Add syntax to support C-style typedef assignment.
[cycript.git] / Cycript.yy.in
index 7ffc95121edd3b5d05ad4c475bc55c1cb9a4211b..8adbbf5fe96c0431db20311601e0e1f90db9eafc 100644 (file)
@@ -1,20 +1,20 @@
 /* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2012  Jay Freeman (saurik)
+ * Copyright (C) 2009-2013  Jay Freeman (saurik)
 */
 
-/* GNU Lesser General Public License, Version 3 {{{ */
+/* GNU General Public License, Version 3 {{{ */
 /*
- * 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.
+ * Cycript is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
  *
- * 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.
+ * 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 General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public License
+ * You should have received a copy of the GNU General Public License
  * along with Cycript.  If not, see <http://www.gnu.org/licenses/>.
 **/
 /* }}} */
@@ -28,6 +28,7 @@
 @if Bison24 }
 
 @if Bison24 %code requires {
+#include "Driver.hpp"
 #include "Parser.hpp"
 #define CYNew new($pool)
 
@@ -81,9 +82,6 @@ typedef struct {
         CYString *string_;
         CYThis *this_;
         CYTrue *true_;
-        CYTypeModifier *type_;
-        CYTypedIdentifier *typedIdentifier_;
-        CYTypedParameter *typedParameter_;
         CYWord *word_;
 
 @begin ObjectiveC
@@ -93,6 +91,9 @@ typedef struct {
         CYMessageParameter *messageParameter_;
         CYProtocol *protocol_;
         CYSelectorPart *selector_;
+        CYTypeModifier *type_;
+        CYTypedIdentifier *typedIdentifier_;
+        CYTypedParameter *typedParameter_;
 @end
 
 @begin E4X
@@ -223,10 +224,16 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token OpenBracket "["
 %token CloseBracket "]"
 
+%token AtError "@error"
+
 @begin Java
 %token AtClass "@class"
 @end
 
+@begin C
+%token <identifier_> Typedef "typedef"
+@end
+
 @begin ObjectiveC
 %token AtImplementation "@implementation"
 %token AtImplementation_ ";@implementation"
@@ -557,8 +564,10 @@ LexNoFunction
     : { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; }
     ;
 
-LexNoAtImplementation
-    : { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
+LexNoAtImplementation :
+@begin ObjectiveC
+    { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
+@end
     ;
 
 LexSetStatement
@@ -640,6 +649,10 @@ WordOpt
 Identifier
     : Identifier_ { $$ = $1; }
 
+@begin C
+    | "typedef" { $$ = $1; }
+@end
+
     | "implements" { $$ = $1; }
     | "interface" { $$ = $1; }
     | "package" { $$ = $1; }
@@ -1349,7 +1362,7 @@ ProgramBodyOpt
 SuffixedType
     : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
     | "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
-    | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
+    | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3); $$ = $1; }
     ;
 
 PrefixedType
@@ -1572,20 +1585,6 @@ PrimaryExpression
     ;
 /* }}} */
 /* Cycript (Objective-C): Block Expressions {{{ */
-TypedParameterList_
-    : "," TypedParameterList { $$ = $2; }
-    | { $$ = NULL; }
-    ;
-
-TypedParameterList
-    : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
-    ;
-
-TypedParameterListOpt
-    : TypedParameterList { $$ = $1; }
-    | { $$ = NULL; }
-    ;
-
 PrimaryExpression
     : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
     ;
@@ -1613,6 +1612,30 @@ Var_
     : "auto"
     ;
 /* }}} */
+/* Cycript (C): Lambda Expressions {{{ */
+TypedParameterList_
+    : "," TypedParameterList { $$ = $2; }
+    | { $$ = NULL; }
+    ;
+
+TypedParameterList
+    : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+    ;
+
+TypedParameterListOpt
+    : TypedParameterList { $$ = $1; }
+    | { $$ = NULL; }
+    ;
+
+PrimaryExpression
+    : "[" LexPushInOff LexSetRegExp "=" "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" ModifiedType BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($13, $9, $16); }
+    ;
+/* }}} */
+/* Cycript (C): Type Definitions {{{ */
+Statement__
+    : "typedef" TypedIdentifier Terminator { $$ = CYNew CYTypeDefinition($2); }
+    ;
+/* }}} */
 @end
 
 /* YUI: Documentation Comments {{{ */