X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/afbff131aaf5c5efeee9c306b41e1ff586832b88..e7ff015817107dbac9373c19ce851178e4f3c791:/Cycript.yy.in?ds=sidebyside diff --git a/Cycript.yy.in b/Cycript.yy.in index 0425b21..5a35dd7 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -72,6 +72,7 @@ typedef struct { CYInfix *infix_; CYLiteral *literal_; CYMember *member_; + CYModule *module_; CYNull *null_; CYNumber *number_; CYProgram *program_; @@ -91,7 +92,7 @@ typedef struct { CYMessageParameter *messageParameter_; CYProtocol *protocol_; CYSelectorPart *selector_; - CYTypeModifier *type_; + CYTypeModifier *modifier_; CYTypedIdentifier *typedIdentifier_; CYTypedParameter *typedParameter_; @end @@ -159,6 +160,7 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin E4X ObjectiveC %token At "@" +%token Pound "#" @end %token Ampersand "&" @@ -241,6 +243,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" @@ -344,6 +348,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ArgumentList %type ArgumentListOpt %type Arguments +%type ArrayComprehension +%type ArrayInitialiser %type ArrayLiteral %type ArrowFunction %type ArrowParameters @@ -365,10 +371,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type CaseClause %type CaseClausesOpt %type CatchOpt -%type ComprehensionForList -%type ComprehensionForListOpt -%type ComprehensionList -%type ComprehensionListOpt +%type Comprehension +%type ComprehensionFor +%type ComprehensionIf +%type ComprehensionTail %type ConditionalExpression %type ContinueStatement %type ConciseBody @@ -389,7 +395,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ExpressionOpt %type ExpressionStatement %type FinallyOpt -%type ForComprehension %type ForStatementInitialiser %type ForInStatementInitialiser %type FormalParameter @@ -402,7 +407,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type Identifier %type IdentifierOpt %type IdentifierName -%type IfComprehension %type IfStatement %type Initialiser %type InitialiserOpt @@ -465,6 +469,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type Variable @begin ObjectiveC +%type ArrayedType %type BoxableExpression %type CategoryStatement %type ClassExpression @@ -480,16 +485,17 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocols %type ClassProtocolsOpt %type EncodedType +%type FunctionedType %type MessageExpression %type MessageParameter %type MessageParameters %type MessageParameterList %type MessageParameterListOpt %type MessageScope -%type ModifiedType +%type ModifiedType +%type Module %type PrefixedType %type PrimitiveType -%type QualifiedType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -499,6 +505,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 @@ -651,6 +661,8 @@ Identifier @begin C | "typedef" { $$ = $1; } + | "YES" { $$ = $1; } + | "NO" { $$ = $1; } @end | "implements" { $$ = $1; } @@ -752,13 +764,19 @@ PrimaryExpression : "this" { $$ = $1; } | Variable { $$ = $1; } | Literal { $$ = $1; } - | ArrayLiteral { $$ = $1; } + | ArrayInitialiser { $$ = $1; } | ObjectLiteral { $$ = $1; } | Parenthetical { $$ = $1; } | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; } ; /* }}} */ -/* 11.1.4.1 Array Initialiser {{{ */ +/* 11.1.4 Array Initializer {{{ */ +ArrayInitialiser + : ArrayLiteral { $$ = $1; } + | ArrayComprehension { $$ = $1; } + ; +/* }}} */ +/* 11.1.4.1 Array Literal {{{ */ ArrayLiteral : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); } ; @@ -783,19 +801,26 @@ ElementListOpt ; /* }}} */ /* 11.1.4.2 Array Comprehension {{{ */ -PrimaryExpression - : "[" LexPushInOff AssignmentExpression ComprehensionForList "]" LexPopIn { $$ = CYNew CYArrayComprehension($3, $4); } +ArrayComprehension + : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; } ; -ComprehensionForList - : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); } - | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); } +Comprehension + : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); } ; -ComprehensionForListOpt - : ComprehensionForList { $$ = $1; } - | "if" Expression { $$ = CYNew CYIfComprehension($2); } - | { $$ = NULL; } +ComprehensionTail + : { $$ = NULL; } + | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); } + | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); } + ; + +ComprehensionFor + : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); } + ; + +ComprehensionIf + : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); } ; /* }}} */ /* 11.1.5 Object Initialiser {{{ */ @@ -994,6 +1019,7 @@ LogicalORExpression ConditionalExpression : LogicalORExpression { $$ = $1; } | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); } + | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); } ; /* }}} */ /* 11.13 Assignment Operators {{{ */ @@ -1359,40 +1385,59 @@ ProgramBodyOpt @begin ObjectiveC /* Cycript (Objective-C): Type Encoding {{{ */ +TypeParenthetical + : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } + ; + +TypeSignifier + : Identifier { $$ = CYNew CYTypedIdentifier($1); } + | TypeParenthetical { $$ = $1; } + ; + +ArrayedType + : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); } + | TypeSignifier { $$ = $1; } + | { $$ = CYNew CYTypedIdentifier(); } + ; + +FunctionedType + : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); } + ; + SuffixedType - : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); } - | "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } - | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3); $$ = $1; } + : ArrayedType { $$ = $1; } + | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); } + | TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; } + | FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; } ; PrefixedType - : SuffixedType { $$ = $1; } - | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; } - | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; } + : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } ; -PrimitiveType - : Variable { $$ = $1; } - | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); } +TypeQualifierLeft + : "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); } + /* XXX: | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } */ + | { $$ = NULL; } ; -QualifiedType - : PrimitiveType { $$ = CYNew CYTypeVariable($1); } - | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); } +TypeQualifierRight + : "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); } + | PrefixedType { $$ = $1; } + | SuffixedType { $$ = $1; } ; -ModifiedType - : QualifiedType { $$ = $1; } - | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); } - | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); } +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;} + : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->type_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; } ; EncodedType - : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); } + : TypedIdentifier { $$ = CYNew CYEncodedType($1); } ; PrimaryExpression @@ -1553,20 +1598,13 @@ PrimaryExpression ; /* }}} */ /* Cycript (Objective-C): @import Directive {{{ */ -PathName - : "/" PathName - | "." PathName - | Word PathName - | - ; - -ImportPath - : "<" PathName ">" - | StringLiteral +Module + : Module "." Word { $$ = CYNew CYModule($3, $1); } + | Word { $$ = CYNew CYModule($1); } ; -StatementListItem - : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); } +Declaration__ + : "@import" Module { $$ = CYNew CYImport($2); } ; /* }}} */ /* Cycript (Objective-C): Boxed Expressions {{{ */ @@ -1578,6 +1616,8 @@ BoxableExpression | ArrayLiteral { $$ = $1; } | ObjectLiteral { $$ = $1; } | Parenthetical { $$ = $1; } + | "YES" { $$ = CYNew CYTrue(); } + | "NO" { $$ = CYNew CYFalse(); } ; PrimaryExpression @@ -1585,10 +1625,20 @@ PrimaryExpression ; /* }}} */ /* Cycript (Objective-C): Block Expressions {{{ */ +ModifiedType + : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->type_ = $2; $$->modifier_ = $1; } + | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } + ; + PrimaryExpression : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); } ; /* }}} */ +/* Cycript (Objective-C): Instance Literals {{{ */ +PrimaryExpression + : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); } + ; +/* }}} */ @end @begin C @@ -1628,7 +1678,7 @@ TypedParameterListOpt ; PrimaryExpression - : "[" LexPushInOff LexSetRegExp "=" "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" ModifiedType BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($13, $9, $16); } + : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); } ; /* }}} */ /* Cycript (C): Type Definitions {{{ */ @@ -1819,27 +1869,13 @@ Statement__ @end /* JavaScript 1.7: Array Comprehensions {{{ */ -IfComprehension - : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); } +Comprehension + : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); } ; -ForComprehension - : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); } - | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); } - ; - -ComprehensionList - : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } - ; - -ComprehensionListOpt - : ComprehensionList { $$ = $1; } - | IfComprehension { $$ = $1; } - | { $$ = NULL; } - ; - -PrimaryExpression - : "[" LexPushInOff AssignmentExpression ComprehensionList "]" LexPopIn { $$ = CYNew CYArrayComprehension($3, $4); } +ComprehensionFor + : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); } + | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); } ; /* }}} */ /* JavaScript 1.7: for each {{{ */