1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define YYSTACKEXPANDABLE 1
30 #define CYNew new(driver.pool_)
33 #include "ObjectiveC/Syntax.hpp"
37 #include "E4X/Syntax.hpp"
40 #include "Highlight.hpp"
43 %union { bool bool_; }
45 %union { CYMember *access_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBinding *binding_; }
49 %union { CYBindings *bindings_; }
50 %union { CYBoolean *boolean_; }
51 %union { CYClause *clause_; }
52 %union { cy::Syntax::Catch *catch_; }
53 %union { CYClassTail *classTail_; }
54 %union { CYComprehension *comprehension_; }
55 %union { CYElement *element_; }
56 %union { CYExpression *expression_; }
57 %union { CYFalse *false_; }
58 %union { CYVariable *variable_; }
59 %union { CYFinally *finally_; }
60 %union { CYForInitializer *for_; }
61 %union { CYForInInitializer *forin_; }
62 %union { CYFunctionParameter *functionParameter_; }
63 %union { CYIdentifier *identifier_; }
64 %union { CYInfix *infix_; }
65 %union { CYLiteral *literal_; }
66 %union { CYMethod *method_; }
67 %union { CYModule *module_; }
68 %union { CYNull *null_; }
69 %union { CYNumber *number_; }
70 %union { CYParenthetical *parenthetical_; }
71 %union { CYProperty *property_; }
72 %union { CYPropertyName *propertyName_; }
73 %union { CYRubyProc *rubyProc_; }
74 %union { CYSpan *span_; }
75 %union { CYStatement *statement_; }
76 %union { CYString *string_; }
77 %union { CYTarget *target_; }
78 %union { CYThis *this_; }
79 %union { CYTrue *true_; }
80 %union { CYWord *word_; }
83 %union { CYTypeModifier *modifier_; }
84 %union { CYTypeSpecifier *specifier_; }
85 %union { CYTypedIdentifier *typedIdentifier_; }
86 %union { CYTypedParameter *typedParameter_; }
90 %union { CYMessage *message_; }
91 %union { CYMessageParameter *messageParameter_; }
92 %union { CYImplementationField *implementationField_; }
93 %union { CYProtocol *protocol_; }
94 %union { CYSelectorPart *selector_; }
98 %union { CYAttribute *attribute_; }
99 %union { CYPropertyIdentifier *propertyIdentifier_; }
100 %union { CYSelector *selector_; }
106 cy::parser::semantic_type semantic_;
107 hi::Value highlight_;
110 int cylex(YYSTYPE *, CYLocation *, void *);
118 typedef cy::parser::token tk;
120 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
121 driver.newline_ = false;
124 int token(cylex(&data, location, driver.scanner_));
125 *semantic = data.semantic_;
129 case tk::OpenBracket:
131 driver.in_.push(false);
135 if (driver.in_.top())
140 case tk::CloseBracket:
147 if (driver.yield_.top())
148 token = tk::_yield__;
152 driver.newline_ = true;
160 #define yylex_(semantic, location, driver) ({ \
162 if (driver.hold_ == cy::parser::empty_symbol) \
163 type = yytranslate_(cylex_(semantic, location, driver)); \
165 type = driver.hold_; \
166 driver.hold_ = cy::parser::empty_symbol; \
170 #define CYLEX() do if (yyla.empty()) { \
171 YYCDEBUG << "Mapping a token: "; \
172 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
173 YY_SYMBOL_PRINT("Next token is", yyla); \
176 #define CYMAP(to, from) do { \
178 if (yyla.type == yytranslate_(token::from)) \
179 yyla.type = yytranslate_(token::to); \
182 #define CYERR(location, message) do { \
183 error(location, message); \
187 #define CYEOK() do { \
189 driver.errors_.pop_back(); \
192 #define CYNOT(location) \
193 CYERR(location, "unimplemented feature")
195 #define CYMPT(location) do { \
196 if (!yyla.empty() && yyla.type_get() != yyeof_) \
197 CYERR(location, "unexpected lookahead"); \
207 @$.begin.filename = @$.end.filename = &driver.filename_;
209 switch (driver.mark_) {
211 driver.hold_ = yytranslate_(token::MarkScript);
214 driver.hold_ = yytranslate_(token::MarkModule);
222 %define api.location.type { CYLocation }
229 %param { CYDriver &driver }
231 /* Token Declarations {{{ */
237 %token XMLAttributeValue
239 %token XMLTagCharacters
245 %token LeftRight "<>"
246 %token LeftSlashRight "</>"
248 %token SlashRight "/>"
249 %token LeftSlash "</"
251 %token ColonColon "::"
252 %token PeriodPeriod ".."
255 @begin E4X ObjectiveC
261 %token AmpersandAmpersand "&&"
262 %token AmpersandEqual "&="
264 %token CarrotEqual "^="
266 %token EqualEqual "=="
267 %token EqualEqualEqual "==="
268 %token EqualRight "=>"
269 %token Exclamation "!"
270 %token ExclamationEqual "!="
271 %token ExclamationEqualEqual "!=="
273 %token HyphenEqual "-="
274 %token HyphenHyphen "--"
275 %token HyphenRight "->"
277 %token LeftEqual "<="
279 %token LeftLeftEqual "<<="
281 %token PercentEqual "%="
283 %token PeriodPeriodPeriod "..."
285 %token PipeEqual "|="
288 %token PlusEqual "+="
291 %token RightEqual ">="
292 %token RightRight ">>"
293 %token RightRightEqual ">>="
294 %token RightRightRight ">>>"
295 %token RightRightRightEqual ">>>="
297 %token SlashEqual "/="
299 %token StarEqual "*="
312 %token CloseParen ")"
315 %token OpenBrace_ ";{"
316 %token OpenBrace_let "let {"
317 %token CloseBrace "}"
319 %token OpenBracket "["
320 %token OpenBracket_let "let ["
321 %token CloseBracket "]"
323 %token At_error_ "@error"
326 %token At_class_ "@class"
330 %token _typedef_ "typedef"
331 %token _unsigned_ "unsigned"
332 %token _signed_ "signed"
333 %token _extern_ "extern"
337 %token At_encode_ "@encode"
341 %token At_implementation_ "@implementation"
342 %token At_import_ "@import"
343 %token At_end_ "@end"
344 %token At_selector_ "@selector"
345 %token At_null_ "@null"
346 %token At_YES_ "@YES"
348 %token At_true_ "@true"
349 %token At_false_ "@false"
354 %token _false_ "false"
358 %token _break_ "break"
360 %token _catch_ "catch"
361 %token _class_ "class"
362 %token _class__ ";class"
363 %token _const_ "const"
364 %token _continue_ "continue"
365 %token _debugger_ "debugger"
366 %token _default_ "default"
367 %token _delete_ "delete"
371 %token _export_ "export"
372 %token _extends_ "extends"
373 %token _finally_ "finally"
375 %token _function_ "function"
376 %token _function__ ";function"
378 %token _import_ "import"
381 %token _Infinity_ "Infinity"
382 %token _instanceof_ "instanceof"
384 %token _return_ "return"
385 %token _super_ "super"
386 %token _switch_ "switch"
387 %token _target_ "target"
389 %token _throw_ "throw"
391 %token _typeof_ "typeof"
394 %token _while_ "while"
397 %token _abstract_ "abstract"
398 %token _await_ "await"
399 %token _boolean_ "boolean"
402 %token _constructor_ "constructor"
403 %token _double_ "double"
405 %token _final_ "final"
406 %token _float_ "float"
410 %token _implements_ "implements"
412 %token _interface_ "interface"
416 %token _native_ "native"
417 %token _package_ "package"
418 %token _private_ "private"
419 %token _protected_ "protected"
420 %token _prototype_ "prototype"
421 %token _public_ "public"
423 %token _short_ "short"
424 %token _static_ "static"
425 %token _synchronized_ "synchronized"
426 %token _throws_ "throws"
427 %token _transient_ "transient"
428 %token _volatile_ "volatile"
429 %token _yield_ "yield"
430 %token _yield__ "!yield"
432 %token _undefined_ "undefined"
448 %token _namespace_ "namespace"
453 %token YieldStar "yield *"
455 %token <identifier_> Identifier_
456 %token <number_> NumericLiteral
457 %token <string_> StringLiteral
458 %token <literal_> RegularExpressionLiteral_
460 %token <string_> NoSubstitutionTemplate
461 %token <string_> TemplateHead
462 %token <string_> TemplateMiddle
463 %token <string_> TemplateTail
465 %type <target_> AccessExpression
466 %type <expression_> AdditiveExpression
467 %type <argument_> ArgumentList_
468 %type <argument_> ArgumentList
469 %type <argument_> ArgumentListOpt
470 %type <argument_> Arguments
471 %type <target_> ArrayComprehension
472 %type <literal_> ArrayLiteral
473 %type <expression_> ArrowFunction
474 %type <functionParameter_> ArrowParameters
475 %type <expression_> AssignmentExpression
476 %type <expression_> AssignmentExpressionOpt
477 %type <identifier_> BindingIdentifier
478 %type <identifier_> BindingIdentifierOpt
479 %type <bindings_> BindingList_
480 %type <bindings_> BindingList
481 %type <expression_> BitwiseANDExpression
482 %type <statement_> Block
483 %type <statement_> BlockStatement
484 %type <boolean_> BooleanLiteral
485 %type <binding_> BindingElement
486 %type <expression_> BitwiseORExpression
487 %type <expression_> BitwiseXORExpression
488 %type <statement_> BreakStatement
489 %type <statement_> BreakableStatement
490 %type <expression_> CallExpression_
491 %type <target_> CallExpression
492 %type <clause_> CaseBlock
493 %type <clause_> CaseClause
494 %type <clause_> CaseClausesOpt
496 %type <identifier_> CatchParameter
497 %type <statement_> ClassDeclaration
498 %type <target_> ClassExpression
499 %type <classTail_> ClassHeritage
500 %type <classTail_> ClassHeritageOpt
501 %type <classTail_> ClassTail
502 %type <target_> Comprehension
503 %type <comprehension_> ComprehensionFor
504 %type <comprehension_> ComprehensionIf
505 %type <comprehension_> ComprehensionTail
506 %type <propertyName_> ComputedPropertyName
507 %type <expression_> ConditionalExpression
508 %type <statement_> ContinueStatement
509 %type <statement_> ConciseBody
510 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
511 %type <statement_> DebuggerStatement
512 %type <statement_> Declaration_
513 %type <statement_> Declaration
514 %type <clause_> DefaultClause
515 %type <element_> ElementList
516 %type <element_> ElementListOpt
517 %type <statement_> ElseStatementOpt
518 %type <for_> EmptyStatement
519 %type <expression_> EqualityExpression
520 %type <expression_> Expression
521 %type <expression_> ExpressionOpt
522 %type <for_> ExpressionStatement_
523 %type <statement_> ExpressionStatement
524 %type <finally_> Finally
525 %type <binding_> ForBinding
526 %type <forin_> ForDeclaration
527 %type <forin_> ForInStatementInitializer
528 %type <for_> ForStatementInitializer
529 %type <binding_> FormalParameter
530 %type <functionParameter_> FormalParameterList_
531 %type <functionParameter_> FormalParameterList
532 %type <functionParameter_> FormalParameters
533 %type <statement_> FunctionBody
534 %type <statement_> FunctionDeclaration
535 %type <target_> FunctionExpression
536 %type <statement_> FunctionStatementList
537 %type <statement_> GeneratorBody
538 %type <statement_> GeneratorDeclaration
539 %type <target_> GeneratorExpression
540 %type <method_> GeneratorMethod
541 %type <statement_> HoistableDeclaration
542 %type <identifier_> Identifier
543 %type <identifier_> IdentifierNoOf
544 %type <identifier_> IdentifierType
545 %type <identifier_> IdentifierTypeNoOf
546 %type <word_> IdentifierName
547 %type <variable_> IdentifierReference
548 %type <statement_> IfStatement
549 %type <target_> IndirectExpression
550 %type <expression_> Initializer
551 %type <expression_> InitializerOpt
552 %type <statement_> IterationStatement
553 %type <identifier_> LabelIdentifier
554 %type <statement_> LabelledItem
555 %type <statement_> LabelledStatement
556 %type <assignment_> LeftHandSideAssignment
557 %type <target_> LeftHandSideExpression
558 %type <bool_> LetOrConst
559 %type <binding_> LexicalBinding
560 %type <for_> LexicalDeclaration_
561 %type <statement_> LexicalDeclaration
562 %type <literal_> Literal
563 %type <propertyName_> LiteralPropertyName
564 %type <expression_> LogicalANDExpression
565 %type <expression_> LogicalORExpression
566 %type <access_> MemberAccess
567 %type <target_> MemberExpression
568 %type <method_> MethodDefinition
569 %type <module_> ModulePath
570 %type <expression_> MultiplicativeExpression
571 %type <target_> NewExpression
572 %type <null_> NullLiteral
573 %type <literal_> ObjectLiteral
574 %type <expression_> PostfixExpression
575 %type <target_> PrimaryExpression
576 %type <propertyName_> PropertyName
577 %type <property_> PropertyDefinition
578 %type <property_> PropertyDefinitionList_
579 %type <property_> PropertyDefinitionList
580 %type <property_> PropertyDefinitionListOpt
581 %type <functionParameter_> PropertySetParameterList
582 %type <literal_> RegularExpressionLiteral
583 %type <bool_> RegularExpressionSlash
584 %type <expression_> RelationalExpression
585 %type <statement_> ReturnStatement
586 %type <rubyProc_> RubyProcExpression
587 %type <functionParameter_> RubyProcParameterList_
588 %type <functionParameter_> RubyProcParameterList
589 %type <functionParameter_> RubyProcParameters
590 %type <functionParameter_> RubyProcParametersOpt
591 %type <statement_> Script
592 %type <statement_> ScriptBody
593 %type <statement_> ScriptBodyOpt
594 %type <expression_> ShiftExpression
595 %type <binding_> SingleNameBinding
596 %type <statement_> Statement__
597 %type <statement_> Statement_
598 %type <statement_> Statement
599 %type <statement_> StatementList
600 %type <statement_> StatementListOpt
601 %type <statement_> StatementListItem
602 %type <functionParameter_> StrictFormalParameters
603 %type <target_> SuperCall
604 %type <target_> SuperProperty
605 %type <statement_> SwitchStatement
606 %type <target_> TemplateLiteral
607 %type <span_> TemplateSpans
608 %type <statement_> ThrowStatement
609 %type <statement_> TryStatement
610 %type <expression_> UnaryExpression_
611 %type <expression_> UnaryExpression
612 %type <binding_> VariableDeclaration
613 %type <bindings_> VariableDeclarationList_
614 %type <bindings_> VariableDeclarationList
615 %type <for_> VariableStatement_
616 %type <statement_> VariableStatement
617 %type <statement_> WithStatement
620 %type <word_> WordOpt
622 %type <expression_> YieldExpression
625 %type <specifier_> IntegerType
626 %type <specifier_> IntegerTypeOpt
627 %type <typedIdentifier_> PrefixedType
628 %type <specifier_> PrimitiveType
629 %type <typedIdentifier_> SuffixedType
630 %type <typedIdentifier_> TypeSignifier
631 %type <modifier_> TypeQualifierLeft
632 %type <typedIdentifier_> TypeQualifierRight
633 %type <typedIdentifier_> TypedIdentifierMaybe
634 %type <typedIdentifier_> TypedIdentifierNo
635 %type <typedIdentifier_> TypedIdentifierYes
636 %type <typedParameter_> TypedParameterList_
637 %type <typedParameter_> TypedParameterList
638 %type <typedParameter_> TypedParameterListOpt
642 %type <expression_> AssignmentExpressionClassic
643 %type <expression_> BoxableExpression
644 %type <statement_> CategoryStatement
645 %type <expression_> ClassSuperOpt
646 %type <expression_> ConditionalExpressionClassic
647 %type <implementationField_> ImplementationFieldListOpt
648 %type <implementationField_> ImplementationFields
649 %type <message_> ClassMessageDeclaration
650 %type <message_> ClassMessageDeclarationListOpt
651 %type <protocol_> ClassProtocolListOpt
652 %type <protocol_> ClassProtocols
653 %type <protocol_> ClassProtocolsOpt
654 %type <statement_> ImplementationStatement
655 %type <target_> MessageExpression
656 %type <messageParameter_> MessageParameter
657 %type <messageParameter_> MessageParameters
658 %type <messageParameter_> MessageParameterList
659 %type <messageParameter_> MessageParameterListOpt
660 %type <bool_> MessageScope
661 %type <argument_> SelectorCall_
662 %type <argument_> SelectorCall
663 %type <selector_> SelectorExpression_
664 %type <selector_> SelectorExpression
665 %type <selector_> SelectorExpressionOpt
666 %type <argument_> SelectorList
667 %type <word_> SelectorWordOpt
668 %type <typedIdentifier_> TypeOpt
669 %type <argument_> VariadicCall
673 %type <propertyIdentifier_> PropertyIdentifier_
674 %type <selector_> PropertySelector_
675 %type <selector_> PropertySelector
676 %type <identifier_> QualifiedIdentifier_
677 %type <identifier_> QualifiedIdentifier
678 %type <identifier_> WildcardIdentifier
679 %type <identifier_> XMLComment
680 %type <identifier_> XMLCDATA
681 %type <identifier_> XMLElement
682 %type <identifier_> XMLElementContent
683 %type <identifier_> XMLMarkup
684 %type <identifier_> XMLPI
686 %type <attribute_> AttributeIdentifier
687 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
688 %type <expression_> PropertyIdentifier
689 %type <expression_> XMLListInitilizer
690 %type <expression_> XMLInitilizer
693 /* Token Priorities {{{ */
709 /* Lexer State {{{ */
710 LexPushInOn: { driver.in_.push(true); };
711 LexPushInOff: { driver.in_.push(false); };
712 LexPopIn: { driver.in_.pop(); };
714 LexPushReturnOn: { driver.return_.push(true); };
715 LexPopReturn: { driver.return_.pop(); };
717 LexPushSuperOn: { driver.super_.push(true); };
718 LexPushSuperOff: { driver.super_.push(false); };
719 LexPopSuper: { driver.super_.pop(); };
721 LexPushYieldOn: { driver.yield_.push(true); };
722 LexPushYieldOff: { driver.yield_.push(false); };
723 LexPopYield: { driver.yield_.pop(); };
726 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
730 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
734 : { CYMAP(YieldStar, Star); }
738 : { CYMAP(OpenBrace_, OpenBrace); }
742 : { CYMAP(_class__, _class_); }
746 : { CYMAP(_function__, _function_); }
750 : LexNoBrace LexNoClass LexNoFunction
753 /* Virtual Tokens {{{ */
759 /* 11.6 Names and Keywords {{{ */
761 : Word[pass] { $$ = $pass; }
762 | "for" { $$ = CYNew CYWord("for"); }
763 | "in" { $$ = CYNew CYWord("in"); }
764 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
768 : IdentifierNoOf[pass] { $$ = $pass; }
769 | "break" { $$ = CYNew CYWord("break"); }
770 | "case" { $$ = CYNew CYWord("case"); }
771 | "catch" { $$ = CYNew CYWord("catch"); }
772 | "class" LexOf { $$ = CYNew CYWord("class"); }
773 | ";class" { $$ = CYNew CYWord("class"); }
774 | "const" { $$ = CYNew CYWord("const"); }
775 | "continue" { $$ = CYNew CYWord("continue"); }
776 | "debugger" { $$ = CYNew CYWord("debugger"); }
777 | "default" { $$ = CYNew CYWord("default"); }
778 | "delete" { $$ = CYNew CYWord("delete"); }
779 | "do" { $$ = CYNew CYWord("do"); }
780 | "else" { $$ = CYNew CYWord("else"); }
781 | "enum" { $$ = CYNew CYWord("enum"); }
782 | "export" { $$ = CYNew CYWord("export"); }
783 | "extends" { $$ = CYNew CYWord("extends"); }
784 | "false" { $$ = CYNew CYWord("false"); }
785 | "finally" { $$ = CYNew CYWord("finally"); }
786 | "function" LexOf { $$ = CYNew CYWord("function"); }
787 | "if" { $$ = CYNew CYWord("if"); }
788 | "import" { $$ = CYNew CYWord("import"); }
789 | "!in" { $$ = CYNew CYWord("in"); }
790 | "!of" { $$ = CYNew CYWord("of"); }
791 | "new" { $$ = CYNew CYWord("new"); }
792 | "null" { $$ = CYNew CYWord("null"); }
793 | "return" { $$ = CYNew CYWord("return"); }
794 | "super" { $$ = CYNew CYWord("super"); }
795 | "switch" { $$ = CYNew CYWord("switch"); }
796 | "this" { $$ = CYNew CYWord("this"); }
797 | "throw" { $$ = CYNew CYWord("throw"); }
798 | "true" { $$ = CYNew CYWord("true"); }
799 | "try" { $$ = CYNew CYWord("try"); }
800 | "typeof" { $$ = CYNew CYWord("typeof"); }
801 | "var" { $$ = CYNew CYWord("var"); }
802 | "void" { $$ = CYNew CYWord("void"); }
803 | "while" { $$ = CYNew CYWord("while"); }
804 | "with" { $$ = CYNew CYWord("with"); }
805 | "yield" { $$ = CYNew CYIdentifier("yield"); }
810 : Word[pass] { $$ = $pass; }
815 /* 11.8.1 Null Literals {{{ */
817 : "null" { $$ = CYNew CYNull(); }
820 /* 11.8.2 Boolean Literals {{{ */
822 : "true" { $$ = CYNew CYTrue(); }
823 | "false" { $$ = CYNew CYFalse(); }
826 /* 11.8.5 Regular Expression Literals {{{ */
827 RegularExpressionSlash
828 : "/" { $$ = false; }
829 | "/=" { $$ = true; }
832 RegularExpressionLiteral
833 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
837 /* 11.9 Automatic Semicolon Insertion {{{ */
839 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
847 : LexNewLineOrNot "\n"
852 : LexNewLineOrNot "\n" StrictSemi
853 | NewLineNot LexOf Terminator
858 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
863 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
867 /* 12.1 Identifiers {{{ */
869 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
870 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
874 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
875 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
876 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
880 : BindingIdentifier[pass] { $$ = $pass; }
881 | LexOf { $$ = NULL; }
885 : Identifier[pass] { $$ = $pass; }
886 | "yield" { $$ = CYNew CYIdentifier("yield"); }
890 : Identifier_[pass] { $$ = $pass; }
891 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
892 | "await" { $$ = CYNew CYIdentifier("await"); }
893 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
894 | "byte" { $$ = CYNew CYIdentifier("byte"); }
895 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
896 | "double" { $$ = CYNew CYIdentifier("double"); }
897 | "each" { $$ = CYNew CYIdentifier("each"); }
898 | "eval" { $$ = CYNew CYIdentifier("eval"); }
899 | "final" { $$ = CYNew CYIdentifier("final"); }
900 | "float" { $$ = CYNew CYIdentifier("float"); }
901 | "from" { $$ = CYNew CYIdentifier("from"); }
902 | "get" { $$ = CYNew CYIdentifier("get"); }
903 | "goto" { $$ = CYNew CYIdentifier("goto"); }
904 | "implements" { $$ = CYNew CYIdentifier("implements"); }
905 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
906 | "interface" { $$ = CYNew CYIdentifier("interface"); }
907 | "let" { $$ = CYNew CYIdentifier("let"); }
908 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
909 | "native" { $$ = CYNew CYIdentifier("native"); }
910 | "package" { $$ = CYNew CYIdentifier("package"); }
911 | "private" { $$ = CYNew CYIdentifier("private"); }
912 | "protected" { $$ = CYNew CYIdentifier("protected"); }
913 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
914 | "public" { $$ = CYNew CYIdentifier("public"); }
915 | "set" { $$ = CYNew CYIdentifier("set"); }
916 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
917 | "target" { $$ = CYNew CYIdentifier("target"); }
918 | "throws" { $$ = CYNew CYIdentifier("throws"); }
919 | "transient" { $$ = CYNew CYIdentifier("transient"); }
920 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
922 | "bool" { $$ = CYNew CYIdentifier("bool"); }
923 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
924 | "id" { $$ = CYNew CYIdentifier("id"); }
925 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
930 : IdentifierTypeNoOf[pass] { $$ = $pass; }
931 | "of" { $$ = CYNew CYIdentifier("of"); }
936 | "char" { $$ = CYNew CYIdentifier("char"); }
937 | "int" { $$ = CYNew CYIdentifier("int"); }
938 | "long" { $$ = CYNew CYIdentifier("long"); }
939 | "short" { $$ = CYNew CYIdentifier("short"); }
940 | "static" { $$ = CYNew CYIdentifier("static"); }
941 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
943 | "signed" { $$ = CYNew CYIdentifier("signed"); }
944 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
947 | "nil" { $$ = CYNew CYIdentifier("nil"); }
948 | "NO" { $$ = CYNew CYIdentifier("NO"); }
949 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
950 | "YES" { $$ = CYNew CYIdentifier("YES"); }
955 : IdentifierNoOf[pass] { $$ = $pass; }
956 | "of" { $$ = CYNew CYIdentifier("of"); }
957 | "!of" { $$ = CYNew CYIdentifier("of"); }
960 /* 12.2 Primary Expression {{{ */
962 : "this" { $$ = CYNew CYThis(); }
963 | IdentifierReference[pass] { $$ = $pass; }
964 | Literal[pass] { $$ = $pass; }
965 | ArrayLiteral[pass] { $$ = $pass; }
966 | ObjectLiteral[pass] { $$ = $pass; }
967 | FunctionExpression[pass] { $$ = $pass; }
968 | ClassExpression[pass] { $$ = $pass; }
969 | GeneratorExpression[pass] { $$ = $pass; }
970 | RegularExpressionLiteral[pass] { $$ = $pass; }
971 | TemplateLiteral[pass] { $$ = $pass; }
972 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
973 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
976 CoverParenthesizedExpressionAndArrowParameterList
977 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
978 | "(" LexOf ")" { $$ = NULL; }
979 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
980 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
983 /* 12.2.4 Literals {{{ */
985 : NullLiteral[pass] { $$ = $pass; }
986 | BooleanLiteral[pass] { $$ = $pass; }
987 | NumericLiteral[pass] { $$ = $pass; }
988 | StringLiteral[pass] { $$ = $pass; }
991 /* 12.2.5 Array Initializer {{{ */
993 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
997 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
998 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
999 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1003 : ElementList[pass] { $$ = $pass; }
1004 | LexOf { $$ = NULL; }
1007 /* 12.2.6 Object Initializer {{{ */
1009 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1012 PropertyDefinitionList_
1013 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1017 PropertyDefinitionList
1018 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1021 PropertyDefinitionListOpt
1022 : PropertyDefinitionList[properties] { $$ = $properties; }
1027 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1028 | CoverInitializedName[name] { CYNOT(@$); }
1029 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1030 | MethodDefinition[pass] { $$ = $pass; }
1034 : LiteralPropertyName[pass] { $$ = $pass; }
1035 | ComputedPropertyName[pass] { $$ = $pass; }
1039 : IdentifierName[pass] { $$ = $pass; }
1040 | StringLiteral[pass] { $$ = $pass; }
1041 | NumericLiteral[pass] { $$ = $pass; }
1044 ComputedPropertyName
1045 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1048 CoverInitializedName
1049 : IdentifierReference Initializer
1053 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1057 : Initializer[pass] { $$ = $pass; }
1061 /* 12.2.9 Template Literals {{{ */
1063 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1064 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1068 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1069 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1073 /* 12.3 Left-Hand-Side Expressions {{{ */
1075 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1076 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1077 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1078 | TemplateLiteral { CYNOT(@$); }
1082 : PrimaryExpression[pass] { $$ = $pass; }
1083 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1084 | SuperProperty[pass] { $$ = $pass; }
1085 | MetaProperty { CYNOT(@$); }
1086 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1090 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1091 | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1099 : "new" "." "target"
1103 : MemberExpression[pass] { $$ = $pass; }
1104 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1108 : MemberExpression[pass] { $$ = $pass; }
1109 | CallExpression[pass] { $$ = $pass; }
1113 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1114 | SuperCall[pass] { $$ = $pass; }
1115 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1119 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1123 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1127 : "," ArgumentList[arguments] { $$ = $arguments; }
1132 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1133 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1137 : ArgumentList[pass] { $$ = $pass; }
1138 | LexOf { $$ = NULL; }
1142 : NewExpression[pass] { $$ = $pass; }
1143 | CallExpression[pass] { $$ = $pass; }
1146 LeftHandSideExpression
1147 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
1148 | IndirectExpression[pass] { $$ = $pass; }
1151 /* 12.4 Postfix Expressions {{{ */
1153 : AccessExpression[lhs] LexNewLineOrOpt { $$ = $lhs; }
1154 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1155 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1158 /* 12.5 Unary Operators {{{ */
1160 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1161 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1162 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1163 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1164 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1165 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1166 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1167 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1168 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1172 : PostfixExpression[expression] { $$ = $expression; }
1173 | PostfixExpression[expression] "\n" { $$ = $expression; }
1174 | UnaryExpression_[pass] { $$ = $pass; }
1177 /* 12.6 Multiplicative Operators {{{ */
1178 MultiplicativeExpression
1179 : UnaryExpression[pass] { $$ = $pass; }
1180 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1181 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1182 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1185 /* 12.7 Additive Operators {{{ */
1187 : MultiplicativeExpression[pass] { $$ = $pass; }
1188 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1189 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1192 /* 12.8 Bitwise Shift Operators {{{ */
1194 : AdditiveExpression[pass] { $$ = $pass; }
1195 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1196 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1197 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1200 /* 12.9 Relational Operators {{{ */
1201 RelationalExpression
1202 : ShiftExpression[pass] { $$ = $pass; }
1203 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1204 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1205 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1206 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1207 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1208 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1211 /* 12.10 Equality Operators {{{ */
1213 : RelationalExpression[pass] { $$ = $pass; }
1214 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1215 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1216 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1217 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1220 /* 12.11 Binary Bitwise Operators {{{ */
1221 BitwiseANDExpression
1222 : EqualityExpression[pass] { $$ = $pass; }
1223 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1226 BitwiseXORExpression
1227 : BitwiseANDExpression[pass] { $$ = $pass; }
1228 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1232 : BitwiseXORExpression[pass] { $$ = $pass; }
1233 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1236 /* 12.12 Binary Logical Operators {{{ */
1237 LogicalANDExpression
1238 : BitwiseORExpression[pass] { $$ = $pass; }
1239 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1243 : LogicalANDExpression[pass] { $$ = $pass; }
1244 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1247 /* 12.13 Conditional Operator ( ? : ) {{{ */
1249 ConditionalExpressionClassic
1250 : LogicalORExpression[pass] { $$ = $pass; }
1251 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1255 ConditionalExpression
1256 : LogicalORExpression[pass] { $$ = $pass; }
1257 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1260 /* 12.14 Assignment Operators {{{ */
1261 LeftHandSideAssignment
1262 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1263 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1264 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1265 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1266 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1267 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1268 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1269 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1270 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1271 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1272 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1273 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1277 AssignmentExpressionClassic
1278 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1279 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1283 AssignmentExpression
1284 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1285 | LexOf YieldExpression[pass] { $$ = $pass; }
1286 | ArrowFunction[pass] { $$ = $pass; }
1287 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1290 AssignmentExpressionOpt
1291 : AssignmentExpression[pass] { $$ = $pass; }
1292 | LexOf { $$ = NULL; }
1295 /* 12.15 Comma Operator ( , ) {{{ */
1297 : AssignmentExpression[pass] { $$ = $pass; }
1298 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1302 : Expression[pass] { $$ = $pass; }
1303 | LexOf { $$ = NULL; }
1307 /* 13 Statements and Declarations {{{ */
1309 : BlockStatement[pass] { $$ = $pass; }
1310 | VariableStatement[pass] { $$ = $pass; }
1311 | EmptyStatement[pass] { $$ = $pass; }
1312 | IfStatement[pass] { $$ = $pass; }
1313 | BreakableStatement[pass] { $$ = $pass; }
1314 | ContinueStatement[pass] { $$ = $pass; }
1315 | BreakStatement[pass] { $$ = $pass; }
1316 | ReturnStatement[pass] { $$ = $pass; }
1317 | WithStatement[pass] { $$ = $pass; }
1318 | LabelledStatement[pass] { $$ = $pass; }
1319 | ThrowStatement[pass] { $$ = $pass; }
1320 | TryStatement[pass] { $$ = $pass; }
1321 | DebuggerStatement[pass] { $$ = $pass; }
1325 : LexOf Statement__[pass] { $$ = $pass; }
1326 | ExpressionStatement[pass] { $$ = $pass; }
1330 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1334 : HoistableDeclaration[pass] { $$ = $pass; }
1335 | ClassDeclaration[pass] { $$ = $pass; }
1339 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1340 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1343 HoistableDeclaration
1344 : FunctionDeclaration[pass] { $$ = $pass; }
1345 | GeneratorDeclaration[pass] { $$ = $pass; }
1349 : IterationStatement[pass] { $$ = $pass; }
1350 | SwitchStatement[pass] { $$ = $pass; }
1353 /* 13.2 Block {{{ */
1355 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1359 : "{" StatementListOpt[code] "}" { $$ = $code; }
1363 : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
1367 : StatementList[pass] { $$ = $pass; }
1368 | LexSetStatement LexLet LexOf { $$ = NULL; }
1372 : Statement[pass] { $$ = $pass; }
1373 | Declaration[pass] { $$ = $pass; }
1376 /* 13.3 Let and Const Declarations {{{ */
1378 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1382 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1386 : { CYMAP(_let__, _let_); }
1390 : { CYMAP(_of__, _of_); }
1394 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1398 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1399 | LexLet LexOf "const" { $$ = true; }
1403 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1408 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1412 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1413 | LexOf BindingPattern Initializer { CYNOT(@$); }
1416 /* 13.3.2 Variable Statement {{{ */
1418 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1422 : VariableStatement_[statement] Terminator { $$ = $statement; }
1425 VariableDeclarationList_
1426 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1430 VariableDeclarationList
1431 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1435 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1436 | LexOf BindingPattern Initializer { CYNOT(@$); }
1439 /* 13.3.3 Destructuring Binding Patterns {{{ */
1441 : ObjectBindingPattern
1442 | ArrayBindingPattern
1445 ObjectBindingPattern
1446 : "let {" BindingPropertyListOpt "}"
1450 : "let [" BindingElementListOpt "]"
1453 BindingPropertyList_
1454 : "," BindingPropertyListOpt
1459 : BindingProperty BindingPropertyList_
1462 BindingPropertyListOpt
1463 : BindingPropertyList
1468 : BindingElementOpt[element] "," BindingElementListOpt[next]
1469 | BindingRestElement[element]
1470 | BindingElement[element]
1473 BindingElementListOpt
1474 : BindingElementList[pass]
1480 | LexOf PropertyName ":" BindingElement
1484 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1485 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1489 : BindingElement[pass]
1494 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1498 : LexBind LexOf "..." BindingIdentifier
1501 /* 13.4 Empty Statement {{{ */
1503 : ";" { $$ = CYNew CYEmpty(); }
1506 /* 13.5 Expression Statement {{{ */
1507 ExpressionStatement_
1508 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1511 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1514 /* 13.6 The if Statement {{{ */
1516 : "else" Statement[false] { $$ = $false; }
1517 | %prec "if" { $$ = NULL; }
1521 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1524 /* 13.7 Iteration Statements {{{ */
1526 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1527 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1528 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1529 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1530 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1531 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1534 ForStatementInitializer
1535 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1536 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1537 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1538 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1541 ForInStatementInitializer
1542 : LexLet LexOf AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
1543 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1544 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1545 | ForDeclaration[pass] { $$ = $pass; }
1549 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1553 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1554 | LexOf BindingPattern { CYNOT(@$); }
1557 /* 13.8 The continue Statement {{{ */
1559 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1560 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1563 /* 13.9 The break Statement {{{ */
1565 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1566 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1569 /* 13.10 The return Statement {{{ */
1571 : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
1575 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1576 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1579 /* 13.11 The with Statement {{{ */
1581 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1584 /* 13.12 The switch Statement {{{ */
1586 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1590 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1594 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1598 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1599 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1603 // XXX: the standard makes certain you can only have one of these
1605 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1608 /* 13.13 Labelled Statements {{{ */
1610 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1614 : Statement[pass] { $$ = $pass; }
1615 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1618 /* 13.14 The throw Statement {{{ */
1620 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1621 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1624 /* 13.15 The try Statement {{{ */
1626 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1627 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1628 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1632 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1636 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1640 : BindingIdentifier[pass] { $$ = $pass; }
1641 | LexOf BindingPattern { CYNOT(@$); }
1644 /* 13.16 The debugger Statement {{{ */
1646 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1650 /* 14.1 Function Definitions {{{ */
1652 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1656 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1659 StrictFormalParameters
1660 : FormalParameters[pass] { $$ = $pass; }
1664 : LexBind LexOf { $$ = NULL; }
1665 | FormalParameterList
1668 FormalParameterList_
1669 : "," FormalParameterList[parameters] { $$ = $parameters; }
1674 : FunctionRestParameter { CYNOT(@$); }
1675 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1678 FunctionRestParameter
1679 : BindingRestElement
1683 : BindingElement[pass] { $$ = $pass; }
1687 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1690 FunctionStatementList
1691 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1694 /* 14.2 Arrow Function Definitions {{{ */
1696 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1700 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1701 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1705 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1706 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1709 /* 14.3 Method Definitions {{{ */
1711 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1712 | GeneratorMethod[pass] { $$ = $pass; }
1713 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1714 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1717 PropertySetParameterList
1718 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1721 /* 14.4 Generator Function Definitions {{{ */
1723 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1726 GeneratorDeclaration
1727 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1731 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1735 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1739 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1740 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1741 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1742 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1745 /* 14.5 Class Definitions {{{ */
1747 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1751 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1755 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1759 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1763 : ClassHeritage[pass] { $$ = $pass; }
1764 | { $$ = CYNew CYClassTail(NULL); }
1777 : ClassElementListOpt ClassElement
1786 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1787 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1792 /* 15.1 Scripts {{{ */
1794 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1798 : StatementList[pass] { $$ = $pass; }
1802 : ScriptBody[pass] { $$ = $pass; }
1803 | LexSetStatement LexLet LexOf { $$ = NULL; }
1806 /* 15.2 Modules {{{ */
1821 : ModuleItemListOpt ModuleItem
1830 : LexSetStatement LexLet LexOf ImportDeclaration
1831 | LexSetStatement LexLet LexOf ExportDeclaration
1835 /* 15.2.2 Imports {{{ */
1837 : "import" ImportClause FromClause Terminator
1838 | "import" LexOf ModuleSpecifier Terminator
1842 : ImportedDefaultBinding
1843 | LexOf NameSpaceImport
1844 | LexOf NamedImports
1845 | ImportedDefaultBinding "," NameSpaceImport
1846 | ImportedDefaultBinding "," NamedImports
1849 ImportedDefaultBinding
1854 : "*" "as" ImportedBinding
1858 : "{" ImportsListOpt "}"
1862 : "from" ModuleSpecifier
1866 : "," ImportsListOpt
1871 : ImportSpecifier ImportsList_
1881 | LexOf IdentifierName "as" ImportedBinding
1892 /* 15.2.3 Exports {{{ */
1894 : "*" FromClause Terminator
1895 | ExportClause FromClause Terminator
1896 | ExportClause Terminator
1898 | "default" LexSetStatement LexOf HoistableDeclaration
1899 | "default" LexSetStatement LexOf ClassDeclaration
1900 | "default" LexSetStatement AssignmentExpression Terminator
1904 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1905 | "export" Declaration
1909 : ";{" ExportsListOpt "}"
1913 : "," ExportsListOpt
1918 : ExportSpecifier ExportsList_
1928 | IdentifierName "as" IdentifierName
1933 /* Cycript (C): Type Encoding {{{ */
1935 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1936 | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; }
1940 : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1941 | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1942 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1943 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1944 | TypeSignifier[pass] { $$ = $pass; }
1945 | { $$ = CYNew CYTypedIdentifier(@$); }
1949 : "*" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1954 | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1955 | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1959 : PrefixedType[pass] { $$ = $pass; }
1960 | SuffixedType[pass] { $$ = $pass; }
1961 | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1962 | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1966 : "int" { $$ = CYNew CYTypeVariable("int"); }
1967 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
1968 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
1969 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
1970 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
1974 : IntegerType[pass] { $$ = $pass; }
1975 | { $$ = CYNew CYTypeVariable("int"); }
1979 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
1980 | IntegerType[pass] { $$ = $pass; }
1981 | "void" { $$ = CYNew CYTypeVoid(); }
1982 | "char" { $$ = CYNew CYTypeVariable("char"); }
1983 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1984 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1987 TypedIdentifierMaybe
1988 : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
1992 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
1996 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2000 : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2006 /* Cycript (Objective-C): @class Declaration {{{ */
2008 /* XXX: why the hell did I choose MemberExpression? */
2009 : ":" MemberExpression[extends] { $$ = $extends; }
2013 ImplementationFieldListOpt
2014 : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2018 ImplementationFields
2019 : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
2023 : "+" { $$ = false; }
2024 | "-" { $$ = true; }
2028 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2029 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2033 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2036 MessageParameterList
2037 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2040 MessageParameterListOpt
2041 : MessageParameterList[pass] { $$ = $pass; }
2046 : MessageParameterList[pass] { $$ = $pass; }
2047 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2050 ClassMessageDeclaration
2051 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2054 ClassMessageDeclarationListOpt
2055 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2059 // XXX: this should be AssignmentExpressionNoRight
2061 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2065 : "," ClassProtocols[protocols] { $$ = $protocols; }
2069 ClassProtocolListOpt
2070 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2074 ImplementationStatement
2075 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2083 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2087 : ImplementationStatement[pass] { $$ = $pass; }
2088 | CategoryStatement[pass] { $$ = $pass; }
2091 /* Cycript (Objective-C): Send Message {{{ */
2093 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2098 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2099 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2103 : SelectorCall[pass] { $$ = $pass; }
2104 | VariadicCall[pass] { $$ = $pass; }
2108 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2112 : SelectorCall[pass] { $$ = $pass; }
2113 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2117 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2118 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2122 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2126 : SelectorExpression_[pass] { $$ = $pass; }
2127 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2130 SelectorExpressionOpt
2131 : SelectorExpression_[pass] { $$ = $pass; }
2136 : MessageExpression[pass] { $$ = $pass; }
2137 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2142 /* Cycript: @import Directive {{{ */
2144 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2145 | Word[part] { $$ = CYNew CYModule($part); }
2149 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2154 /* Cycript (Objective-C): Boxed Expressions {{{ */
2156 : NullLiteral[pass] { $$ = $pass; }
2157 | BooleanLiteral[pass] { $$ = $pass; }
2158 | NumericLiteral[pass] { $$ = $pass; }
2159 | StringLiteral[pass] { $$ = $pass; }
2160 | ArrayLiteral[pass] { $$ = $pass; }
2161 | ObjectLiteral[pass] { $$ = $pass; }
2162 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2163 | "YES" { $$ = CYNew CYTrue(); }
2164 | "NO" { $$ = CYNew CYFalse(); }
2168 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2169 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2170 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2171 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2172 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2173 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2176 /* Cycript (Objective-C): Block Expressions {{{ */
2178 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2181 /* Cycript (Objective-C): Instance Literals {{{ */
2183 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2189 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2191 : IndirectExpression[pass] { $$ = $pass; }
2195 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2199 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2203 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2204 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2205 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2208 /* Cycript (C): Lambda Expressions {{{ */
2210 : "," TypedParameterList[parameters] { $$ = $parameters; }
2215 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2218 TypedParameterListOpt
2219 : TypedParameterList[pass] { $$ = $pass; }
2224 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2227 /* Cycript (C): Type Definitions {{{ */
2229 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2233 : "typedef" NewLineNot TypedIdentifierYes[typed] Terminator { $$ = CYNew CYTypeDefinition($typed); }
2237 : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2240 /* Cycript (C): extern "C" {{{ */
2242 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2246 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifierYes[typed] Terminator { $$ = CYNew CYExternal($abi, $typed); }
2253 /* Lexer State {{{ */
2255 : { driver.PushCondition(CYDriver::RegExpCondition); }
2259 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2263 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2267 : { driver.PopCondition(); }
2271 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2275 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2278 /* Virtual Tokens {{{ */
2285 /* 8.1 Context Keywords {{{ */
2287 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2288 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2291 /* 8.3 XML Initializer Input Elements {{{ */
2293 : XMLComment { $$ = $1; }
2294 | XMLCDATA { $$ = $1; }
2295 | XMLPI { $$ = $1; }
2299 /* 11.1 Primary Expressions {{{ */
2301 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2302 | XMLInitilizer { $$ = $1; }
2303 | XMLListInitilizer { $$ = $1; }
2307 : AttributeIdentifier { $$ = $1; }
2308 | QualifiedIdentifier { $$ = $1; }
2309 | WildcardIdentifier { $$ = $1; }
2312 /* 11.1.1 Attribute Identifiers {{{ */
2314 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2318 : PropertySelector { $$ = $1; }
2319 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2323 : Identifier { $$ = CYNew CYSelector($1); }
2324 | WildcardIdentifier { $$ = $1; }
2327 /* 11.1.2 Qualified Identifiers {{{ */
2328 QualifiedIdentifier_
2329 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2330 | QualifiedIdentifier { $$ = $1; }
2334 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2337 /* 11.1.3 Wildcard Identifiers {{{ */
2339 : "*" { $$ = CYNew CYWildcard(); }
2342 /* 11.1.4 XML Initializer {{{ */
2344 : XMLMarkup { $$ = $1; }
2345 | XMLElement { $$ = $1; }
2349 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2350 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2354 : LexPushXMLTag XMLTagName XMLAttributes
2358 : "{" LexPushRegExp Expression LexPop "}"
2367 : XMLAttributes_ XMLAttribute
2372 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2373 | XMLAttributes_ XMLWhitespaceOpt
2382 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2386 : XMLExpression XMLElementContentOpt
2387 | XMLMarkup XMLElementContentOpt
2388 | XMLText XMLElementContentOpt
2389 | XMLElement XMLElementContentOpt
2392 XMLElementContentOpt
2397 /* 11.1.5 XMLList Initializer {{{ */
2399 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2403 /* 11.2 Left-Hand-Side Expressions {{{ */
2405 : Identifier { $$ = $1; }
2406 | PropertyIdentifier { $$ = $1; }
2410 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2411 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2412 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2415 /* 12.1 The default xml namespace Statement {{{ */
2416 /* XXX: DefaultXMLNamespaceStatement
2417 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2421 : DefaultXMLNamespaceStatement { $$ = $1; }
2426 /* JavaScript FTL: Array Comprehensions {{{ */
2428 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2432 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2435 /* JavaScript FTL: for each {{{ */
2437 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2441 /* JavaScript FTW: Array Comprehensions {{{ */
2443 : ArrayComprehension
2447 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2451 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2456 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2457 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2461 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2462 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2466 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2469 /* JavaScript FTW: Coalesce Operator {{{ */
2470 ConditionalExpression
2471 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2474 /* JavaScript FTW: Named Arguments {{{ */
2476 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2479 /* JavaScript FTW: Ruby Blocks {{{ */
2480 RubyProcParameterList_
2481 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2485 RubyProcParameterList
2486 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2487 | LexOf { $$ = NULL; }
2491 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2492 | "||" { $$ = NULL; }
2495 RubyProcParametersOpt
2496 : RubyProcParameters[pass] { $$ = $pass; }
2501 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2505 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2509 : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2515 bool CYDriver::Parse(CYMark mark) {
2517 CYLocal<CYPool> local(&pool_);
2518 cy::parser parser(*this);
2520 parser.set_debug_level(debug_);
2522 return parser.parse() != 0;
2525 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2529 CYDriver::Error error;
2530 error.warning_ = true;
2531 error.location_ = location;
2532 error.message_ = message;
2533 errors_.push_back(error);
2536 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2537 CYDriver::Error error;
2538 error.warning_ = false;
2539 error.location_ = location;
2540 error.message_ = message;
2541 driver.errors_.push_back(error);