]> git.saurik.com Git - cycript.git/blobdiff - Parser.ypp.in
Include type in toCYON for opaque Pointer address.
[cycript.git] / Parser.ypp.in
index 687218ae7144db28665d5d0d783cc5b7e9b77321..7e0dc2fbc9cb6baf4832d34db5df6836f600ad24 100644 (file)
@@ -80,6 +80,7 @@
 %union { CYWord *word_; }
 
 @begin C
+%union { CYTypeStructField *structField_; }
 %union { CYTypeModifier *modifier_; }
 %union { CYTypeSpecifier *specifier_; }
 %union { CYTypedIdentifier *typedIdentifier_; }
@@ -87,9 +88,9 @@
 @end
 
 @begin ObjectiveC
+%union { CYImplementationField *implementationField_; }
 %union { CYMessage *message_; }
 %union { CYMessageParameter *messageParameter_; }
-%union { CYImplementationField *implementationField_; }
 %union { CYProtocol *protocol_; }
 %union { CYSelectorPart *selector_; }
 @end
@@ -330,6 +331,7 @@ type; })
 %token _typedef_ "typedef"
 %token _unsigned_ "unsigned"
 %token _signed_ "signed"
+%token _struct_ "struct"
 %token _extern_ "extern"
 @end
 
@@ -417,6 +419,7 @@ type; })
 %token _package_ "package"
 %token _private_ "private"
 %token _protected_ "protected"
+%token ___proto___ "__proto__"
 %token _prototype_ "prototype"
 %token _public_ "public"
 %token _set_ "set"
@@ -543,6 +546,7 @@ type; })
 %type <identifier_> IdentifierNoOf
 %type <identifier_> IdentifierType
 %type <identifier_> IdentifierTypeNoOf
+%type <identifier_> IdentifierTypeOpt
 %type <word_> IdentifierName
 %type <variable_> IdentifierReference
 %type <statement_> IfStatement
@@ -583,6 +587,8 @@ type; })
 %type <bool_> RegularExpressionSlash
 %type <expression_> RelationalExpression
 %type <statement_> ReturnStatement
+%type <target_> RubyBlockExpression_
+%type <target_> RubyBlockExpression
 %type <rubyProc_> RubyProcExpression
 %type <functionParameter_> RubyProcParameterList_
 %type <functionParameter_> RubyProcParameterList
@@ -626,6 +632,7 @@ type; })
 %type <specifier_> IntegerTypeOpt
 %type <typedIdentifier_> PrefixedType
 %type <specifier_> PrimitiveType
+%type <structField_> StructFieldListOpt
 %type <typedIdentifier_> SuffixedType
 %type <typedIdentifier_> TypeSignifier
 %type <modifier_> TypeQualifierLeft
@@ -644,13 +651,12 @@ type; })
 %type <statement_> CategoryStatement
 %type <expression_> ClassSuperOpt
 %type <expression_> ConditionalExpressionClassic
-%type <implementationField_> ImplementationFieldListOpt
-%type <implementationField_> ImplementationFields
 %type <message_> ClassMessageDeclaration
 %type <message_> ClassMessageDeclarationListOpt
 %type <protocol_> ClassProtocolListOpt
 %type <protocol_> ClassProtocols
 %type <protocol_> ClassProtocolsOpt
+%type <implementationField_> ImplementationFieldListOpt
 %type <statement_> ImplementationStatement
 %type <target_> MessageExpression
 %type <messageParameter_> MessageParameter
@@ -713,10 +719,12 @@ LexPopIn: { driver.in_.pop(); };
 
 LexPushReturnOn: { driver.return_.push(true); };
 LexPopReturn: { driver.return_.pop(); };
+Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
 
 LexPushSuperOn: { driver.super_.push(true); };
 LexPushSuperOff: { driver.super_.push(false); };
 LexPopSuper: { driver.super_.pop(); };
+Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
 
 LexPushYieldOn: { driver.yield_.push(true); };
 LexPushYieldOff: { driver.yield_.push(false); };
