%union { bool bool_; }
+%union { CYMember *access_; }
%union { CYArgument *argument_; }
%union { CYAssignment *assignment_; }
%union { CYBoolean *boolean_; }
%union { CYClause *clause_; }
%union { cy::Syntax::Catch *catch_; }
+%union { CYClassTail *classTail_; }
%union { CYComprehension *comprehension_; }
%union { CYDeclaration *declaration_; }
%union { CYDeclarations *declarations_; }
%union { CYIdentifier *identifier_; }
%union { CYInfix *infix_; }
%union { CYLiteral *literal_; }
-%union { CYMember *member_; }
+%union { CYMethod *method_; }
%union { CYModule *module_; }
%union { CYNull *null_; }
%union { CYNumber *number_; }
%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
+%union { CYTarget *target_; }
%union { CYThis *this_; }
%union { CYTrue *true_; }
%union { CYWord *word_; }
@end
@begin ObjectiveC
-%union { CYClassName *className_; }
-%union { CYClassField *classField_; }
%union { CYMessage *message_; }
%union { CYMessageParameter *messageParameter_; }
+%union { CYImplementationField *implementationField_; }
%union { CYProtocol *protocol_; }
%union { CYSelectorPart *selector_; }
@end
%code {
+typedef cy::parser::token tk;
+
#undef yylex
_finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
if (driver.mark_ == CYMarkIgnore);
return cy::parser::token::MarkModule;
}
+ lex:
+ if (driver.newline_ == CYDriver::NewLineHere)
+ driver.newline_ = CYDriver::NewLineLast;
+ else if (driver.newline_ == CYDriver::NewLineLast)
+ driver.newline_ = CYDriver::NewLineNone;
+
YYSTYPE data;
int token(cylex(&data, location, driver.scanner_));
*semantic = data.semantic_;
+
+ switch (token) {
+ case tk::_in_:
+ if (driver.in_.top())
+ token = tk::_in__;
+ break;
+
+ case tk::_yield_:
+ if (driver.yield_.top())
+ token = tk::_yield__;
+ break;
+
+ case tk::NewLine:
+ driver.newline_ = CYDriver::NewLineHere;
+ if (!driver.next_)
+ goto lex;
+ break;
+ }
+
+ driver.next_ = false;
return token;
}
+#define CYLEX() do if (yyla.empty()) { \
+ YYCDEBUG << "Mapping a token: "; \
+ yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
+ YY_SYMBOL_PRINT("Next token is", yyla); \
+} while (false)
+
#define CYMAP(to, from) do { \
- if (yyla.empty()) \
- yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
+ CYLEX(); \
if (yyla.type == yytranslate_(token::from)) \
yyla.type = yytranslate_(token::to); \
} while (false)
+#define CYLIN(from) do { \
+ CYLEX(); \
+ if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \
+ yyla.type = yytranslate_(token::from ## _); \
+} while (false)
+
#define CYERR(location, message) do { \
error(location, message); \
YYABORT; \
} while (false)
+#define CYEOK() do { \
+ yyerrok; \
+ driver.errors_.pop_back(); \
+} while (false)
+
#define CYNOT(location) \
CYERR(location, "unimplemented feature")
+#define CYMPT(location) do { \
+ if (!yyla.empty() && yyla.type_get() != yyeof_) \
+ CYERR(location, "unexpected lookahead"); \
+} while (false)
+
}
%name-prefix "cy"
%token OpenBrace "{"
%token OpenBrace_ "\n{"
%token OpenBrace__ ";{"
+%token OpenBrace_let "let {"
%token CloseBrace "}"
%token OpenBracket "["
+%token OpenBracket_let "let ["
%token CloseBracket "]"
%token At_error_ "@error"
%token _import_ "import"
%token _in_ "in"
%token _in__ "!in"
+%token _Infinity_ "Infinity"
%token _instanceof_ "instanceof"
%token _new_ "new"
%token _return_ "return"
-%token _return__ "!return"
%token _super_ "super"
%token _switch_ "switch"
+%token _target_ "target"
%token _this_ "this"
%token _throw_ "throw"
%token _try_ "try"
%token _boolean_ "boolean"
%token _byte_ "byte"
%token _char_ "char"
+%token _constructor_ "constructor"
%token _double_ "double"
+%token _eval_ "eval"
%token _final_ "final"
%token _float_ "float"
%token _from_ "from"
%token _int_ "int"
%token _interface_ "interface"
%token _let_ "let"
+%token _let__ "!let"
%token _long_ "long"
%token _native_ "native"
%token _package_ "package"
%token _private_ "private"
%token _protected_ "protected"
+%token _prototype_ "prototype"
%token _public_ "public"
%token _set_ "set"
%token _short_ "short"
%token _auto_ "auto"
%token _each_ "each"
%token _of_ "of"
+%token _of__ "!of"
@begin E4X
%token _namespace_ "namespace"
%token <string_> TemplateMiddle
%token <string_> TemplateTail
+%type <target_> AccessExpression
%type <expression_> AdditiveExpression
%type <argument_> ArgumentList_
%type <argument_> ArgumentList
%type <argument_> ArgumentListOpt
%type <argument_> Arguments
-%type <expression_> ArrayComprehension
+%type <target_> ArrayComprehension
%type <literal_> ArrayLiteral
%type <expression_> ArrowFunction
%type <functionParameter_> ArrowParameters
%type <statement_> BreakStatement
%type <statement_> BreakableStatement
%type <expression_> CallExpression_
-%type <expression_> CallExpression
+%type <target_> CallExpression
%type <clause_> CaseBlock
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <catch_> Catch
%type <identifier_> CatchParameter
%type <statement_> ClassDeclaration
-%type <expression_> ClassExpression
-%type <expression_> Comprehension
+%type <target_> ClassExpression
+%type <classTail_> ClassHeritage
+%type <classTail_> ClassHeritageOpt
+%type <classTail_> ClassTail
+%type <target_> Comprehension
%type <comprehension_> ComprehensionFor
%type <comprehension_> ComprehensionIf
%type <comprehension_> ComprehensionTail
-%type <expression_> ComputedPropertyName
+%type <propertyName_> ComputedPropertyName
%type <expression_> ConditionalExpression
%type <statement_> ContinueStatement
%type <statement_> ConciseBody
%type <element_> ElementList
%type <element_> ElementListOpt
%type <statement_> ElseStatementOpt
-%type <statement_> EmptyStatement
+%type <for_> EmptyStatement
%type <expression_> EqualityExpression
%type <expression_> Expression
%type <expression_> ExpressionOpt
+%type <for_> ExpressionStatement_
%type <statement_> ExpressionStatement
%type <finally_> Finally
%type <declaration_> ForBinding
-%type <declaration_> ForDeclaration
+%type <forin_> ForDeclaration
%type <forin_> ForInStatementInitializer
%type <for_> ForStatementInitializer
%type <declaration_> FormalParameter
%type <functionParameter_> FormalParameters
%type <statement_> FunctionBody
%type <statement_> FunctionDeclaration
-%type <expression_> FunctionExpression
+%type <target_> FunctionExpression
%type <statement_> FunctionStatementList
%type <statement_> GeneratorBody
%type <statement_> GeneratorDeclaration
-%type <expression_> GeneratorExpression
-%type <property_> GeneratorMethod
+%type <target_> GeneratorExpression
+%type <method_> GeneratorMethod
%type <statement_> HoistableDeclaration
%type <identifier_> Identifier
%type <identifier_> IdentifierType
%type <word_> IdentifierName
%type <variable_> IdentifierReference
%type <statement_> IfStatement
+%type <target_> IndirectExpression
%type <expression_> Initializer
%type <expression_> InitializerOpt
%type <statement_> IterationStatement
%type <identifier_> LabelIdentifier
%type <statement_> LabelledItem
%type <statement_> LabelledStatement
-%type <expression_> LeftHandSideExpression
-%type <statement_> LetStatement
+%type <assignment_> LeftHandSideAssignment
+%type <target_> LeftHandSideExpression
+%type <bool_> LetOrConst
%type <declaration_> LexicalBinding
+%type <for_> LexicalDeclaration_
%type <statement_> LexicalDeclaration
%type <literal_> Literal
%type <propertyName_> LiteralPropertyName
%type <expression_> LogicalANDExpression
%type <expression_> LogicalORExpression
-%type <member_> MemberAccess
-%type <expression_> MemberExpression
-%type <property_> MethodDefinition
+%type <access_> MemberAccess
+%type <target_> MemberExpression
+%type <method_> MethodDefinition
%type <module_> ModulePath
%type <expression_> MultiplicativeExpression
-%type <expression_> NewExpression
+%type <target_> NewExpression
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <expression_> PostfixExpression
-%type <expression_> PrimaryExpression
+%type <target_> PrimaryExpression
%type <propertyName_> PropertyName
%type <property_> PropertyDefinition
%type <property_> PropertyDefinitionList_
%type <statement_> StatementListOpt
%type <statement_> StatementListItem
%type <functionParameter_> StrictFormalParameters
+%type <target_> SuperCall
+%type <target_> SuperProperty
%type <statement_> SwitchStatement
-%type <expression_> TemplateLiteral
+%type <target_> TemplateLiteral
%type <span_> TemplateSpans
%type <statement_> ThrowStatement
%type <statement_> TryStatement
%type <declaration_> VariableDeclaration
%type <declarations_> VariableDeclarationList_
%type <declarations_> VariableDeclarationList
+%type <for_> VariableStatement_
%type <statement_> VariableStatement
%type <statement_> WithStatement
%type <word_> Word
@end
@begin ObjectiveC
+%type <expression_> AssignmentExpressionClassic
%type <expression_> BoxableExpression
%type <statement_> CategoryStatement
-%type <classField_> ClassFieldListOpt
-%type <classField_> ClassFields
-%type <statement_> ClassStatement
%type <expression_> ClassSuperOpt
+%type <expression_> ConditionalExpressionClassic
+%type <implementationField_> ImplementationFieldListOpt
+%type <implementationField_> ImplementationFields
%type <message_> ClassMessageDeclaration
%type <message_> ClassMessageDeclarationListOpt
-%type <className_> ClassName
%type <protocol_> ClassProtocolListOpt
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
-%type <expression_> MessageExpression
+%type <statement_> ImplementationStatement
+%type <target_> MessageExpression
%type <messageParameter_> MessageParameter
%type <messageParameter_> MessageParameters
%type <messageParameter_> MessageParameterList
@end
/* }}} */
/* Token Priorities {{{ */
-%nonassoc ""
-%left "++" "--" "{"
-
%nonassoc "if"
%nonassoc "else"
/* }}} */
LexPushReturnOn: { driver.return_.push(true); };
LexPopReturn: { driver.return_.pop(); };
+LexPushSuperOn: { driver.super_.push(true); };
+LexPushSuperOff: { driver.super_.push(false); };
+LexPopSuper: { driver.super_.pop(); };
+
LexPushYieldOn: { driver.yield_.push(true); };
LexPushYieldOff: { driver.yield_.push(false); };
LexPopYield: { driver.yield_.pop(); };
+LexOf
+ : { CYMAP(_of__, _of_); }
+ ;
+
LexSetRegExp
- : { driver.SetCondition(CYDriver::RegExpCondition); }
+ : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } } LexOf
;
LexNewLine
- : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
+ : { CYMPT(@$); driver.next_ = true; }
;
LexNoStar
| "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
| "null" { $$ = CYNew CYWord("null"); }
| "return" { $$ = CYNew CYWord("return"); }
- | "!return" { $$ = CYNew CYWord("return"); }
| "super" { $$ = CYNew CYWord("super"); }
| "switch" { $$ = CYNew CYWord("switch"); }
| "this" { $$ = CYNew CYWord("this"); }
| "yield" { $$ = CYNew CYIdentifier("yield"); }
| Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
-
- // XXX: should be Identifier
- | "let" { $$ = CYNew CYIdentifier("let"); }
;
@begin ObjectiveC
Terminator
: ";"
- | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
+ | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) CYERR(@1, "required semi-colon"); else CYEOK(); } StrictSemi
;
TerminatorOpt
| "await" { $$ = CYNew CYIdentifier("await"); }
| "boolean" { $$ = CYNew CYIdentifier("boolean"); }
| "byte" { $$ = CYNew CYIdentifier("byte"); }
+ | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
| "double" { $$ = CYNew CYIdentifier("double"); }
| "each" { $$ = CYNew CYIdentifier("each"); }
+ | "eval" { $$ = CYNew CYIdentifier("eval"); }
| "final" { $$ = CYNew CYIdentifier("final"); }
| "float" { $$ = CYNew CYIdentifier("float"); }
+ | "from" { $$ = CYNew CYIdentifier("from"); }
+ | "get" { $$ = CYNew CYIdentifier("get"); }
| "goto" { $$ = CYNew CYIdentifier("goto"); }
| "implements" { $$ = CYNew CYIdentifier("implements"); }
+ | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
| "interface" { $$ = CYNew CYIdentifier("interface"); }
+ | "let" { $$ = CYNew CYIdentifier("let"); }
+ | "!let" LexBind { $$ = CYNew CYIdentifier("let"); }
| "native" { $$ = CYNew CYIdentifier("native"); }
- | "of" { $$ = CYNew CYIdentifier("of"); }
+ | "!of" { $$ = CYNew CYIdentifier("of"); }
| "package" { $$ = CYNew CYIdentifier("package"); }
| "private" { $$ = CYNew CYIdentifier("private"); }
| "protected" { $$ = CYNew CYIdentifier("protected"); }
+ | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
| "public" { $$ = CYNew CYIdentifier("public"); }
- | "static" { $$ = CYNew CYIdentifier("static"); }
+ | "set" { $$ = CYNew CYIdentifier("set"); }
| "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
+ | "target" { $$ = CYNew CYIdentifier("target"); }
| "throws" { $$ = CYNew CYIdentifier("throws"); }
| "transient" { $$ = CYNew CYIdentifier("transient"); }
+ | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
@begin ObjectiveC
| "bool" { $$ = CYNew CYIdentifier("bool"); }
| "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
Identifier
: IdentifierType
| "char" { $$ = CYNew CYIdentifier("char"); }
- | "from" { $$ = CYNew CYIdentifier("from"); }
- | "get" { $$ = CYNew CYIdentifier("get"); }
| "int" { $$ = CYNew CYIdentifier("int"); }
| "long" { $$ = CYNew CYIdentifier("long"); }
- | "set" { $$ = CYNew CYIdentifier("set"); }
| "short" { $$ = CYNew CYIdentifier("short"); }
- | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
+ | "static" { $$ = CYNew CYIdentifier("static"); }
| "volatile" { $$ = CYNew CYIdentifier("volatile"); }
@begin C
| "extern" { $$ = CYNew CYIdentifier("extern"); }
;
PropertyDefinition
- : IdentifierReference { $$ = CYNew CYProperty($1->name_, $1); }
+ : IdentifierReference { $$ = CYNew CYPropertyValue($1->name_, $1); }
| CoverInitializedName { CYNOT(@$); }
- | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
+ | PropertyName ":" AssignmentExpression { $$ = CYNew CYPropertyValue($1, $3); }
| MethodDefinition { $$ = $1; }
;
PropertyName
: LiteralPropertyName { $$ = $1; }
- | ComputedPropertyName { CYNOT(@$); /* $$ = $1; */ }
+ | ComputedPropertyName { $$ = $1; }
;
LiteralPropertyName
;
ComputedPropertyName
- : "[" AssignmentExpression "]" { $$ = $2; }
+ : "[" AssignmentExpression "]" { $$ = CYNew CYComputed($2); }
;
CoverInitializedName
MemberExpression
: LexSetRegExp PrimaryExpression { $$ = $2; }
| MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
- | SuperProperty { CYNOT(@$); }
+ | SuperProperty { $$ = $1; }
| MetaProperty { CYNOT(@$); }
| LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
;
SuperProperty
- : LexSetRegExp "super" "[" Expression "]"
- | LexSetRegExp "super" "." IdentifierName
+ : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "[" Expression "]" { $$ = CYNew CYSuperAccess($5); }
+ | LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($5)); }
;
MetaProperty
;
CallExpression_
- : MemberExpression
- | CallExpression
+ : MemberExpression { $$ = $1; }
+ | CallExpression { $$ = $1; }
;
CallExpression
- : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
- | SuperCall { CYNOT(@$); }
+ : CallExpression_ Arguments { if (!$1->Eval()) $$ = CYNew CYCall($1, $2); else $$ = CYNew CYEval($2); }
+ | SuperCall { $$ = $1; }
| CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
;
SuperCall
- : LexSetRegExp "super" Arguments
+ : LexSetRegExp "super" { if (!driver.super_.top()) CYERR(@2, "invalid super"); } Arguments { $$ = CYNew CYSuperCall($4); }
;
Arguments
| LexSetRegExp { $$ = NULL; }
;
-LeftHandSideExpression
+AccessExpression
: NewExpression { $$ = $1; }
| CallExpression { $$ = $1; }
;
+
+LeftHandSideExpression
+ : AccessExpression LexCrement { $$ = $1; }
+ | LexSetRegExp IndirectExpression { $$ = $2; }
+ ;
/* }}} */
/* 12.4 Postfix Expressions {{{ */
+LexCrement
+ : { CYLIN(PlusPlus); CYLIN(HyphenHyphen); }
+ ;
+
PostfixExpression
- : %prec "" LeftHandSideExpression { $$ = $1; }
- | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
- | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
+ : AccessExpression LexCrement { $$ = $1; }
+ | AccessExpression LexCrement "++" { $$ = CYNew CYPostIncrement($1); }
+ | AccessExpression LexCrement "--" { $$ = CYNew CYPostDecrement($1); }
;
/* }}} */
/* 12.5 Unary Operators {{{ */
;
UnaryExpression
- : PostfixExpression { $$ = $1; }
+ : PostfixExpression LexOpenBrace { $$ = $1; }
| LexSetRegExp UnaryExpression_ { $$ = $2; }
;
/* }}} */
;
/* }}} */
/* 12.13 Conditional Operator ( ? : ) {{{ */
+@begin ObjectiveC
+ConditionalExpressionClassic
+ : LogicalORExpression { $$ = $1; }
+ | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpressionClassic { $$ = CYNew CYCondition($1, $4, $7); }
+ ;
+@end
+
ConditionalExpression
: LogicalORExpression { $$ = $1; }
| LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
;
/* }}} */
/* 12.14 Assignment Operators {{{ */
+LeftHandSideAssignment
+ : LeftHandSideExpression "=" { $$ = CYNew CYAssign($1, NULL); }
+ | LeftHandSideExpression "*=" { $$ = CYNew CYMultiplyAssign($1, NULL); }
+ | LeftHandSideExpression "/=" { $$ = CYNew CYDivideAssign($1, NULL); }
+ | LeftHandSideExpression "%=" { $$ = CYNew CYModulusAssign($1, NULL); }
+ | LeftHandSideExpression "+=" { $$ = CYNew CYAddAssign($1, NULL); }
+ | LeftHandSideExpression "-=" { $$ = CYNew CYSubtractAssign($1, NULL); }
+ | LeftHandSideExpression "<<=" { $$ = CYNew CYShiftLeftAssign($1, NULL); }
+ | LeftHandSideExpression ">>=" { $$ = CYNew CYShiftRightSignedAssign($1, NULL); }
+ | LeftHandSideExpression ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($1, NULL); }
+ | LeftHandSideExpression "&=" { $$ = CYNew CYBitwiseAndAssign($1, NULL); }
+ | LeftHandSideExpression "^=" { $$ = CYNew CYBitwiseXOrAssign($1, NULL); }
+ | LeftHandSideExpression "|=" { $$ = CYNew CYBitwiseOrAssign($1, NULL); }
+ ;
+
+@begin ObjectiveC
+AssignmentExpressionClassic
+ : ConditionalExpressionClassic { $$ = $1; }
+ | LeftHandSideAssignment AssignmentExpressionClassic { $1->SetRight($2); $$ = $1; }
+ ;
+@end
+
AssignmentExpression
: ConditionalExpression { $$ = $1; }
| LexSetRegExp YieldExpression { $$ = $2; }
| ArrowFunction { $$ = $1; }
- | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
- | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
- | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
- | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
- | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
- | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
- | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
- | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
- | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
- | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
- | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
- | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
+ | LeftHandSideAssignment AssignmentExpression { $1->SetRight($2); $$ = $1; }
;
AssignmentExpressionOpt
;
Statement
- : LexSetStatement Statement_ { $$ = $2; }
+ : LexSetStatement LexLet Statement_ { $$ = $3; }
;
Declaration__
: HoistableDeclaration { $$ = $1; }
| ClassDeclaration { $$ = $1; }
- | LexicalDeclaration { $$ = $1; }
;
Declaration_
- : LexSetRegExp Declaration__ { $$ = $2; }
+ : LexLet LexSetRegExp Declaration__ { $$ = $3; }
+ | LexicalDeclaration { $$ = $1; }
;
Declaration
StatementListOpt
: StatementList { $$ = $1; }
- | LexSetStatement LexSetRegExp { $$ = NULL; }
+ | LexSetStatement LexLet LexSetRegExp { $$ = NULL; }
;
StatementListItem
;
/* }}} */
/* 13.3 Let and Const Declarations {{{ */
+LexicalDeclaration_
+ : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); }
+ ;
+
LexicalDeclaration
- : LetOrConst BindingList Terminator { $$ = CYNew CYVar($2); }
+ : LexicalDeclaration_ Terminator { $$ = $1; }
+ ;
+
+LexLet
+ : { CYMAP(_let__, _let_); }
+ ;
+
+LexBind
+ : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf
;
LetOrConst
- : "let"
- | "const"
+ : LexLet LexSetRegExp "!let" LexBind { $$ = false; }
+ | LexLet LexSetRegExp "const" { $$ = true; }
;
BindingList_
- : "," BindingList { $$ = $2; }
+ : "," LexBind BindingList { $$ = $3; }
| { $$ = NULL; }
;
;
/* }}} */
/* 13.3.2 Variable Statement {{{ */
+VariableStatement_
+ : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); }
+ ;
+
VariableStatement
- : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
+ : VariableStatement_ Terminator { $$ = $1; }
;
VariableDeclarationList_
;
VariableDeclarationList
- : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
+ : LexBind VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($2, $3); }
;
VariableDeclaration
;
ObjectBindingPattern
- : BRACE BindingPropertyListOpt "}"
+ : "let {" BindingPropertyListOpt "}"
;
ArrayBindingPattern
- : "[" { CYNOT(@$); }
+ : "let [" { CYNOT(@$); }
;
BindingPropertyList_
;
BindingElement
- : SingleNameBinding { $$ = $1; }
- | BindingPattern InitializerOpt { CYNOT(@$); }
+ : LexBind SingleNameBinding { $$ = $2; }
+ | LexBind BindingPattern InitializerOpt { CYNOT(@$); }
;
SingleNameBinding
;
/* }}} */
/* 13.5 Expression Statement {{{ */
+ExpressionStatement_
+ : Expression { $$ = CYNew CYExpress($1); }
+
ExpressionStatement
- : Expression Terminator { $$ = CYNew CYExpress($1); }
+ : ExpressionStatement_ Terminator { $$ = $1; }
;
/* }}} */
/* 13.6 The if Statement {{{ */
IterationStatement
: "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
| "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
- | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
+ | "for" "(" LexPushInOn ForStatementInitializer LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $6, $8, $10); }
+ | "for" "(" LexPushInOn LexLet LexSetRegExp Var_ LexBind BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($8, $9), $12, $14); }
| "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
- | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
+ | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
;
ForStatementInitializer
- : ExpressionOpt { $$ = $1; }
- | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
- | LexSetRegExp LexicalDeclaration { CYNOT(@$); }
+ : LexLet LexSetRegExp EmptyStatement { $$ = $3; }
+ | LexLet ExpressionStatement_ ";" { $$ = $2; }
+ | LexLet LexSetRegExp VariableStatement_ ";" { $$ = $3; }
+ | LexicalDeclaration_ ";" { $$ = $1; }
;
ForInStatementInitializer
- : LeftHandSideExpression { $$ = $1; }
- | LexSetRegExp Var_ ForBinding { $$ = $3; }
- | LexSetRegExp ForDeclaration { $$ = $2; }
+ : LexLet AccessExpression LexCrement { $$ = $2; }
+ | LexLet LexSetRegExp IndirectExpression { $$ = $3; }
+ | LexLet LexSetRegExp Var_ LexBind ForBinding { $$ = CYNew CYForVariable($5); }
+ | ForDeclaration { $$ = $1; }
;
ForDeclaration
- : LetOrConst ForBinding { $$ = $2; }
+ : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); }
;
ForBinding
/* }}} */
/* 13.10 The return Statement {{{ */
Return
- : "!return" LexNewLine
+ : "return" { if (!driver.return_.top()) CYERR(@1, "invalid return"); } LexNewLine
;
ReturnStatement
LabelledItem
: Statement { $$ = $1; }
- | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
+ | LexSetStatement LexLet LexSetRegExp FunctionDeclaration { $$ = $4; }
;
/* }}} */
/* 13.14 The throw Statement {{{ */
;
Catch
- : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
+ : "catch" "(" LexBind CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($4, $6); }
;
Finally
/* 14.1 Function Definitions {{{ */
FunctionDeclaration
- : ";function" BindingIdentifier "(" FormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
+ : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); }
;
FunctionExpression
- : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
+ : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); }
;
StrictFormalParameters
;
FormalParameters
- : { $$ = NULL; }
+ : LexBind { $$ = NULL; }
| FormalParameterList
;
;
FormalParameterList
- : FunctionRestParameter { CYNOT(@$); }
+ : LexBind FunctionRestParameter { CYNOT(@$); }
| FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
;
;
/* }}} */
/* 14.2 Arrow Function Definitions {{{ */
+LexEqualRight
+ : { CYLIN(EqualRight); }
+ ;
+
ArrowFunction
- : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
+ : LexSetRegExp ArrowParameters LexEqualRight "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $6); }
;
ArrowParameters
: BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
- | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); }
+ | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) $$ = NULL; else { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); } }
;
ConciseBody
/* }}} */
/* 14.3 Method Definitions {{{ */
MethodDefinition
- : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYFunctionMethod($1, $3, $6); */ }
+ : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyMethod($1, $3, $6); }
| GeneratorMethod { $$ = $1; }
- | "get" PropertyName "(" ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodGet($2, $6); */ }
- | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodSet($2, $4); */ }
+ | "get" PropertyName "(" ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyGetter($2, $6); }
+ | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertySetter($2, CYNew CYFunctionParameter($4), $7); }
;
PropertySetParameterList
;
YieldExpression
- : Yield LexSetRegExp "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
+ : Yield LexSetRegExp NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
| Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ }
| Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ }
;
/* }}} */
/* 14.5 Class Definitions {{{ */
ClassDeclaration
- : ";class" BindingIdentifier ClassTail { CYNOT(@$); }
+ : ";class" BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($2, $3); }
;
ClassExpression
- : "class" BindingIdentifierOpt ClassTail { CYNOT(@$); }
+ : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); }
;
ClassTail
- : ClassHeritageOpt BRACE ClassBodyOpt "}"
+ : ClassHeritageOpt { driver.class_.push($1); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $1; }
;
ClassHeritage
- : "extends" LeftHandSideExpression
+ : "extends" AccessExpression { $$ = CYNew CYClassTail($2); }
;
ClassHeritageOpt
- : ClassHeritage
- |
+ : ClassHeritage { $$ = $1; }
+ | { $$ = CYNew CYClassTail(NULL); }
;
ClassBody
;
ClassElement
- : MethodDefinition
- | "static" MethodDefinition
+ : MethodDefinition { if (CYFunctionExpression *constructor = $1->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$1; }
+ | "static" MethodDefinition { driver.class_.top()->static_->*$2; }
| ";"
;
/* }}} */
ScriptBodyOpt
: ScriptBody { $$ = $1; }
- | LexSetStatement LexSetRegExp { $$ = NULL; }
+ | LexSetStatement LexLet LexSetRegExp { $$ = NULL; }
;
/* }}} */
/* 15.2 Modules {{{ */
;
ModuleItem
- : LexSetStatement LexSetRegExp ImportDeclaration
- | LexSetStatement LexSetRegExp ExportDeclaration
+ : LexSetStatement LexLet LexSetRegExp ImportDeclaration
+ | LexSetStatement LexLet LexSetRegExp ExportDeclaration
| StatementListItem
;
/* }}} */
;
ExportDeclaration
- : "export" LexSetStatement LexSetRegExp ExportDeclaration_
+ : "export" LexSetStatement LexLet LexSetRegExp ExportDeclaration_
| "export" Declaration
;
| { $$ = NULL; }
;
-ClassFieldListOpt
- : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
+ImplementationFieldListOpt
+ : LexSetRegExp TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($2, $4); }
| LexSetRegExp { $$ = NULL; }
;
-ClassFields
- : BRACE ClassFieldListOpt "}" { $$ = $2; }
+ImplementationFields
+ : BRACE ImplementationFieldListOpt "}" { $$ = $2; }
;
MessageScope
;
ClassMessageDeclaration
- : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
+ : MessageScope TypeOpt MessageParameters BRACE LexPushSuperOn FunctionBody "}" LexPopSuper { $$ = CYNew CYMessage($1, $2, $3, $6); }
;
ClassMessageDeclarationListOpt
| { $$ = NULL; }
;
-ClassName
- : Identifier { $$ = $1; }
- | "(" AssignmentExpression ")" { $$ = $2; }
- ;
-
// XXX: this should be AssignmentExpressionNoRight
ClassProtocols
: ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
| { $$ = NULL; }
;
-ClassStatement
- : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
+ImplementationStatement
+ : "@implementation" Identifier ClassSuperOpt ClassProtocolListOpt ImplementationFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYImplementation($2, $3, $4, $5, $6); }
;
CategoryName
;
CategoryStatement
- : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
+ : "@implementation" Identifier CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
;
Statement__
- : ClassStatement { $$ = $1; }
+ : ImplementationStatement { $$ = $1; }
| CategoryStatement { $$ = $1; }
;
/* }}} */
/* Cycript (Objective-C): Send Message {{{ */
VariadicCall
- : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
+ : "," AssignmentExpressionClassic VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
| { $$ = NULL; }
;
;
SelectorCall
- : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
+ : SelectorWordOpt ":" AssignmentExpressionClassic SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
;
SelectorList
;
MessageExpression
- : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
+ : "[" LexPushInOff AssignmentExpressionClassic { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
| "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
;
@begin C
/* Cycript (C): Pointer Indirection/Addressing {{{ */
-LeftHandSideExpression
- : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
+UnaryExpression_
+ : IndirectExpression { $$ = $1; }
+ ;
+
+IndirectExpression
+ : "*" UnaryExpression { $$ = CYNew CYIndirect($2); }
;
UnaryExpression_
;
ComprehensionFor
- : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
+ : "for" "each" "(" LexPushInOn LexBind ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($6, $9); }
;
/* }}} */
/* JavaScript FTL: for each {{{ */
: "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
;
/* }}} */
-/* JavaScript FTL: let Statements {{{ */
-LetStatement
- : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
- ;
-
-Statement__
- : LetStatement
- ;
-/* }}} */
/* JavaScript FTW: Array Comprehensions {{{ */
PrimaryExpression
;
ComprehensionFor
- : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
- | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); }
+ : "for" "(" LexPushInOn LexBind ForBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($5, $8); }
+ | "for" "(" LexPushInOn LexBind ForBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
;
ComprehensionIf
RubyProcParametersOpt
: RubyProcParameters { $$ = $1; }
- | { $$ = NULL; }
+ | LexSetRegExp { $$ = NULL; }
+ ;
+
+LexOpenBrace
+ : { CYLIN(OpenBrace); }
;
RubyProcExpression
;
PostfixExpression
- : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
+ : PostfixExpression LexOpenBrace RubyProcExpression { $$ = CYNew CYRubyBlock($1, $3); }
;
/* }}} */