X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/797cb0e583f817860d6e8672b48af28b1ccfe5b5..abadba191738e5d27797718fccf50d82ffe7b0b6:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index f4c6a20..e735597 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -1,5 +1,5 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2010 Jay Freeman (saurik) + * Copyright (C) 2009-2012 Jay Freeman (saurik) */ /* GNU Lesser General Public License, Version 3 {{{ */ @@ -126,6 +126,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %parse-param { CYDriver &driver } %lex-param { void *cyscanner } +/* Token Declarations {{{ */ @begin E4X %token XMLCDATA %token XMLComment @@ -332,6 +333,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ArrowFunction %type ArrowParameters %type AssignmentExpression +%type Binding %type BindingIdentifier %type BitwiseANDExpression %type Block_ @@ -348,6 +350,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %type CaseClause %type CaseClausesOpt %type CatchOpt +%type ComprehensionForList +%type ComprehensionForListOpt %type ComprehensionList %type ComprehensionListOpt %type ConditionalExpression @@ -393,7 +397,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type LetStatement %type LexicalDeclaration %type Literal -%type LiteralNoRE +%type ValueLiteral %type LogicalANDExpression %type LogicalORExpression %type MemberAccess @@ -445,11 +449,13 @@ int cylex(YYSTYPE *, cy::location *, void *); %type WordOpt @begin ObjectiveC +%type BoxableExpression %type CategoryStatement %type ClassExpression +%type ClassFieldListOpt +%type ClassFields %type ClassStatement %type ClassSuperOpt -%type ClassFieldList %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt %type ClassName @@ -494,12 +500,14 @@ int cylex(YYSTYPE *, cy::location *, void *); %type XMLListInitialiser %type XMLInitialiser @end - +/* }}} */ +/* Token Priorities {{{ */ %nonassoc "" %left "++" "--" %nonassoc "if" %nonassoc "else" +/* }}} */ %start Program @@ -530,44 +538,31 @@ LexNoFunction : { if (yychar == token::Function) yychar = token::Function_; } ; +LexNoAtImplementation + : { if (yychar == token::AtImplementation) yychar = token::AtImplementation_; } + ; + LexSetStatement - : LexNoBrace LexNoFunction + : LexNoBrace LexNoFunction LexNoAtImplementation ; /* }}} */ - +/* Virtual Tokens {{{ */ BRACE : "{" | "\n{" ; +/* }}} */ -StrictSemi - : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); } - ; - -Terminator - : ";" - | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi - ; - -TerminatorOpt - : ";" - | error { yyerrok; driver.errors_.pop_back(); } StrictSemi +/* 7.6 Identifier Names and Identifiers {{{ */ +IdentifierName + : Word { $$ = $1; } ; -/*CommaOpt - : "," - | - ;*/ - NewLineOpt : "\n" | ; -IdentifierName - : Word { $$ = $1; } - ; - Word : Identifier { $$ = $1; } | "break" NewLineOpt { $$ = $1; } @@ -618,15 +613,6 @@ WordOpt | { $$ = NULL; } ; -@begin ObjectiveC -PrimaryExpression - : "@" LiteralNoRE { $$ = CYNew CYBox($2); } - | "@" ArrayLiteral { $$ = CYNew CYBox($2); } - | "@" ObjectLiteral { $$ = CYNew CYBox($2); } - | "@" Parenthetical { $$ = CYNew CYBox($2); } - ; -@end - Identifier : Identifier_ { $$ = $1; } @@ -668,27 +654,48 @@ IdentifierOpt : Identifier { $$ = $1; } | { $$ = NULL; } ; +/* }}} */ -LiteralNoRE +/* 7.8 Literals {{{ */ +Literal : NullLiteral { $$ = $1; } - | BooleanLiteral { $$ = $1; } - | NumericLiteral { $$ = $1; } - | StringLiteral { $$ = $1; } + | ValueLiteral { $$ = $1; } ; -Literal - : LiteralNoRE { $$ = $1; } +ValueLiteral + : BooleanLiteral { $$ = $1; } + | NumericLiteral { $$ = $1; } + | StringLiteral { $$ = $1; } | RegularExpressionLiteral { $$ = $1; } ; - +/* }}} */ +/* 7.8.1 Null Literals {{{ */ NullLiteral : "null" { $$ = $1; } ; - +/* }}} */ +/* 7.8.2 Boolean Literals {{{ */ BooleanLiteral : "true" { $$ = $1; } | "false" { $$ = $1; } ; +/* }}} */ + +/* 7.9 Automatic Semicolon Insertion {{{ */ +StrictSemi + : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); } + ; + +Terminator + : ";" + | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi + ; + +TerminatorOpt + : ";" + | error { yyerrok; driver.errors_.pop_back(); } StrictSemi + ; +/* }}} */ /* 11.1 Primary Expressions {{{ */ Parenthetical @@ -735,6 +742,22 @@ ElementListOpt | LexSetRegExp { $$ = NULL; } ; /* }}} */ +/* 11.1.4.2 Array Comprehension {{{ */ +PrimaryExpression + : "[" LexPushInOff AssignmentExpression ComprehensionForList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); } + ; + +ComprehensionForList + : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); } + | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); } + ; + +ComprehensionForListOpt + : ComprehensionForList { $$ = $1; } + | "if" Expression { $$ = CYNew CYIfComprehension($2); } + | { $$ = NULL; } + ; +/* }}} */ /* 11.1.5 Object Initialiser {{{ */ ObjectLiteral : BRACE LexPushInOff PropertyDefinitionListOpt LexPopIn "}" { $$ = CYNew CYObject($3); } @@ -1033,11 +1056,16 @@ StatementListItem | Declaration { $$ = $1; } ; /* }}} */ + /* 12.2 Declarations {{{ */ BindingIdentifier : Identifier { $$ = $1; } ; +Binding + : BindingIdentifier + ; + // XXX: BindingPattern /* }}} */ /* 12.2.1 Let and Const Declarations {{{ */ @@ -1089,6 +1117,7 @@ SingleNameBinding : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } ; /* }}} */ + /* 12.3 Empty Statement {{{ */ EmptyStatement : ";" { $$ = CYNew CYEmpty(); } @@ -1295,17 +1324,13 @@ ClassSuperOpt | { $$ = NULL; } ; -ClassField - : Expression Identifier ";" - ; - -ClassFieldList - : BRACE ClassFieldListOpt "}" { $$ = NULL; } +ClassFieldListOpt + : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); } + | { $$ = NULL; } ; -ClassFieldListOpt - : ClassFieldListOpt ClassField - | +ClassFields + : BRACE ClassFieldListOpt "}" { $$ = $2; } ; MessageScope @@ -1315,7 +1340,7 @@ MessageScope TypeOpt : "(" Expression ")" { $$ = $2; } - | "(" LexSetRegExp "void" ")" { $$ = NULL; } + | "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); } | { $$ = NULL; } ; @@ -1373,11 +1398,11 @@ ClassProtocolListOpt ; ClassExpression - : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } + : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } ; ClassStatement - : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } + : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } ; CategoryName @@ -1463,6 +1488,21 @@ StatementListItem : "@import" ImportPath { $$ = CYNew CYImport(); } ; /* }}} */ +/* Cycript (Objective-C): Boxed Expressions {{{ */ +BoxableExpression + : NullLiteral { $$ = $1; } + | BooleanLiteral { $$ = $1; } + | NumericLiteral { $$ = $1; } + | StringLiteral { $$ = $1; } + | ArrayLiteral { $$ = $1; } + | ObjectLiteral { $$ = $1; } + | Parenthetical { $$ = $1; } + ; + +PrimaryExpression + : "@" BoxableExpression { $$ = CYNew CYBox($2); } + ; +/* }}} */ @end @begin C @@ -1515,11 +1555,12 @@ LexSetXMLTag : { driver.SetCondition(CYDriver::XMLTagCondition); } ; /* }}} */ - +/* Virtual Tokens {{{ */ XMLWhitespaceOpt : XMLWhitespace | ; +/* }}} */ /* 8.1 Context Keywords {{{ */ Identifier @@ -1534,6 +1575,7 @@ XMLMarkup | XMLPI { $$ = $1; } ; /* }}} */ + /* 11.1 Primary Expressions {{{ */ PrimaryExpression : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); } @@ -1637,6 +1679,7 @@ XMLListInitialiser : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "" { $$ = CYNew CYXMLList($4); } ; /* }}} */ + /* 11.2 Left-Hand-Side Expressions {{{ */ PropertyIdentifier_ : Identifier { $$ = $1; } @@ -1666,8 +1709,8 @@ IfComprehension ; ForComprehension - : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); } - | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); } + : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); } + | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); } ; ComprehensionList