@@ -910,6 +918,7 @@ IdentifierTypeNoOf
     | "package" { $$ = CYNew CYIdentifier("package"); }
     | "private" { $$ = CYNew CYIdentifier("private"); }
     | "protected" { $$ = CYNew CYIdentifier("protected"); }
+    | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
     | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
     | "public" { $$ = CYNew CYIdentifier("public"); }
     | "set" { $$ = CYNew CYIdentifier("set"); }
@@ -931,6 +940,11 @@ IdentifierType
     | "of" { $$ = CYNew CYIdentifier("of"); }
     ;
 
+IdentifierTypeOpt
+    : IdentifierType[pass] { $$ = $pass; }
+    | { $$ = NULL; }
+    ;
+
 IdentifierNoOf
     : IdentifierTypeNoOf
     | "char" { $$ = CYNew CYIdentifier("char"); }
@@ -941,6 +955,7 @@ IdentifierNoOf
     | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
 @begin C
     | "signed" { $$ = CYNew CYIdentifier("signed"); }
+    | "struct" { $$ = CYNew CYIdentifier("struct"); }
     | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
 @end
 @begin ObjectiveC
@@ -1087,8 +1102,8 @@ MemberExpression
     ;
 
 SuperProperty
-    : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
-    | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
+    : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
+    | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
     ;
 
 MetaProperty
@@ -1116,7 +1131,7 @@ CallExpression
     ;
 
 SuperCall
-    : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
+    : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
     ;
 
 Arguments
@@ -1144,13 +1159,13 @@ AccessExpression
     ;
 
 LeftHandSideExpression
-    : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+    : RubyBlockExpression[pass] { $$ = $pass; }
     | IndirectExpression[pass] { $$ = $pass; }
     ;
 /* }}} */
 /* 12.4 Postfix Expressions {{{ */
 PostfixExpression
-    : AccessExpression[lhs] LexNewLineOrOpt { $$ = $lhs; }
+    : RubyBlockExpression[pass] { $$ = $pass; }
     | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
     | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
     ;
@@ -1170,7 +1185,6 @@ UnaryExpression_
 
 UnaryExpression
     : PostfixExpression[expression] { $$ = $expression; }
-    | PostfixExpression[expression] "\n" { $$ = $expression; }
     | UnaryExpression_[pass] { $$ = $pass; }
     ;
 /* }}} */
@@ -1539,7 +1553,7 @@ ForStatementInitializer
     ;
 
 ForInStatementInitializer
-    : LexLet LexOf AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+    : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
     | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
     | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
     | ForDeclaration[pass] { $$ = $pass; }
@@ -1567,10 +1581,6 @@ BreakStatement
     ;
 /* }}} */
 /* 13.10 The return Statement {{{ */
-Return
-    : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
-    ;
-
 ReturnStatement
     : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
     | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
@@ -1975,6 +1985,11 @@ IntegerTypeOpt
     | { $$ = CYNew CYTypeVariable("int"); }
     ;
 
+StructFieldListOpt
+    : TypedIdentifierMaybe[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
+    | { $$ = NULL; }
+    ;
+
 PrimitiveType
     : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
     | IntegerType[pass] { $$ = $pass; }
@@ -1982,6 +1997,7 @@ PrimitiveType
     | "char" { $$ = CYNew CYTypeVariable("char"); }
     | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
     | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
+    | "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYTypeStruct($name, $fields); }
     ;
 
 TypedIdentifierMaybe
@@ -2015,10 +2031,6 @@ ImplementationFieldListOpt
     | { $$ = NULL; }
     ;
 
-ImplementationFields
-    : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
-    ;
-
 MessageScope
     : "+" { $$ = false; }
     | "-" { $$ = true; }
@@ -2072,7 +2084,7 @@ ClassProtocolListOpt
     ;
 
 ImplementationStatement
-    : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
+    : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
     ;
 
 CategoryName
@@ -2505,8 +2517,14 @@ PrimaryExpression
     : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
     ;
 
-PostfixExpression
-    : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
+RubyBlockExpression_
+    : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
+    | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
+    ;
+
+RubyBlockExpression
+    : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
+    | RubyBlockExpression_[pass] { $$ = $pass; }
     ;
 /* }}} */