]> git.saurik.com Git - cycript.git/blobdiff - Parser.ypp.in
Fix Objective-C dictionary/array literal lowering.
[cycript.git] / Parser.ypp.in
index ac4237301acdac380f886f6c829b79e760304e96..acda20a719a51fdbd1d724d57d2d0647d986c3e8 100644 (file)
@@ -81,6 +81,7 @@
 %union { CYWord *word_; }
 
 @begin C
+%union { CYTypeIntegral *integral_; }
 %union { CYTypeStructField *structField_; }
 %union { CYTypeModifier *modifier_; }
 %union { CYTypeSpecifier *specifier_; }
@@ -89,6 +90,7 @@
 @end
 
 @begin ObjectiveC
+%union { CYObjCKeyValue *keyValue_; }
 %union { CYImplementationField *implementationField_; }
 %union { CYMessage *message_; }
 %union { CYMessageParameter *messageParameter_; }
@@ -476,11 +478,11 @@ type; })
 %type <argument_> ArgumentListOpt
 %type <argument_> Arguments
 %type <target_> ArrayComprehension
+%type <element_> ArrayElement
 %type <literal_> ArrayLiteral
 %type <expression_> ArrowFunction
 %type <functionParameter_> ArrowParameters
 %type <expression_> AssignmentExpression
-%type <expression_> AssignmentExpressionOpt
 %type <identifier_> BindingIdentifier
 %type <identifier_> BindingIdentifierOpt
 %type <bindings_> BindingList_
@@ -519,6 +521,7 @@ type; })
 %type <statement_> Declaration_
 %type <statement_> Declaration
 %type <clause_> DefaultClause
+%type <element_> ElementList_
 %type <element_> ElementList
 %type <element_> ElementListOpt
 %type <statement_> ElseStatementOpt
@@ -653,8 +656,8 @@ type; })
 %type <expression_> YieldExpression
 
 @begin C
-%type <specifier_> IntegerType
-%type <specifier_> IntegerTypeOpt
+%type <integral_> IntegerType
+%type <integral_> IntegerTypeOpt
 %type <typedIdentifier_> PrefixedType
 %type <specifier_> PrimitiveType
 %type <structField_> StructFieldListOpt
@@ -692,6 +695,9 @@ type; })
 %type <protocol_> ClassProtocolsOpt
 %type <implementationField_> ImplementationFieldListOpt
 %type <statement_> ImplementationStatement
+%type <keyValue_> KeyValuePairList_
+%type <keyValue_> KeyValuePairList
+%type <keyValue_> KeyValuePairListOpt
 %type <target_> MessageExpression
 %type <messageParameter_> MessageParameter
 %type <messageParameter_> MessageParameters
@@ -1049,10 +1055,19 @@ ArrayLiteral
     : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
     ;
 
-ElementList
-    : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
+ArrayElement
+    : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
     | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
-    | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
+    ;
+
+ElementList_
+    : "," ElementListOpt[elements] { $$ = $elements; } 
+    | { $$ = NULL; }
+    ;
+
+ElementList
+    : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
+    | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
     ;
 
 ElementListOpt
@@ -1341,11 +1356,6 @@ AssignmentExpression
     | ArrowFunction[pass] { $$ = $pass; }
     | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
     ;
-
-AssignmentExpressionOpt
-    : AssignmentExpression[pass] { $$ = $pass; }
-    | LexOf { $$ = NULL; }
-    ;
 /* }}} */
 /* 12.15 Comma Operator ( , ) {{{ */
 Expression
@@ -2059,16 +2069,16 @@ TypeQualifierRightOpt
     ;
 
 IntegerType
-    : "int" { $$ = CYNew CYTypeVariable("int"); }
-    | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
-    | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
-    | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
-    | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
+    : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
+    | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
+    | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
+    | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
+    | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
     ;
 
 IntegerTypeOpt
     : IntegerType[pass] { $$ = $pass; }
-    | { $$ = CYNew CYTypeVariable("int"); }
+    | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
     ;
 
 StructFieldListOpt
@@ -2079,9 +2089,9 @@ StructFieldListOpt
 PrimitiveType
     : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
     | IntegerType[pass] { $$ = $pass; }
-    | "char" { $$ = CYNew CYTypeVariable("char"); }
-    | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
-    | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
+    | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
+    | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
+    | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
     | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
     ;
 
@@ -2271,15 +2281,29 @@ BoxableExpression
     | BooleanLiteral[pass] { $$ = $pass; }
     | NumericLiteral[pass] { $$ = $pass; }
     | StringLiteral[pass] { $$ = $pass; }
-    | ArrayLiteral[pass] { $$ = $pass; }
-    | ObjectLiteral[pass] { $$ = $pass; }
     | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
     | "YES" { $$ = CYNew CYTrue(); }
     | "NO" { $$ = CYNew CYFalse(); }
     ;
 
+KeyValuePairList_
+    : "," KeyValuePairListOpt[next] { $$ = $next; }
+    | { $$ = NULL; }
+
+KeyValuePairList
+    : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
+    ;
+
+KeyValuePairListOpt
+    : KeyValuePairList[pass] { $$ = $pass; }
+    | LexOf { $$ = NULL; }
+    ;
+
 PrimaryExpression
     : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
+    | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
+    | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
+
     | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
     | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
     | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }