X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/21d5f610b933e87b7110d629daddeb8f333dcec9..5b75838211f16d9c88fb1bae3193e3693a1bee39:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index b6f355c..fe1873f 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -73,7 +73,6 @@ typedef struct { CYMember *member_; CYNull *null_; CYNumber *number_; - CYEncodedPart *part_; CYProgram *program_; CYProperty *property_; CYPropertyName *propertyName_; @@ -82,7 +81,9 @@ typedef struct { CYString *string_; CYThis *this_; CYTrue *true_; - CYEncodedType *type_; + CYTypeModifier *type_; + CYTypedIdentifier *typedIdentifier_; + CYTypedParameter *typedParameter_; CYWord *word_; @begin ObjectiveC @@ -471,6 +472,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt +%type EncodedType %type MessageExpression %type MessageParameter %type MessageParameters @@ -478,8 +480,9 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MessageParameterListOpt %type MessageScope %type ModifiedType -%type NamedTypeOpt -%type PrefixedType +%type PrefixedType +%type PrimitiveType +%type QualifiedType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -487,9 +490,12 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type SuffixedType +%type SuffixedType %type TypeOpt -%type TypedIdentifier +%type TypedIdentifier +%type TypedParameterList_ +%type TypedParameterList +%type TypedParameterListOpt %type VariadicCall @end @@ -787,7 +793,7 @@ ObjectLiteral PropertyDefinitionList_ : "," PropertyDefinitionList { $$ = $2; } - | "," { $$ = NULL; } + | "," LexSetRegExp { $$ = NULL; } | { $$ = NULL; } ; @@ -797,7 +803,7 @@ PropertyDefinitionList PropertyDefinitionListOpt : PropertyDefinitionList { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; PropertyDefinition @@ -1207,7 +1213,7 @@ BreakStatement /* }}} */ /* 12.9 The return Statement {{{ */ ReturnStatement - : "return" "\n" StrictSemi { $$ = CYNew CYReturn(NULL); } + : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); } | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); } ; /* }}} */ @@ -1247,7 +1253,7 @@ LabelledStatement /* }}} */ /* 12.13 The throw Statement {{{ */ ThrowStatement - : "throw" "\n" StrictSemi { YYABORT; } + : "throw" LexSetRegExp "\n" StrictSemi { YYABORT; } | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); } ; /* }}} */ @@ -1320,7 +1326,7 @@ ArrowParameters ConciseBody : AssignmentExpression { $$ = CYNew CYReturn($1); } - | ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $3; } + | LexSetRegExp ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $4; } ; /* }}} */ /* 14 Program {{{ */ @@ -1340,33 +1346,44 @@ ProgramBodyOpt @begin ObjectiveC /* Cycript (Objective-C): Type Encoding {{{ */ -NamedTypeOpt - : Identifier { $$ = CYNew CYEncodedPart(NULL, "withName", CYNew CYArgument(CYNew CYString($1->word_))); } - | { $$ = NULL; } - ; - SuffixedType - : NamedTypeOpt { $$ = $1; } - | "(" PrefixedType ")" { $$ = $2; } - | SuffixedType "[" NumericLiteral "]" { $$ = CYNew CYEncodedPart($1, "arrayOf", CYNew CYArgument($3)); } + : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); } + | "(" LexPushInOff PrefixedType LexPopIn ")" { $$ = $3; } + | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; } ; PrefixedType : SuffixedType { $$ = $1; } - | "*" PrefixedType { $$ = CYNew CYEncodedPart($2, "pointerTo"); } + | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; } + | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; } + ; + +PrimitiveType + : Variable { $$ = $1; } + | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); } + ; + +QualifiedType + : PrimitiveType { $$ = CYNew CYTypeVariable($1); } + | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); } ; ModifiedType - : Variable { $$ = CYNew CYEncodedType($1); } - | "const" ModifiedType { $2->base_ = CYNew CYCall(CYNew CYDirectMember($2->base_, CYNew CYString("constant"))); $$ = $2; } + : QualifiedType { $$ = $1; } + | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); } + | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); } ; TypedIdentifier - : ModifiedType PrefixedType { $1->parts_ = $2; $$ = $1;} + : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;} + ; + +EncodedType + : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); } ; PrimaryExpression - : AtEncode "(" TypedIdentifier ")" { $$ = $3; } + : AtEncode "(" EncodedType ")" { $$ = $3; } ; /* }}} */ /* Cycript (Objective-C): @class Declaration {{{ */ @@ -1378,7 +1395,7 @@ ClassSuperOpt ClassFieldListOpt : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; ClassFields @@ -1391,8 +1408,7 @@ MessageScope ; TypeOpt - : "(" TypedIdentifier ")" { $$ = $2; } - | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); } + : "(" LexSetRegExp EncodedType ")" { $$ = $3; } | { $$ = NULL; } ; @@ -1555,6 +1571,25 @@ PrimaryExpression : "@" BoxableExpression { $$ = CYNew CYBox($2); } ; /* }}} */ +/* 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); } + ; +/* }}} */ @end @begin C