X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b12a99658d0a609d28ff522b82be8826928107cf..8a81192b83961beebb4698b63e122e754ef40ada:/Cycript.yy.in?ds=sidebyside diff --git a/Cycript.yy.in b/Cycript.yy.in index 14f6aad..94d804b 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -224,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 Typedef "typedef" +@end + @begin ObjectiveC %token AtImplementation "@implementation" %token AtImplementation_ ";@implementation" @@ -235,6 +241,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %token AtEncode "@encode" %token AtEnd "@end" %token AtSelector "@selector" +%token Yes "YES" +%token No "NO" @end %token False "false" @@ -459,6 +467,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type Variable @begin ObjectiveC +%type ArrayedType %type BoxableExpression %type CategoryStatement %type ClassExpression @@ -473,6 +482,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt +%type ConcreteType %type EncodedType %type MessageExpression %type MessageParameter @@ -480,10 +490,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MessageParameterList %type MessageParameterListOpt %type MessageScope +%type ModifiedType_ %type ModifiedType %type PrefixedType %type PrimitiveType -%type QualifiedType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -493,6 +503,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorWordOpt %type SuffixedType %type TypeOpt +%type TypeParenthetical +%type TypeQualifierLeft +%type TypeQualifierRight +%type TypeSignifier %type TypedIdentifier %type TypedParameterList_ %type TypedParameterList @@ -643,6 +657,12 @@ WordOpt Identifier : Identifier_ { $$ = $1; } +@begin C + | "typedef" { $$ = $1; } + | "YES" { $$ = $1; } + | "NO" { $$ = $1; } +@end + | "implements" { $$ = $1; } | "interface" { $$ = $1; } | "package" { $$ = $1; } @@ -744,7 +764,6 @@ PrimaryExpression | Literal { $$ = $1; } | ArrayLiteral { $$ = $1; } | ObjectLiteral { $$ = $1; } - | FunctionExpression { $$ = $1; } | Parenthetical { $$ = $1; } | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; } ; @@ -841,6 +860,7 @@ MemberExpression_ MemberExpression : LexSetRegExp PrimaryExpression { $$ = $2; } + | LexSetRegExp FunctionExpression { $$ = $2; } | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); } ; @@ -1349,42 +1369,67 @@ ProgramBodyOpt @begin ObjectiveC /* Cycript (Objective-C): Type Encoding {{{ */ +TypeParenthetical + : "(" PrefixedType ")" { $$ = $2; } + ; + +TypeSignifier + : Identifier { $$ = CYNew CYTypedIdentifier($1); } + | TypeParenthetical + ; + +ArrayedType + : ArrayedType "[" NumericLiteral "]" { $$ = $1; CYSetLast($$->type_) = CYNew CYTypeArrayOf($3); } + | TypeSignifier { $$ = $1; } + | { $$ = CYNew CYTypedIdentifier(NULL); } + ; + SuffixedType - : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); } - | "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } - | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3); $$ = $1; } + : ArrayedType { $$ = $1; } + | TypeParenthetical "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; CYSetLast($$->type_) = CYNew CYTypeFunctionWith($4); } ; PrefixedType - : SuffixedType { $$ = $1; } - | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; } - | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; } + : "*" TypeQualifierRight PrefixedType { $$ = $3; CYSetLast($$->type_) = $2; CYSetLast($$->type_) = CYNew CYTypePointerTo(); } + | SuffixedType { $$ = $1; } ; -PrimitiveType - : Variable { $$ = $1; } - | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); } +TypeQualifierLeft + : "const" TypeQualifierLeft { $$ = CYNew CYTypeConstant(); CYSetLast($$) = $2; } + | { $$ = NULL; } ; -QualifiedType - : PrimitiveType { $$ = CYNew CYTypeVariable($1); } - | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); } +TypeQualifierRight + : TypeQualifierRight "const" { $$ = CYNew CYTypeConstant($1); } + | { $$ = NULL; } ; -ModifiedType - : QualifiedType { $$ = $1; } - | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); } - | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); } +ConcreteType + : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; CYSetLast($$) = $1; CYSetLast($$) = CYNew CYTypeVariable($2); } + ; + +PrimitiveType + : Variable { $$ = $1; } + | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); } ; TypedIdentifier - : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;} + : ConcreteType PrefixedType { $$ = $2; CYSetLast($$->type_) = $1; } ; EncodedType : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); } ; +ModifiedType_ + : TypeQualifierLeft PrimitiveType { $$ = $1; CYSetLast($$) = CYNew CYTypeVariable($2); } + | ModifiedType "*" { $$ = CYNew CYTypePointerTo($1); } + ; + +ModifiedType + : ModifiedType_ TypeQualifierRight { $$ = $2; CYSetLast($$) = $1; } + ; + PrimaryExpression : AtEncode "(" EncodedType ")" { $$ = $3; } ; @@ -1568,6 +1613,8 @@ BoxableExpression | ArrayLiteral { $$ = $1; } | ObjectLiteral { $$ = $1; } | Parenthetical { $$ = $1; } + | "YES" { $$ = CYNew CYTrue(); } + | "NO" { $$ = CYNew CYFalse(); } ; PrimaryExpression @@ -1575,20 +1622,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); } ; @@ -1616,6 +1649,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 "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14->type_, $10, $17); } + ; +/* }}} */ +/* Cycript (C): Type Definitions {{{ */ +Statement__ + : "typedef" TypedIdentifier Terminator { $$ = CYNew CYTypeDefinition($2); } + ; +/* }}} */ @end /* YUI: Documentation Comments {{{ */