-/* Cycript - Remote Execution Server and Disassembler
+/* Cycript - Inlining/Optimizing JavaScript Compiler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
#include "Parser.hpp"
@begin ObjectiveC
-#include "ObjectiveC.hpp"
+#include "ObjectiveC/Syntax.hpp"
+@end
+
+@begin E4X
+#include "E4X/Syntax.hpp"
@end
typedef struct {
CYAssignment *assignment_;
CYBoolean *boolean_;
CYClause *clause_;
- CYCatch *catch_;
+ cy::Syntax::Catch *catch_;
CYComprehension *comprehension_;
CYCompound *compound_;
CYDeclaration *declaration_;
CYMessageParameter *messageParameter_;
CYSelectorPart *selector_;
@end
+
+@begin E4X
+ CYAttribute *attribute_;
+ CYPropertyIdentifier *propertyIdentifier_;
+ CYSelector *selector_;
+@end
};
} YYSTYPE;
%lex-param { void *scanner }
@begin E4X
-%token At "@"
-%token ColonColon "::"
+%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 "</"
+
+%token ColonColon "::"
%token PeriodPeriod ".."
+@end
-%token XMLCDATA
-%token XMLComment
-%token XMLPI
+@begin E4X ObjectiveC
+%token At "@"
@end
%token Ampersand "&"
// Woah?!
%token <identifier_> Each "each"
+@begin E4X
+// E4X Conditional
+%token <identifier_> Namespace "namespace"
+%token <identifier_> XML "xml"
+@end
+
+@begin ObjectiveC
+%type <expression_> AdditiveExpressionNoWC
+%type <expression_> AssigneeExpressionNoWC
+%type <expression_> AssignmentExpressionNoWC
+%type <expression_> BitwiseANDExpressionNoWC
+%type <expression_> BitwiseXORExpressionNoWC
+%type <expression_> BitwiseORExpressionNoWC
+%type <expression_> ConditionalExpressionNoWC
+%type <expression_> EqualityExpressionNoWC
+%type <expression_> LeftHandSideExpressionNoWC
+%type <expression_> LogicalANDExpressionNoWC
+%type <expression_> LogicalORExpressionNoWC
+%type <expression_> MemberExpressionNoWC
+%type <expression_> MultiplicativeExpressionNoWC
+%type <expression_> NewExpressionNoWC
+%type <expression_> PostfixExpressionNoWC
+%type <expression_> RelationalExpressionNoWC
+%type <expression_> ShiftExpressionNoWC
+%type <expression_> UnaryExpressionNoWC
+@end
+
%token <identifier_> Identifier_
%token <number_> NumericLiteral
%token <string_> StringLiteral
%type <argument_> Arguments
%type <literal_> ArrayLiteral
%type <expression_> AssigneeExpression
-%type <expression_> AssigneeExpression_
%type <expression_> AssigneeExpressionNoBF
+%type <expression_> AssigneeExpressionNoRE
%type <expression_> AssignmentExpression
%type <assignment_> AssignmentExpression_
%type <expression_> AssignmentExpressionNoBF
%type <statement_> BreakStatement
%type <expression_> CallExpression
%type <expression_> CallExpressionNoBF
+%type <expression_> CallExpressionNoRE
%type <clause_> CaseBlock
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <statement_> LabelledStatement
%type <expression_> LeftHandSideExpression
%type <expression_> LeftHandSideExpressionNoBF
+%type <expression_> LeftHandSideExpressionNoRE
//%type <statement_> LetStatement
%type <literal_> Literal
+%type <literal_> LiteralNoRE
+%type <literal_> LiteralRE
%type <expression_> LogicalANDExpression
%type <expression_> LogicalANDExpressionNoBF
%type <expression_> LogicalANDExpressionNoIn
%type <expression_> MemberExpression
%type <expression_> MemberExpression_
%type <expression_> MemberExpressionNoBF
+%type <expression_> MemberExpressionNoRE
%type <expression_> MultiplicativeExpression
%type <expression_> MultiplicativeExpressionNoBF
%type <expression_> NewExpression
%type <expression_> NewExpression_
%type <expression_> NewExpressionNoBF
+%type <expression_> NewExpressionNoRE
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <expression_> PostfixExpression
%type <expression_> PostfixExpressionNoBF
+%type <expression_> PostfixExpressionNoRE
%type <expression_> PrimaryExpression
-%type <expression_> PrimaryExpression_
+%type <expression_> PrimaryExpressionNo
%type <expression_> PrimaryExpressionNoBF
+%type <expression_> PrimaryExpressionNoRE
+%type <expression_> PrimaryExpressionNoWC
+%type <expression_> PrimaryExpressionNoWC_
+@begin E4X
+%type <expression_> PrimaryExpressionWC
+@end
+%type <expression_> PrimaryExpressionBF
%type <statement_> Program
%type <propertyName_> PropertyName
+%type <propertyName_> PropertyName_
%type <property_> PropertyNameAndValueList
%type <property_> PropertyNameAndValueList_
%type <property_> PropertyNameAndValueListOpt
-%type <literal_> RegularExpressionLiteral_
-%type <condition_> RegularExpressionToken
%type <expression_> RelationalExpression
%type <infix_> RelationalExpression_
%type <expression_> RelationalExpressionNoBF
%type <expression_> ShiftExpression
%type <expression_> ShiftExpressionNoBF
%type <statement_> SourceElement
+%type <statement_> SourceElement_
%type <statement_> SourceElements
%type <statement_> Statement
%type <statement_> Statement_
%type <statement_> SwitchStatement
%type <statement_> ThrowStatement
%type <statement_> TryStatement
+%type <expression_> UnaryAssigneeExpression
%type <expression_> UnaryExpression
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpressionNoBF
+%type <expression_> UnaryExpressionNoRE
%type <declaration_> VariableDeclaration
%type <declaration_> VariableDeclarationNoIn
%type <declarations_> VariableDeclarationList
%type <word_> WordOpt
@end
+@begin E4X
+%type <propertyIdentifier_> PropertyIdentifier_
+%type <selector_> PropertySelector
+%type <selector_> PropertySelector_
+%type <identifier_> QualifiedIdentifier
+%type <identifier_> QualifiedIdentifier_
+%type <identifier_> WildcardIdentifier
+%type <identifier_> XMLComment
+%type <identifier_> XMLCDATA
+%type <identifier_> XMLElement
+%type <identifier_> XMLElementContent
+%type <identifier_> XMLMarkup
+%type <identifier_> XMLPI
+
+%type <attribute_> AttributeIdentifier
+/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
+%type <expression_> PropertyIdentifier
+%type <expression_> XMLListInitialiser
+%type <expression_> XMLInitialiser
+@end
+
+%token WC
+
+%nonassoc Identifier_ "abstract" "boolean" "break" "byte" "case" "catch" "char" "class" "const" "continue" "debugger" "default" "delete" "do" "double" "each" "enum" "export" "extends" "false" "final" "finally" "float" /*"for"*/ "function" "goto" "implements" "import" /*"in"*/ /*"instanceof"*/ "int" "interface" "let" "long" "namespace" "native" "new" "null" "package" "private" "protected" "public" "return" "short" "super" "static" "switch" "synchronized" "this" "throw" "throws" "transient" "true" "try" "typeof" "var" "void" "volatile" "while" "with" "xml" "yield"
+
+%nonassoc "if"
+%nonassoc "else"
+
+%nonassoc "++" "--"
+%nonassoc "(" "["
+
%left "*" "/" "%"
%left "+" "-"
%left "<<" ">>" ">>>"
%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
-%nonassoc "if"
-%nonassoc "else"
-
%start Program
%%
+/* Lexer State {{{ */
+LexSetRegExp
+ : { driver.SetCondition(CYDriver::RegExpCondition); }
+ ;
+/* }}} */
+
StrictSemi
: { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
;
| "extends" { $$ = $1; }
| "false" { $$ = $1; }
| "finally" { $$ = $1; }
- | "for" { $$ = $1; }
+ /* XXX: | "for" { $$ = $1; } */
| "function" { $$ = $1; }
| "if" { $$ = $1; }
| "import" { $$ = $1; }
| { $$ = NULL; }
;
-RegularExpressionToken
- : "/" { $$ = CYDriver::RegExpSlash; }
- | "/=" { $$ = CYDriver::RegExpSlashEqual; }
-@begin E4X
- | "/>" { $$ = CYDriver::RegExpSlashRight; }
-@end
+LiteralNoRE
+ : NullLiteral { $$ = $1; }
+ | BooleanLiteral { $$ = $1; }
+ | NumericLiteral { $$ = $1; }
+ | StringLiteral { $$ = $1; }
+ | "@" StringLiteral { $$ = $2; }
;
-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
;
/* 11.1 Primary Expressions {{{ */
-PrimaryExpression_
+PrimaryExpression
+ : PrimaryExpressionNoWC { $$ = $1; }
+@begin E4X
+ | LexSetRegExp PrimaryExpressionWC { $$ = $2; }
+@end
+ ;
+
+PrimaryExpressionNoBF
+ : PrimaryExpressionNo { $$ = $1; }
+@begin E4X
+ | PrimaryExpressionWC { $$ = $1; }
+@end
+ ;
+
+PrimaryExpressionNoRE
+ : PrimaryExpressionNoWC_ { $$ = $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; }
| "(" Expression ")" { $$ = $2; }
;
-PrimaryExpression
+PrimaryExpressionBF
: ObjectLiteral { $$ = $1; }
- | PrimaryExpression_ { $$ = $1; }
- ;
-
-PrimaryExpressionNoBF
- : PrimaryExpression_ { $$ = $1; }
;
/* }}} */
/* 11.1.4 Array Initialiser {{{ */
ElementOpt
: Element { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
ElementListOpt
: ElementList { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
ElementList
: PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
;
-PropertyName
+PropertyName_
: Identifier { $$ = $1; }
| StringLiteral { $$ = $1; }
| NumericLiteral { $$ = $1; }
;
+
+PropertyName
+ : LexSetRegExp PropertyName_ { $$ = $2; }
+ ;
/* }}} */
/* 11.2 Left-Hand-Side Expressions {{{ */
MemberExpression
: PrimaryExpression { $$ = $1; }
- | FunctionExpression { $$ = $1; }
+ | LexSetRegExp FunctionExpression { $$ = $2; }
| MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
- | MemberExpression_ { $$ = $1; }
+ | LexSetRegExp MemberExpression_ { $$ = $2; }
;
MemberExpressionNoBF
| MemberExpression_ { $$ = $1; }
;
+MemberExpressionNoRE
+ : PrimaryExpressionNoRE { $$ = $1; }
+ | FunctionExpression { $$ = $1; }
+ | MemberExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; }
+ | MemberExpression_ { $$ = $1; }
+ ;
+
+@begin ObjectiveC
+MemberExpressionNoWC
+ : PrimaryExpression { $$ = $1; }
+ | LexSetRegExp FunctionExpression { $$ = $2; }
+ | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
+ | LexSetRegExp MemberExpression_ { $$ = $2; }
+ ;
+@end
+
NewExpression_
: "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
;
NewExpression
: MemberExpression { $$ = $1; }
- | NewExpression_ { $$ = $1; }
+ | LexSetRegExp NewExpression_ { $$ = $2; }
;
NewExpressionNoBF
| NewExpression_ { $$ = $1; }
;
+NewExpressionNoRE
+ : MemberExpressionNoRE { $$ = $1; }
+ | NewExpression_ { $$ = $1; }
+ ;
+
+@begin ObjectiveC
+NewExpressionNoWC
+ : MemberExpressionNoWC { $$ = $1; }
+ | LexSetRegExp NewExpression_ { $$ = $2; }
+ ;
+@end
+
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; }
;
| CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
;
+CallExpressionNoRE
+ : PrimaryExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
+ | CallExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
+ | CallExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; }
+ ;
+
ArgumentList_
: "," ArgumentList { $$ = $2; }
| { $$ = NULL; }
ArgumentListOpt
: ArgumentList { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
ArgumentList
: NewExpressionNoBF { $$ = $1; }
| CallExpressionNoBF { $$ = $1; }
;
+
+LeftHandSideExpressionNoRE
+ : NewExpressionNoRE { $$ = $1; }
+ | CallExpressionNoRE { $$ = $1; }
+ ;
+
+@begin ObjectiveC
+LeftHandSideExpressionNoWC
+ : NewExpressionNoWC { $$ = $1; }
+ | CallExpression { $$ = $1; }
+ ;
+@end
/* }}} */
/* 11.3 Postfix Expressions {{{ */
PostfixExpression
| LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
| LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
;
+
+PostfixExpressionNoRE
+ : AssigneeExpressionNoRE { $$ = $1; }
+ | LeftHandSideExpressionNoRE "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
+ | LeftHandSideExpressionNoRE "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
+ ;
+
+@begin ObjectiveC
+PostfixExpressionNoWC
+ : AssigneeExpressionNoWC { $$ = $1; }
+ | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
+ | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
+ ;
+@end
/* }}} */
/* 11.4 Unary Operators {{{ */
UnaryExpression_
UnaryExpression
: PostfixExpression { $$ = $1; }
- | UnaryExpression_ { $$ = $1; }
+ | LexSetRegExp UnaryExpression_ { $$ = $2; }
;
UnaryExpressionNoBF
: PostfixExpressionNoBF { $$ = $1; }
| UnaryExpression_ { $$ = $1; }
;
+
+UnaryExpressionNoRE
+ : PostfixExpressionNoRE { $$ = $1; }
+ | UnaryExpression_ { $$ = $1; }
+ ;
+
+@begin ObjectiveC
+UnaryExpressionNoWC
+ : PostfixExpressionNoWC { $$ = $1; }
+ | LexSetRegExp UnaryExpression_ { $$ = $2; }
+ ;
+@end
/* }}} */
/* 11.5 Multiplicative Operators {{{ */
MultiplicativeExpression
| MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
| MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
;
+
+@begin ObjectiveC
+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); }
+ ;
+@end
/* }}} */
/* 11.6 Additive Operators {{{ */
AdditiveExpression
| AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
| AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
;
+
+@begin ObjectiveC
+AdditiveExpressionNoWC
+ : MultiplicativeExpressionNoWC { $$ = $1; }
+ | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
+ | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
+ ;
+@end
/* }}} */
/* 11.7 Bitwise Shift Operators {{{ */
ShiftExpression
| ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
| ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
;
+
+@begin ObjectiveC
+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); }
+ ;
+@end
/* }}} */
/* 11.8 Relational Operators {{{ */
RelationalExpressionNoIn_
: ShiftExpressionNoBF { $$ = $1; }
| RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
;
+
+@begin ObjectiveC
+RelationalExpressionNoWC
+ : ShiftExpressionNoWC { $$ = $1; }
+ | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
+ ;
+@end
/* }}} */
/* 11.9 Equality Operators {{{ */
EqualityExpression
| EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
| EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
;
+
+@begin ObjectiveC
+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); }
+ ;
+@end
/* }}} */
/* 11.10 Binary Bitwise Operators {{{ */
BitwiseANDExpression
| BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
;
+@begin ObjectiveC
+BitwiseANDExpressionNoWC
+ : EqualityExpressionNoWC { $$ = $1; }
+ | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
+ ;
+@end
+
BitwiseXORExpression
: BitwiseANDExpression { $$ = $1; }
| BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
| BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
;
+@begin ObjectiveC
+BitwiseXORExpressionNoWC
+ : BitwiseANDExpressionNoWC { $$ = $1; }
+ | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
+ ;
+@end
+
BitwiseORExpression
: BitwiseXORExpression { $$ = $1; }
| BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
: BitwiseXORExpressionNoBF { $$ = $1; }
| BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
;
+
+@begin ObjectiveC
+BitwiseORExpressionNoWC
+ : BitwiseXORExpressionNoWC { $$ = $1; }
+ | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
+ ;
+@end
/* }}} */
/* 11.11 Binary Logical Operators {{{ */
LogicalANDExpression
| LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
;
+@begin ObjectiveC
+LogicalANDExpressionNoWC
+ : BitwiseORExpressionNoWC { $$ = $1; }
+ | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
+ ;
+@end
+
LogicalORExpression
: LogicalANDExpression { $$ = $1; }
| LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
: LogicalANDExpressionNoBF { $$ = $1; }
| LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
;
+
+@begin ObjectiveC
+LogicalORExpressionNoWC
+ : LogicalANDExpressionNoWC { $$ = $1; }
+ | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
+ ;
+@end
/* }}} */
/* 11.12 Conditional Operator ( ? : ) {{{ */
ConditionalExpression
: LogicalORExpressionNoBF { $$ = $1; }
| LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
;
+
+@begin ObjectiveC
+ConditionalExpressionNoWC
+ : LogicalORExpressionNoWC { $$ = $1; }
+ | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
+ ;
+@end
/* }}} */
/* 11.13 Assignment Operators {{{ */
AssignmentExpression_
AssigneeExpression
: LeftHandSideExpression { $$ = $1; }
- | AssigneeExpression_ { $$ = $1; }
+ | LexSetRegExp UnaryAssigneeExpression { $$ = $2; }
;
AssigneeExpressionNoBF
: LeftHandSideExpressionNoBF { $$ = $1; }
- | AssigneeExpression_ { $$ = $1; }
+ | UnaryAssigneeExpression { $$ = $1; }
+ ;
+
+AssigneeExpressionNoRE
+ : LeftHandSideExpressionNoRE { $$ = $1; }
+ | UnaryAssigneeExpression { $$ = $1; }
;
+@begin ObjectiveC
+AssigneeExpressionNoWC
+ : LeftHandSideExpressionNoWC { $$ = $1; }
+ | LexSetRegExp UnaryAssigneeExpression { $$ = $2; }
+ ;
+@end
+
AssignmentExpression
: ConditionalExpression { $$ = $1; }
| AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
: ConditionalExpressionNoBF { $$ = $1; }
| AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
;
+
+@begin ObjectiveC
+AssignmentExpressionNoWC
+ : ConditionalExpressionNoWC { $$ = $1; }
+ | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
+ ;
+@end
/* }}} */
/* 11.14 Comma Operator {{{ */
Expression_
ExpressionOpt
: Expression { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
ExpressionNoInOpt
: ExpressionNoIn { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
Expression
;
Statement
- : Statement_ { $$ = $1; }
+ : LexSetRegExp Statement_ { $$ = $2; }
;
/* }}} */
/* 12.1 Block {{{ */
StatementListOpt
: StatementList { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
/* }}} */
/* 12.2 Variable Statement {{{ */
ForStatementInitialiser
: ExpressionNoInOpt { $$ = $1; }
- | "var" VariableDeclarationListNoIn { $$ = $2; }
+ | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = $3; }
;
/* }}} */
/* 12.6.4 The for-in Statement {{{ */
ForInStatementInitialiser
: LeftHandSideExpression { $$ = $1; }
- | "var" VariableDeclarationNoIn { $$ = $2; }
+ | LexSetRegExp "var" VariableDeclarationNoIn { $$ = $3; }
;
/* }}} */
/* }}} */
/* 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; }
;
SourceElements
: SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
;
-SourceElement
+SourceElement_
: Statement_ { $$ = $1; }
| FunctionDeclaration { $$ = $1; }
;
+
+SourceElement
+ : LexSetRegExp SourceElement_ { $$ = $2; }
+ ;
/* }}} */
@begin ObjectiveC
/* Cycript (Objective-C): @class Declaration {{{ */
ClassSuperOpt
- : ":" MemberExpressionNoBF { $$ = $2; }
+ /* XXX: why the hell did I choose MemberExpressionNoBF? */
+ : ":" LexSetRegExp MemberExpressionNoBF { $$ = $3; }
| { $$ = NULL; }
;
: "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
;
-PrimaryExpression
+PrimaryExpressionBF
: ClassExpression { $$ = $1; }
;
;
MessageExpression
- : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
- | "[" "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($3); }
+ : "[" AssignmentExpressionNoWC SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
+ | "[" LexSetRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); }
;
SelectorExpressionOpt
| Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
;
-PrimaryExpression_
+PrimaryExpressionNo
: MessageExpression { $$ = $1; }
| "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
;
@begin C
/* Cycript (C): Pointer Indirection/Addressing {{{ */
-AssigneeExpression_
- : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
+UnaryAssigneeExpression
+ : "*" UnaryExpressionNoRE { $$ = new(driver.pool_) CYIndirect($2); }
;
UnaryExpression_
@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
- | XMLCDATA
- | XMLPI
+ : XMLComment { $$ = $1; }
+ | XMLCDATA { $$ = $1; }
+ | XMLPI { $$ = $1; }
;
/* }}} */
/* 11.1 Primary Expressions {{{ */
-PrimaryExpression_
- : PropertyIdentifier
- | XMLInitialiser
- | XMLListInitialiser
+PrimaryExpressionWC
+ : PropertyIdentifier { $$ = new(driver.pool_) CYPropertyVariable($1); }
+ | XMLInitialiser { $$ = $1; }
+ | XMLListInitialiser { $$ = $1; }
;
PropertyIdentifier
- : AttributeIdentifier
- | QualifiedIdentifier
- | WildcardIdentifier
+ : AttributeIdentifier { $$ = $1; }
+ | QualifiedIdentifier { $$ = $1; }
+ | WildcardIdentifier { $$ = $1; }
;
/* }}} */
/* 11.1.1 Attribute Identifiers {{{ */
AttributeIdentifier
- : "@" PropertySelector
- | "@" QualifiedIdentifier
- | "@" "[" Expression "]"
+ : "@" QualifiedIdentifier_ { $$ = new(driver.pool_) CYAttribute($2); }
+ ;
+
+PropertySelector_
+ : PropertySelector { $$ = $1; }
+ | "[" Expression "]" { $$ = new(driver.pool_) CYSelector($2); }
;
PropertySelector
- : Identifier
- | WildcardIdentifier
+ : Identifier { $$ = new(driver.pool_) CYSelector($1); }
+ | WildcardIdentifier { $$ = $1; }
;
/* }}} */
/* 11.1.2 Qualified Identifiers {{{ */
+QualifiedIdentifier_
+ : PropertySelector_ { $$ = new(driver.pool_) CYQualified(NULL, $1); }
+ | QualifiedIdentifier { $$ = $1; }
+ ;
+
QualifiedIdentifier
- : PropertySelector "::" PropertySelector
- | PropertySelector "::" "[" Expression "]"
+ : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQualified($1, $3); }
;
/* }}} */
/* 11.1.3 Wildcard Identifiers {{{ */
WildcardIdentifier
- : "*"
+ : "*" { $$ = new(driver.pool_) CYWildcard(); }
;
/* }}} */
/* 11.1.4 XML Initialiser {{{ */
XMLInitialiser
- : XMLMarkup
- | XMLElement
+ : XMLMarkup { $$ = $1; }
+ | XMLElement { $$ = $1; }
;
XMLElement
- : "<" XMLTagContent XMLWhitespaceOpt "/>"
- | "<" XMLTagContent XMLWhitespace ">" XMLElementContentOpt "</" XMLTagName XMLWhitespaceOpt ">"
+ : "<" XMLTagContent "/>" LexPop
+ | "<" XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt ">" LexPop
;
XMLTagContent
- : XMLTagName XMLAttributesOpt
+ : LexPushXMLTag XMLTagName XMLAttributes
+ ;
+
+XMLExpression
+ : "{" LexPushRegExp Expression "}" LexPop
;
XMLTagName
- : "{" Expression "}"
+ : XMLExpression
| XMLName
;
-XMLAttributes
- : XMLWhitespace "{" Expression "}"
- | XMLAttributeOpt XMLAttributes
+XMLAttributes_
+ : XMLAttributes_ XMLAttribute
+ |
;
-XMLAttributesOpt
- : XMLAttributes
- |
+XMLAttributes
+ : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
+ | XMLAttributes_ XMLWhitespaceOpt
;
-XMLAttribute
- : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt "{" Expression "}"
- | XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue
+XMLAttributeValue_
+ : XMLExpression
+ | XMLAttributeValue
;
-XMLAttributeOpt
- : XMLAttribute
- |
+XMLAttribute
+ : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
;
XMLElementContent
- : "{" Expression "}" XMLElementContentOpt
+ : XMLExpression XMLElementContentOpt
| XMLMarkup XMLElementContentOpt
| XMLText XMLElementContentOpt
| XMLElement XMLElementContentOpt
/* }}} */
/* 11.1.5 XMLList Initialiser {{{ */
XMLListInitialiser
- : "<>" XMLElementContent "</>"
+ : "<>" LexPushXMLContent XMLElementContent "</>" LexPop { $$ = new(driver.pool_) CYXMLList($3); }
+ ;
+/* }}} */
+/* 11.2 Left-Hand-Side Expressions {{{ */
+PropertyIdentifier_
+ : Identifier { $$ = $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 {{{ */
+/* XXX: DefaultXMLNamespaceStatement
+ : "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); }
;
+
+Statement_
+ : DefaultXMLNamespaceStatement { $$ = $1; }
+ ; */
/* }}} */
@end
: ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
;
-PrimaryExpression_
+PrimaryExpressionNo
: "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
;
/* }}} */
: "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; }
;
/* }}} */