X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/328ad7664db4453de412b3e32cf0320ea84542b2..561ac4181ec3ad1e1e207e840f70d5017ba9a1ed:/Cycript.y.in diff --git a/Cycript.y.in b/Cycript.y.in index 4d47834..37b9203 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -1,4 +1,4 @@ -/* Cycript - Remove Execution Server and Disassembler +/* Cycript - Inlining/Optimizing JavaScript Compiler * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -46,8 +46,12 @@ %code requires { #include "Parser.hpp" -@begin ObjC -#include "ObjectiveC.hpp" +@begin ObjectiveC +#include "ObjectiveC/Syntax.hpp" +@end + +@begin E4X +#include "E4X.hpp" @end typedef struct { @@ -62,7 +66,7 @@ typedef struct { CYAssignment *assignment_; CYBoolean *boolean_; CYClause *clause_; - CYCatch *catch_; + cy::Syntax::Catch *catch_; CYComprehension *comprehension_; CYCompound *compound_; CYDeclaration *declaration_; @@ -89,13 +93,17 @@ typedef struct { CYTrue *true_; CYWord *word_; -@begin ObjC +@begin ObjectiveC CYClassName *className_; CYField *field_; CYMessage *message_; CYMessageParameter *messageParameter_; CYSelectorPart *selector_; @end + +@begin E4X + CYAttribute *attribute_; +@end }; } YYSTYPE; @@ -124,7 +132,29 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %parse-param { CYDriver &driver } %lex-param { void *scanner } +@begin E4X +%token XMLCDATA +%token XMLComment +%token XMLPI + +%token XMLAttributeValue +%token XMLName +%token XMLTagCharacters +%token XMLText +%token XMLWhitespace +@end + +@begin E4X +%token LeftRight "<>" +%token LeftSlashRight "" + +%token SlashRight "/>" +%token LeftSlash " Each "each" +@begin E4X +// E4X Conditional +%token Namespace "namespace" +%token XML "xml" +@end + %token Identifier_ %token NumericLiteral %token StringLiteral @@ -273,30 +309,35 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type AdditiveExpression %type AdditiveExpressionNoBF +%type AdditiveExpressionNoWC %type ArgumentList %type ArgumentList_ %type ArgumentListOpt %type Arguments %type ArrayLiteral %type AssigneeExpression -%type AssigneeExpression_ %type AssigneeExpressionNoBF +%type AssigneeExpressionNoWC %type AssignmentExpression %type AssignmentExpression_ %type AssignmentExpressionNoBF %type AssignmentExpressionNoIn +%type AssignmentExpressionNoWC %type BitwiseANDExpression %type BitwiseANDExpressionNoBF %type BitwiseANDExpressionNoIn +%type BitwiseANDExpressionNoWC %type Block %type Block_ %type BooleanLiteral %type BitwiseORExpression %type BitwiseORExpressionNoBF %type BitwiseORExpressionNoIn +%type BitwiseORExpressionNoWC %type BitwiseXORExpression %type BitwiseXORExpressionNoBF %type BitwiseXORExpressionNoIn +%type BitwiseXORExpressionNoWC %type BreakStatement %type CallExpression %type CallExpressionNoBF @@ -309,6 +350,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ConditionalExpression %type ConditionalExpressionNoBF %type ConditionalExpressionNoIn +%type ConditionalExpressionNoWC %type ContinueStatement %type DefaultClause %type DoWhileStatement @@ -321,6 +363,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type EqualityExpression %type EqualityExpressionNoBF %type EqualityExpressionNoIn +%type EqualityExpressionNoWC %type Expression %type ExpressionOpt %type Expression_ @@ -340,6 +383,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type FunctionBody %type FunctionDeclaration %type FunctionExpression +%type FunctionExpression_ %type Identifier %type IdentifierOpt %type IfComprehension @@ -352,46 +396,62 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LabelledStatement %type LeftHandSideExpression %type LeftHandSideExpressionNoBF +%type LeftHandSideExpressionNoWC //%type LetStatement %type Literal +%type LiteralNoRE +%type LiteralRE %type LogicalANDExpression %type LogicalANDExpressionNoBF %type LogicalANDExpressionNoIn +%type LogicalANDExpressionNoWC %type LogicalORExpression %type LogicalORExpressionNoBF %type LogicalORExpressionNoIn +%type LogicalORExpressionNoWC %type MemberAccess %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF +%type MemberExpressionNoWC %type MultiplicativeExpression %type MultiplicativeExpressionNoBF +%type MultiplicativeExpressionNoWC %type NewExpression %type NewExpression_ %type NewExpressionNoBF +%type NewExpressionNoWC %type NullLiteral %type ObjectLiteral %type PostfixExpression %type PostfixExpressionNoBF +%type PostfixExpressionNoWC %type PrimaryExpression -%type PrimaryExpression_ +%type PrimaryExpressionNo %type PrimaryExpressionNoBF +%type PrimaryExpressionNoWC +%type PrimaryExpressionNoWC_ +@begin E4X +%type PrimaryExpressionWC +@end +%type PrimaryExpressionBF %type Program %type PropertyName %type PropertyNameAndValueList %type PropertyNameAndValueList_ %type PropertyNameAndValueListOpt -%type RegularExpressionLiteral_ -%type RegularExpressionToken %type RelationalExpression %type RelationalExpression_ %type RelationalExpressionNoBF %type RelationalExpressionNoIn +%type RelationalExpressionNoWC %type RelationalExpressionNoIn_ %type ReturnStatement %type ShiftExpression %type ShiftExpressionNoBF +%type ShiftExpressionNoWC %type SourceElement +%type SourceElement_ %type SourceElements %type Statement %type Statement_ @@ -400,9 +460,11 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type SwitchStatement %type ThrowStatement %type TryStatement +%type UnaryAssigneeExpression %type UnaryExpression %type UnaryExpression_ %type UnaryExpressionNoBF +%type UnaryExpressionNoWC %type VariableDeclaration %type VariableDeclarationNoIn %type VariableDeclarationList @@ -413,7 +475,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type WhileStatement %type WithStatement -@begin ObjC +@begin ObjectiveC %type CategoryStatement %type ClassExpression %type ClassStatement @@ -441,6 +503,28 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type WordOpt @end +@begin E4X +%type PropertyIdentifier_ +%type PropertySelector +%type PropertySelector_ +%type QualifiedIdentifier +%type QualifiedIdentifier_ +%type WildcardIdentifier +%type XMLComment +%type XMLCDATA +%type XMLElement +%type XMLElementContent +%type XMLMarkup +%type XMLPI + +%type AttributeIdentifier +%type DefaultXMLNamespaceStatement +%type PropertyIdentifier +%type XMLListInitialiser +%type XMLInitialiser +@end + +/* %left "*" "/" "%" %left "+" "-" %left "<<" ">>" ">>>" @@ -453,6 +537,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %left "||" %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|=" +*/ %nonassoc "if" %nonassoc "else" @@ -461,6 +546,12 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %% +/* Lexer State {{{ */ +LexSetRegExp + : { driver.SetCondition(CYDriver::RegExpCondition); } + ; +/* }}} */ + StrictSemi : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); } ; @@ -485,7 +576,7 @@ Terminator | ;*/ -@begin ObjC +@begin ObjectiveC NewLineOpt : "\n" | @@ -514,7 +605,7 @@ Word | "extends" { $$ = $1; } | "false" { $$ = $1; } | "finally" { $$ = $1; } - | "for" { $$ = $1; } + /* XXX: | "for" { $$ = $1; } */ | "function" { $$ = $1; } | "if" { $$ = $1; } | "import" { $$ = $1; } @@ -576,21 +667,20 @@ IdentifierOpt | { $$ = NULL; } ; -RegularExpressionToken - : "/" { $$ = CYDriver::RegExStart; } - | "/=" { $$ = CYDriver::RegExRest; } +LiteralNoRE + : NullLiteral { $$ = $1; } + | BooleanLiteral { $$ = $1; } + | NumericLiteral { $$ = $1; } + | StringLiteral { $$ = $1; } ; -RegularExpressionLiteral_ - : RegularExpressionToken { driver.SetCondition($1); } RegularExpressionLiteral { $$ = $3; } +LiteralRE + : RegularExpressionLiteral { $$ = $1; } ; Literal - : NullLiteral { $$ = $1; } - | BooleanLiteral { $$ = $1; } - | NumericLiteral { $$ = $1; } - | StringLiteral { $$ = $1; } - | RegularExpressionLiteral_ { $$ = $1; } + : LiteralNoRE { $$ = $1; } + | LiteralRE { $$ = $1; } ; NullLiteral @@ -603,7 +693,30 @@ BooleanLiteral ; /* 11.1 Primary Expressions {{{ */ -PrimaryExpression_ +PrimaryExpression + : PrimaryExpressionNoWC { $$ = $1; } +@begin E4X + | LexSetRegExp PrimaryExpressionWC { $$ = $1; } +@end + ; + +PrimaryExpressionNoBF + : PrimaryExpressionNo { $$ = $1; } +@begin E4X + | PrimaryExpressionWC { $$ = $1; } +@end + ; + +PrimaryExpressionNoWC_ + : PrimaryExpressionBF { $$ = $1; } + | PrimaryExpressionNo { $$ = $1; } + ; + +PrimaryExpressionNoWC + : LexSetRegExp PrimaryExpressionNoWC_ { $$ = $2; } + ; + +PrimaryExpressionNo : "this" { $$ = $1; } | Identifier { $$ = new(driver.pool_) CYVariable($1); } | Literal { $$ = $1; } @@ -611,13 +724,8 @@ PrimaryExpression_ | "(" Expression ")" { $$ = $2; } ; -PrimaryExpression +PrimaryExpressionBF : ObjectLiteral { $$ = $1; } - | PrimaryExpression_ { $$ = $1; } - ; - -PrimaryExpressionNoBF - : PrimaryExpression_ { $$ = $1; } ; /* }}} */ /* 11.1.4 Array Initialiser {{{ */ @@ -631,12 +739,12 @@ Element ElementOpt : Element { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; ElementListOpt : ElementList { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; ElementList @@ -684,7 +792,7 @@ MemberExpression : PrimaryExpression { $$ = $1; } | FunctionExpression { $$ = $1; } | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } - | MemberExpression_ { $$ = $1; } + | LexSetRegExp MemberExpression_ { $$ = $2; } ; MemberExpressionNoBF @@ -693,13 +801,20 @@ MemberExpressionNoBF | MemberExpression_ { $$ = $1; } ; +MemberExpressionNoWC + : PrimaryExpressionNoWC { $$ = $1; } + | FunctionExpression { $$ = $1; } + | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } + | LexSetRegExp MemberExpression_ { $$ = $2; } + ; + NewExpression_ : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); } ; NewExpression : MemberExpression { $$ = $1; } - | NewExpression_ { $$ = $1; } + | LexSetRegExp NewExpression_ { $$ = $2; } ; NewExpressionNoBF @@ -707,8 +822,13 @@ NewExpressionNoBF | NewExpression_ { $$ = $1; } ; +NewExpressionNoWC + : MemberExpressionNoWC { $$ = $1; } + | LexSetRegExp NewExpression_ { $$ = $2; } + ; + CallExpression - : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } + : PrimaryExpressionNoWC Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; } ; @@ -726,7 +846,7 @@ ArgumentList_ ArgumentListOpt : ArgumentList { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; ArgumentList @@ -746,6 +866,11 @@ LeftHandSideExpressionNoBF : NewExpressionNoBF { $$ = $1; } | CallExpressionNoBF { $$ = $1; } ; + +LeftHandSideExpressionNoWC + : NewExpressionNoWC { $$ = $1; } + | CallExpression { $$ = $1; } + ; /* }}} */ /* 11.3 Postfix Expressions {{{ */ PostfixExpression @@ -759,6 +884,12 @@ PostfixExpressionNoBF | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); } ; + +PostfixExpressionNoWC + : AssigneeExpressionNoWC { $$ = $1; } + | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); } + | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); } + ; /* }}} */ /* 11.4 Unary Operators {{{ */ UnaryExpression_ @@ -777,13 +908,18 @@ UnaryExpression_ UnaryExpression : PostfixExpression { $$ = $1; } - | UnaryExpression_ { $$ = $1; } + | LexSetRegExp UnaryExpression_ { $$ = $2; } ; UnaryExpressionNoBF : PostfixExpressionNoBF { $$ = $1; } | UnaryExpression_ { $$ = $1; } ; + +UnaryExpressionNoWC + : PostfixExpressionNoWC { $$ = $1; } + | LexSetRegExp UnaryExpression_ { $$ = $2; } + ; /* }}} */ /* 11.5 Multiplicative Operators {{{ */ MultiplicativeExpression @@ -799,6 +935,13 @@ MultiplicativeExpressionNoBF | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); } | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); } ; + +MultiplicativeExpressionNoWC + : UnaryExpressionNoWC { $$ = $1; } + | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); } + | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); } + | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); } + ; /* }}} */ /* 11.6 Additive Operators {{{ */ AdditiveExpression @@ -812,6 +955,12 @@ AdditiveExpressionNoBF | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); } | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); } ; + +AdditiveExpressionNoWC + : MultiplicativeExpressionNoWC{ $$ = $1; } + | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); } + | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); } + ; /* }}} */ /* 11.7 Bitwise Shift Operators {{{ */ ShiftExpression @@ -827,6 +976,13 @@ ShiftExpressionNoBF | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); } | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); } ; + +ShiftExpressionNoWC + : AdditiveExpressionNoWC { $$ = $1; } + | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); } + | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); } + | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); } + ; /* }}} */ /* 11.8 Relational Operators {{{ */ RelationalExpressionNoIn_ @@ -856,6 +1012,11 @@ RelationalExpressionNoBF : ShiftExpressionNoBF { $$ = $1; } | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; } ; + +RelationalExpressionNoWC + : ShiftExpressionNoWC { $$ = $1; } + | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; } + ; /* }}} */ /* 11.9 Equality Operators {{{ */ EqualityExpression @@ -881,6 +1042,14 @@ EqualityExpressionNoBF | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); } | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } ; + +EqualityExpressionNoWC + : RelationalExpressionNoWC { $$ = $1; } + | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); } + | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); } + | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); } + | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); } + ; /* }}} */ /* 11.10 Binary Bitwise Operators {{{ */ BitwiseANDExpression @@ -898,6 +1067,11 @@ BitwiseANDExpressionNoBF | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); } ; +BitwiseANDExpressionNoWC + : EqualityExpressionNoWC { $$ = $1; } + | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); } + ; + BitwiseXORExpression : BitwiseANDExpression { $$ = $1; } | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } @@ -913,6 +1087,11 @@ BitwiseXORExpressionNoBF | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } ; +BitwiseXORExpressionNoWC + : BitwiseANDExpressionNoWC { $$ = $1; } + | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); } + ; + BitwiseORExpression : BitwiseXORExpression { $$ = $1; } | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } @@ -927,6 +1106,11 @@ BitwiseORExpressionNoBF : BitwiseXORExpressionNoBF { $$ = $1; } | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } ; + +BitwiseORExpressionNoWC + : BitwiseXORExpressionNoWC { $$ = $1; } + | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); } + ; /* }}} */ /* 11.11 Binary Logical Operators {{{ */ LogicalANDExpression @@ -944,6 +1128,11 @@ LogicalANDExpressionNoBF | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); } ; +LogicalANDExpressionNoWC + : BitwiseORExpressionNoWC { $$ = $1; } + | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); } + ; + LogicalORExpression : LogicalANDExpression { $$ = $1; } | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); } @@ -958,6 +1147,11 @@ LogicalORExpressionNoBF : LogicalANDExpressionNoBF { $$ = $1; } | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); } ; + +LogicalORExpressionNoWC + : LogicalANDExpressionNoWC { $$ = $1; } + | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); } + ; /* }}} */ /* 11.12 Conditional Operator ( ? : ) {{{ */ ConditionalExpression @@ -974,6 +1168,11 @@ ConditionalExpressionNoBF : LogicalORExpressionNoBF { $$ = $1; } | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); } ; + +ConditionalExpressionNoWC + : LogicalORExpressionNoWC { $$ = $1; } + | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); } + ; /* }}} */ /* 11.13 Assignment Operators {{{ */ AssignmentExpression_ @@ -993,12 +1192,17 @@ AssignmentExpression_ AssigneeExpression : LeftHandSideExpression { $$ = $1; } - | AssigneeExpression_ { $$ = $1; } + | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } ; AssigneeExpressionNoBF : LeftHandSideExpressionNoBF { $$ = $1; } - | AssigneeExpression_ { $$ = $1; } + | UnaryAssigneeExpression { $$ = $1; } + ; + +AssigneeExpressionNoWC + : LeftHandSideExpressionNoWC { $$ = $1; } + | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } ; AssignmentExpression @@ -1026,6 +1230,11 @@ AssignmentExpressionNoBF : ConditionalExpressionNoBF { $$ = $1; } | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; + +AssignmentExpressionNoWC + : ConditionalExpressionNoWC { $$ = $1; } + | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } + ; /* }}} */ /* 11.14 Comma Operator {{{ */ Expression_ @@ -1040,12 +1249,12 @@ ExpressionNoIn_ ExpressionOpt : Expression { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; ExpressionNoInOpt : ExpressionNoIn { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; Expression @@ -1080,7 +1289,7 @@ Statement_ ; Statement - : Statement_ { $$ = $1; } + : LexSetRegExp Statement_ { $$ = $2; } ; /* }}} */ /* 12.1 Block {{{ */ @@ -1098,7 +1307,7 @@ StatementList StatementListOpt : StatementList { $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; /* }}} */ /* 12.2 Variable Statement {{{ */ @@ -1196,7 +1405,7 @@ ForStatement ForStatementInitialiser : ExpressionNoInOpt { $$ = $1; } - | "var" VariableDeclarationListNoIn { $$ = $2; } + | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = $3; } ; /* }}} */ /* 12.6.4 The for-in Statement {{{ */ @@ -1206,7 +1415,7 @@ ForInStatement ForInStatementInitialiser : LeftHandSideExpression { $$ = $1; } - | "var" VariableDeclarationNoIn { $$ = $2; } + | LexSetRegExp "var" VariableDeclarationNoIn { $$ = $3; } ; /* }}} */ @@ -1261,16 +1470,16 @@ LabelledStatement /* }}} */ /* 12.13 The throw Statement {{{ */ ThrowStatement - : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); } + : "throw" Expression Terminator { $$ = new(driver.pool_) cy::Syntax::Throw($2); } ; /* }}} */ /* 12.14 The try Statement {{{ */ TryStatement - : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); } + : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) cy::Syntax::Try($2, $3, $4); } ; CatchOpt - : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); } + : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) cy::Syntax::Catch($3, $5); } | { $$ = NULL; } ; @@ -1285,10 +1494,14 @@ FunctionDeclaration : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); } ; -FunctionExpression +FunctionExpression_ : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); } ; +FunctionExpression + : LexSetRegExp FunctionExpression_ { $$ = $2; } + ; + FormalParameterList_ : "," FormalParameterList { $$ = $2; } | { $$ = NULL; } @@ -1310,19 +1523,24 @@ Program SourceElements : SourceElement SourceElements { $1->SetNext($2); $$ = $1; } - | { $$ = NULL; } + | LexSetRegExp { $$ = NULL; } ; -SourceElement +SourceElement_ : Statement_ { $$ = $1; } | FunctionDeclaration { $$ = $1; } ; + +SourceElement + : LexSetRegExp SourceElement_ { $$ = $2; } + ; /* }}} */ -@begin ObjC +@begin ObjectiveC /* Cycript (Objective-C): @class Declaration {{{ */ ClassSuperOpt - : ":" MemberExpressionNoBF { $$ = $2; } + /* XXX: why the hell did I choose MemberExpressionNoBF? */ + : ":" LexSetRegExp MemberExpressionNoBF { $$ = $3; } | { $$ = NULL; } ; @@ -1389,7 +1607,7 @@ CategoryStatement : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); } ; -PrimaryExpression +PrimaryExpressionBF : ClassExpression { $$ = $1; } ; @@ -1419,7 +1637,8 @@ SelectorList ; MessageExpression - : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); } + : "[" AssignmentExpressionNoWC SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); } + | "[" LexSetRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); } ; SelectorExpressionOpt @@ -1436,7 +1655,7 @@ SelectorExpression | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); } ; -PrimaryExpression_ +PrimaryExpressionNo : MessageExpression { $$ = $1; } | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); } ; @@ -1445,7 +1664,7 @@ PrimaryExpression_ @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ -AssigneeExpression_ +UnaryAssigneeExpression : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); } ; @@ -1460,6 +1679,186 @@ MemberAccess /* }}} */ @end +@begin E4X +/* Lexer State {{{ */ +LexPushRegExp + : { driver.PushCondition(CYDriver::RegExpCondition); } + ; + +LexPushXMLContent + : { driver.PushCondition(CYDriver::XMLContentCondition); } + ; + +LexPushXMLTag + : { driver.PushCondition(CYDriver::XMLTagCondition); } + ; + +LexPop + : { driver.PopCondition(); } + ; + +LexSetXMLContent + : { driver.SetCondition(CYDriver::XMLContentCondition); } + ; + +LexSetXMLTag + : { driver.SetCondition(CYDriver::XMLTagCondition); } + ; +/* }}} */ + +XMLWhitespaceOpt + : XMLWhitespace + | + ; + +/* 8.1 Context Keywords {{{ */ +Identifier + : "namespace" { $$ = $1; } + | "xml" { $$ = $1; } + ; +/* }}} */ +/* 8.3 XML Initialiser Input Elements {{{ */ +XMLMarkup + : XMLComment { $$ = $1; } + | XMLCDATA { $$ = $1; } + | XMLPI { $$ = $1; } + ; +/* }}} */ +/* 11.1 Primary Expressions {{{ */ +PrimaryExpressionWC + : PropertyIdentifier { $$ = $1; } + | XMLInitialiser { $$ = $1; } + | XMLListInitialiser { $$ = $1; } + ; + +PropertyIdentifier + : AttributeIdentifier { $$ = $1; } + | QualifiedIdentifier { $$ = $1; } + | WildcardIdentifier { $$ = $1; } + ; +/* }}} */ +/* 11.1.1 Attribute Identifiers {{{ */ +AttributeIdentifier + : "@" QualifiedIdentifier_ { $$ = new(driver.pool_) CYAttribute($2); } + ; + +PropertySelector_ + : PropertySelector + | "[" Expression "]" + ; + +PropertySelector + : Word { $$ = $1; } + | WildcardIdentifier { $$ = $1; } + ; +/* }}} */ +/* 11.1.2 Qualified Identifiers {{{ */ +QualifiedIdentifier_ + : PropertySelector_ { $$ = $1; } + | QualifiedIdentifier { $$ = $1; } + ; + +QualifiedIdentifier + : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQName($1, $3); } + ; +/* }}} */ +/* 11.1.3 Wildcard Identifiers {{{ */ +WildcardIdentifier + : "*" { $$ = new(driver.pool_) CYWildcard(); } + ; +/* }}} */ +/* 11.1.4 XML Initialiser {{{ */ +XMLInitialiser + : XMLMarkup { $$ = $1; } + | XMLElement { $$ = $1; } + ; + +XMLElement + : "<" XMLTagContent_ "/>" LexPop + | "<" XMLTagContent_ ">" LexSetXMLContent XMLElementContentOpt "" LexPop + ; + +XMLTagContent_ + : LexPushXMLTag XMLTagContent XMLWhitespaceOpt + ; + +XMLTagContent + : XMLTagName XMLAttributesOpt + ; + +XMLExpression + : "{" LexPushRegExp Expression "}" LexPop + ; + +XMLTagName + : XMLExpression + | XMLName + ; + +XMLAttributes + : XMLWhitespace XMLExpression + | XMLAttributeOpt XMLAttributes + ; + +XMLAttributesOpt + : XMLAttributes + | + ; + +XMLAttributeValue_ + : XMLExpression + | XMLAttributeValue + ; + +XMLAttribute + : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_ + ; + +XMLAttributeOpt + : XMLAttribute + | + ; + +XMLElementContent + : XMLExpression XMLElementContentOpt + | XMLMarkup XMLElementContentOpt + | XMLText XMLElementContentOpt + | XMLElement XMLElementContentOpt + ; + +XMLElementContentOpt + : XMLElementContent + | + ; +/* }}} */ +/* 11.1.5 XMLList Initialiser {{{ */ +XMLListInitialiser + : "<>" LexPushXMLContent XMLElementContent "" LexPop { $$ = new(driver.pool_) CYXMLList($3); } + ; +/* }}} */ +/* 11.2 Left-Hand-Side Expressions {{{ */ +PropertyIdentifier_ + : Word { $$ = $1; } + | PropertyIdentifier { $$ = $1; } + ; + +MemberAccess + : "." PropertyIdentifier { $$ = new(driver.pool_) CYPropertyMember(NULL, $2); } + | ".." PropertyIdentifier_ { $$ = new(driver.pool_) CYDescendantMember(NULL, $2); } + | "." "(" Expression ")" { $$ = new(driver.pool_) CYFilteringPredicate(NULL, $3); } + ; +/* }}} */ +/* 12.1 The default xml namespace Statement {{{ */ +DefaultXMLNamespaceStatement + : "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); } + ; + +Statement_ + : DefaultXMLNamespaceStatement { $$ = $1; } + ; +/* }}} */ +@end + /* ECMAScript5: Object Literal Trailing Comma {{{ */ PropertyNameAndValueList_ : "," { $$ = NULL; } @@ -1485,7 +1884,7 @@ ComprehensionList : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } ; -PrimaryExpression_ +PrimaryExpressionNo : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); } ; /* }}} */ @@ -1499,13 +1898,13 @@ LetStatement : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); } ; -Statement +Statement_ : LetStatement ; *//* }}} */ /* JavaScript FTW: Function Statements {{{ */ Statement - : FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $1; } + : LexSetRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; } ; /* }}} */