]> git.saurik.com Git - cycript.git/blobdiff - Parser.ypp.in
Implement output of Objective-C class field lists.
[cycript.git] / Parser.ypp.in
index 50cacb3ed1add2d47a19283e0437adde8ce8a839..f73ccd168b9758b9d83a630351a260d02799c764 100644 (file)
@@ -87,9 +87,9 @@
 @end
 
 @begin ObjectiveC
+%union { CYImplementationField *implementationField_; }
 %union { CYMessage *message_; }
 %union { CYMessageParameter *messageParameter_; }
-%union { CYImplementationField *implementationField_; }
 %union { CYProtocol *protocol_; }
 %union { CYSelectorPart *selector_; }
 @end
@@ -630,7 +630,9 @@ type; })
 %type <typedIdentifier_> TypeSignifier
 %type <modifier_> TypeQualifierLeft
 %type <typedIdentifier_> TypeQualifierRight
-%type <typedIdentifier_> TypedIdentifier
+%type <typedIdentifier_> TypedIdentifierMaybe
+%type <typedIdentifier_> TypedIdentifierNo
+%type <typedIdentifier_> TypedIdentifierYes
 %type <typedParameter_> TypedParameterList_
 %type <typedParameter_> TypedParameterList
 %type <typedParameter_> TypedParameterListOpt
@@ -642,13 +644,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
@@ -1982,12 +1983,20 @@ PrimitiveType
     | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
     ;
 
-TypedIdentifier
+TypedIdentifierMaybe
     : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
     ;
 
+TypedIdentifierYes
+    : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
+    ;
+
+TypedIdentifierNo
+    : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
+    ;
+
 PrimaryExpression
-    : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
+    : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
     ;
 /* }}} */
 @end
@@ -2001,21 +2010,17 @@ ClassSuperOpt
     ;
 
 ImplementationFieldListOpt
-    : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
+    : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
     | { $$ = NULL; }
     ;
 
-ImplementationFields
-    : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
-    ;
-
 MessageScope
     : "+" { $$ = false; }
     | "-" { $$ = true; }
     ;
 
 TypeOpt
-    : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
+    : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
     | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
     ;
 
@@ -2062,7 +2067,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
@@ -2165,7 +2170,7 @@ PrimaryExpression
 /* }}} */
 /* Cycript (Objective-C): Block Expressions {{{ */
 PrimaryExpression
-    : "^" TypedIdentifier[type] { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); } "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
+    : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
     ;
 /* }}} */
 /* Cycript (Objective-C): Instance Literals {{{ */
@@ -2202,7 +2207,7 @@ TypedParameterList_
     ;
 
 TypedParameterList
-    : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
+    : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
     ;
 
 TypedParameterListOpt
@@ -2211,7 +2216,7 @@ TypedParameterListOpt
     ;
 
 PrimaryExpression
-    : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
+    : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
     ;
 /* }}} */
 /* Cycript (C): Type Definitions {{{ */
@@ -2220,7 +2225,11 @@ IdentifierNoOf
     ;
 
 Statement__
-    : "typedef" NewLineNot TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
+    : "typedef" NewLineNot TypedIdentifierYes[typed] Terminator { $$ = CYNew CYTypeDefinition($typed); }
+    ;
+
+PrimaryExpression
+    : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
     ;
 /* }}} */
 /* Cycript (C): extern "C" {{{ */
@@ -2229,7 +2238,7 @@ IdentifierNoOf
     ;
 
 Statement__
-    : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($abi, $typed); }
+    : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifierYes[typed] Terminator { $$ = CYNew CYExternal($abi, $typed); }
     ;
 /* }}} */