X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/60496dd58d9132df7fe3f6cef8e372a786becc13..13c7f2fb8fc0619c8da1b5c8a697f7894479b070:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index 94d804b..3a31f1e 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -72,12 +72,14 @@ typedef struct { CYInfix *infix_; CYLiteral *literal_; CYMember *member_; + CYModule *module_; CYNull *null_; CYNumber *number_; CYProgram *program_; CYProperty *property_; CYPropertyName *propertyName_; CYRubyProc *rubyProc_; + CYTypeSpecifier *specifier_; CYStatement *statement_; CYString *string_; CYThis *this_; @@ -91,7 +93,7 @@ typedef struct { CYMessageParameter *messageParameter_; CYProtocol *protocol_; CYSelectorPart *selector_; - CYTypeModifier *type_; + CYTypeModifier *modifier_; CYTypedIdentifier *typedIdentifier_; CYTypedParameter *typedParameter_; @end @@ -159,6 +161,7 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin E4X ObjectiveC %token At "@" +%token Pound "#" @end %token Ampersand "&" @@ -232,6 +235,8 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin C %token Typedef "typedef" +%token Unsigned "unsigned" +%token Signed "signed" @end @begin ObjectiveC @@ -346,6 +351,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ArgumentList %type ArgumentListOpt %type Arguments +%type ArrayComprehension +%type ArrayInitialiser %type ArrayLiteral %type ArrowFunction %type ArrowParameters @@ -367,10 +374,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 @@ -391,7 +398,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ExpressionOpt %type ExpressionStatement %type FinallyOpt -%type ForComprehension %type ForStatementInitialiser %type ForInStatementInitialiser %type FormalParameter @@ -403,8 +409,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type FunctionExpression %type Identifier %type IdentifierOpt +%type IdentifierType %type IdentifierName -%type IfComprehension %type IfStatement %type Initialiser %type InitialiserOpt @@ -482,18 +488,20 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt -%type ConcreteType %type EncodedType +%type FunctionedType +%type IntegerType +%type IntegerTypeOpt %type MessageExpression %type MessageParameter %type MessageParameters %type MessageParameterList %type MessageParameterListOpt %type MessageScope -%type ModifiedType_ -%type ModifiedType +%type ModifiedType +%type Module %type PrefixedType -%type PrimitiveType +%type PrimitiveType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -504,8 +512,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SuffixedType %type TypeOpt %type TypeParenthetical -%type TypeQualifierLeft -%type TypeQualifierRight +%type TypeQualifierLeft +%type TypeQualifierRight %type TypeSignifier %type TypedIdentifier %type TypedParameterList_ @@ -654,15 +662,9 @@ WordOpt | { $$ = NULL; } ; -Identifier +IdentifierType : Identifier_ { $$ = $1; } -@begin C - | "typedef" { $$ = $1; } - | "YES" { $$ = $1; } - | "NO" { $$ = $1; } -@end - | "implements" { $$ = $1; } | "interface" { $$ = $1; } | "package" { $$ = $1; } @@ -674,19 +676,14 @@ Identifier | "abstract" { $$ = $1; } | "boolean" { $$ = $1; } | "byte" { $$ = $1; } - | "char" { $$ = $1; } | "double" { $$ = $1; } | "final" { $$ = $1; } | "float" { $$ = $1; } | "goto" { $$ = $1; } - | "int" { $$ = $1; } - | "long" { $$ = $1; } | "native" { $$ = $1; } - | "short" { $$ = $1; } | "synchronized" { $$ = $1; } | "throws" { $$ = $1; } | "transient" { $$ = $1; } - | "volatile" { $$ = $1; } // XXX: currently I only have this as Word // | "let" { $$ = $1; } @@ -697,6 +694,22 @@ Identifier | "of" { $$ = $1; } ; +Identifier + : IdentifierType + | "char" { $$ = $1; } + | "int" { $$ = $1; } + | "long" { $$ = $1; } + | "short" { $$ = $1; } + | "volatile" { $$ = $1; } +@begin C + | "typedef" { $$ = $1; } + | "unsigned" { $$ = $1; } + | "signed" { $$ = $1; } + | "YES" { $$ = $1; } + | "NO" { $$ = $1; } +@end + ; + IdentifierOpt : Identifier { $$ = $1; } | { $$ = NULL; } @@ -762,13 +775,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); } ; @@ -793,19 +812,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 {{{ */ @@ -1004,6 +1030,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 {{{ */ @@ -1027,11 +1054,11 @@ AssignmentExpression /* 11.14 Comma Operator {{{ */ Expression_ : "," Expression { $$ = $2; } - | { $$ = CYNew CYCompound(); } + | { $$ = NULL; } ; Expression - : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; } + : AssignmentExpression Expression_ { $$ = CYNew CYCompound($1, $2); } ; ExpressionOpt @@ -1370,68 +1397,80 @@ ProgramBodyOpt @begin ObjectiveC /* Cycript (Objective-C): Type Encoding {{{ */ TypeParenthetical - : "(" PrefixedType ")" { $$ = $2; } + : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } ; TypeSignifier - : Identifier { $$ = CYNew CYTypedIdentifier($1); } - | TypeParenthetical + : IdentifierType { $$ = CYNew CYTypedIdentifier($1); } + | TypeParenthetical { $$ = $1; } ; ArrayedType - : ArrayedType "[" NumericLiteral "]" { $$ = $1; CYSetLast($$->type_) = CYNew CYTypeArrayOf($3); } + : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); } | TypeSignifier { $$ = $1; } - | { $$ = CYNew CYTypedIdentifier(NULL); } + | { $$ = CYNew CYTypedIdentifier(); } + ; + +FunctionedType + : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); } ; SuffixedType : ArrayedType { $$ = $1; } - | TypeParenthetical "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; CYSetLast($$->type_) = CYNew CYTypeFunctionWith($4); } + | "(" 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 - : "*" TypeQualifierRight PrefixedType { $$ = $3; CYSetLast($$->type_) = $2; CYSetLast($$->type_) = CYNew CYTypePointerTo(); } - | SuffixedType { $$ = $1; } + : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } ; TypeQualifierLeft - : "const" TypeQualifierLeft { $$ = CYNew CYTypeConstant(); CYSetLast($$) = $2; } - | { $$ = NULL; } + : { $$ = NULL; } + | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); } + | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } ; TypeQualifierRight - : TypeQualifierRight "const" { $$ = CYNew CYTypeConstant($1); } - | { $$ = NULL; } + : PrefixedType { $$ = $1; } + | SuffixedType { $$ = $1; } + | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); } + | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); } + ; + +IntegerType + : "int" { $$ = CYNew CYTypeVariable("int"); } + | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); } + | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); } + | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); } + | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); } ; -ConcreteType - : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; CYSetLast($$) = $1; CYSetLast($$) = CYNew CYTypeVariable($2); } +IntegerTypeOpt + : IntegerType { $$ = $1; } + | { $$ = CYNew CYTypeVariable("int"); } ; PrimitiveType - : Variable { $$ = $1; } - | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); } + : IdentifierType { $$ = CYNew CYTypeVariable($1); } + | IntegerType { $$ = $1; } + | "void" { $$ = CYNew CYTypeVoid(); } + | "char" { $$ = CYNew CYTypeVariable("char"); } + | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); } + | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); } ; TypedIdentifier - : ConcreteType PrefixedType { $$ = $2; CYSetLast($$->type_) = $1; } + : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $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; } + : TypedIdentifier { $$ = CYNew CYEncodedType($1); } ; PrimaryExpression - : AtEncode "(" EncodedType ")" { $$ = $3; } + : "@encode" "(" EncodedType ")" { $$ = $3; } ; /* }}} */ /* Cycript (Objective-C): @class Declaration {{{ */ @@ -1442,7 +1481,7 @@ ClassSuperOpt ; ClassFieldListOpt - : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); } + : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $3); } | LexSetRegExp { $$ = NULL; } ; @@ -1588,20 +1627,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 {{{ */ @@ -1622,10 +1654,20 @@ PrimaryExpression ; /* }}} */ /* Cycript (Objective-C): Block Expressions {{{ */ +ModifiedType + : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->specifier_ = $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 @@ -1665,7 +1707,7 @@ TypedParameterListOpt ; PrimaryExpression - : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14->type_, $10, $17); } + : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); } ; /* }}} */ /* Cycript (C): Type Definitions {{{ */ @@ -1856,27 +1898,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 {{{ */