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 { CYImportSpecifier *import_; }
65 %union { CYInfix *infix_; }
66 %union { CYLiteral *literal_; }
67 %union { CYMethod *method_; }
68 %union { CYModule *module_; }
69 %union { CYNull *null_; }
70 %union { CYNumber *number_; }
71 %union { CYParenthetical *parenthetical_; }
72 %union { CYProperty *property_; }
73 %union { CYPropertyName *propertyName_; }
74 %union { CYRubyProc *rubyProc_; }
75 %union { CYSpan *span_; }
76 %union { CYStatement *statement_; }
77 %union { CYString *string_; }
78 %union { CYTarget *target_; }
79 %union { CYThis *this_; }
80 %union { CYTrue *true_; }
81 %union { CYWord *word_; }
84 %union { CYTypeStructField *structField_; }
85 %union { CYTypeModifier *modifier_; }
86 %union { CYTypeSpecifier *specifier_; }
87 %union { CYTypedIdentifier *typedIdentifier_; }
88 %union { CYTypedParameter *typedParameter_; }
92 %union { CYImplementationField *implementationField_; }
93 %union { CYMessage *message_; }
94 %union { CYMessageParameter *messageParameter_; }
95 %union { CYProtocol *protocol_; }
96 %union { CYSelectorPart *selector_; }
100 %union { CYAttribute *attribute_; }
101 %union { CYPropertyIdentifier *propertyIdentifier_; }
102 %union { CYSelector *selector_; }
108 cy::parser::semantic_type semantic_;
109 hi::Value highlight_;
112 int cylex(YYSTYPE *, CYLocation *, void *);
120 typedef cy::parser::token tk;
122 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
123 driver.newline_ = false;
126 int token(cylex(&data, location, driver.scanner_));
127 *semantic = data.semantic_;
131 case tk::OpenBracket:
133 driver.in_.push(false);
137 if (driver.in_.top())
142 case tk::CloseBracket:
149 if (driver.yield_.top())
150 token = tk::_yield__;
154 driver.newline_ = true;
162 #define yylex_(semantic, location, driver) ({ \
164 if (driver.hold_ == cy::parser::empty_symbol) \
165 type = yytranslate_(cylex_(semantic, location, driver)); \
167 type = driver.hold_; \
168 driver.hold_ = cy::parser::empty_symbol; \
172 #define CYLEX() do if (yyla.empty()) { \
173 YYCDEBUG << "Mapping a token: "; \
174 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
175 YY_SYMBOL_PRINT("Next token is", yyla); \
178 #define CYMAP(to, from) do { \
180 if (yyla.type == yytranslate_(token::from)) \
181 yyla.type = yytranslate_(token::to); \
184 #define CYERR(location, message) do { \
185 error(location, message); \
189 #define CYEOK() do { \
191 driver.errors_.pop_back(); \
194 #define CYNOT(location) \
195 CYERR(location, "unimplemented feature")
197 #define CYMPT(location) do { \
198 if (!yyla.empty() && yyla.type_get() != yyeof_) \
199 CYERR(location, "unexpected lookahead"); \
209 @$.begin.filename = @$.end.filename = &driver.filename_;
211 switch (driver.mark_) {
213 driver.hold_ = yytranslate_(token::MarkScript);
216 driver.hold_ = yytranslate_(token::MarkModule);
224 %define api.location.type { CYLocation }
231 %param { CYDriver &driver }
233 /* Token Declarations {{{ */
239 %token XMLAttributeValue
241 %token XMLTagCharacters
247 %token LeftRight "<>"
248 %token LeftSlashRight "</>"
250 %token SlashRight "/>"
251 %token LeftSlash "</"
253 %token ColonColon "::"
254 %token PeriodPeriod ".."
257 @begin E4X ObjectiveC
263 %token AmpersandAmpersand "&&"
264 %token AmpersandEqual "&="
266 %token CarrotEqual "^="
268 %token EqualEqual "=="
269 %token EqualEqualEqual "==="
270 %token EqualRight "=>"
271 %token Exclamation "!"
272 %token ExclamationEqual "!="
273 %token ExclamationEqualEqual "!=="
275 %token HyphenEqual "-="
276 %token HyphenHyphen "--"
277 %token HyphenRight "->"
279 %token LeftEqual "<="
281 %token LeftLeftEqual "<<="
283 %token PercentEqual "%="
285 %token PeriodPeriodPeriod "..."
287 %token PipeEqual "|="
290 %token PlusEqual "+="
293 %token RightEqual ">="
294 %token RightRight ">>"
295 %token RightRightEqual ">>="
296 %token RightRightRight ">>>"
297 %token RightRightRightEqual ">>>="
299 %token SlashEqual "/="
301 %token StarEqual "*="
314 %token CloseParen ")"
317 %token OpenBrace_ ";{"
318 %token OpenBrace_let "let {"
319 %token CloseBrace "}"
321 %token OpenBracket "["
322 %token OpenBracket_let "let ["
323 %token CloseBracket "]"
325 %token At_error_ "@error"
328 %token At_class_ "@class"
332 %token _typedef_ "typedef"
333 %token _unsigned_ "unsigned"
334 %token _signed_ "signed"
335 %token _struct_ "struct"
336 %token _extern_ "extern"
340 %token At_encode_ "@encode"
344 %token At_implementation_ "@implementation"
345 %token At_import_ "@import"
346 %token At_end_ "@end"
347 %token At_selector_ "@selector"
348 %token At_null_ "@null"
349 %token At_YES_ "@YES"
351 %token At_true_ "@true"
352 %token At_false_ "@false"
357 %token _false_ "false"
362 %token _break_ "break"
364 %token _catch_ "catch"
365 %token _class_ "class"
366 %token _class__ ";class"
367 %token _const_ "const"
368 %token _continue_ "continue"
369 %token _debugger_ "debugger"
370 %token _default_ "default"
371 %token _delete_ "delete"
375 %token _export_ "export"
376 %token _extends_ "extends"
377 %token _finally_ "finally"
379 %token _function_ "function"
380 %token _function__ ";function"
382 %token _import_ "import"
385 %token _Infinity_ "Infinity"
386 %token _instanceof_ "instanceof"
388 %token _return_ "return"
389 %token _super_ "super"
390 %token _switch_ "switch"
391 %token _target_ "target"
393 %token _throw_ "throw"
395 %token _typeof_ "typeof"
398 %token _while_ "while"
401 %token _abstract_ "abstract"
402 %token _await_ "await"
403 %token _boolean_ "boolean"
406 %token _constructor_ "constructor"
407 %token _double_ "double"
409 %token _final_ "final"
410 %token _float_ "float"
414 %token _implements_ "implements"
416 %token _interface_ "interface"
420 %token _native_ "native"
421 %token _package_ "package"
422 %token _private_ "private"
423 %token _protected_ "protected"
424 %token ___proto___ "__proto__"
425 %token _prototype_ "prototype"
426 %token _public_ "public"
427 %token ___restrict_ "__restrict"
428 %token _restrict_ "restrict"
430 %token _short_ "short"
431 %token _static_ "static"
432 %token _synchronized_ "synchronized"
433 %token _throws_ "throws"
434 %token _transient_ "transient"
435 %token _volatile_ "volatile"
436 %token _yield_ "yield"
437 %token _yield__ "!yield"
439 %token _undefined_ "undefined"
455 %token _namespace_ "namespace"
460 %token YieldStar "yield *"
462 %token <identifier_> Identifier_
463 %token <number_> NumericLiteral
464 %token <string_> StringLiteral
465 %token <literal_> RegularExpressionLiteral_
467 %token <string_> NoSubstitutionTemplate
468 %token <string_> TemplateHead
469 %token <string_> TemplateMiddle
470 %token <string_> TemplateTail
472 %type <target_> AccessExpression
473 %type <expression_> AdditiveExpression
474 %type <argument_> ArgumentList_
475 %type <argument_> ArgumentList
476 %type <argument_> ArgumentListOpt
477 %type <argument_> Arguments
478 %type <target_> ArrayComprehension
479 %type <literal_> ArrayLiteral
480 %type <expression_> ArrowFunction
481 %type <functionParameter_> ArrowParameters
482 %type <expression_> AssignmentExpression
483 %type <expression_> AssignmentExpressionOpt
484 %type <identifier_> BindingIdentifier
485 %type <identifier_> BindingIdentifierOpt
486 %type <bindings_> BindingList_
487 %type <bindings_> BindingList
488 %type <expression_> BitwiseANDExpression
489 %type <statement_> Block
490 %type <statement_> BlockStatement
491 %type <boolean_> BooleanLiteral
492 %type <binding_> BindingElement
493 %type <expression_> BitwiseORExpression
494 %type <expression_> BitwiseXORExpression
495 %type <statement_> BreakStatement
496 %type <statement_> BreakableStatement
497 %type <expression_> CallExpression_
498 %type <target_> CallExpression
499 %type <clause_> CaseBlock
500 %type <clause_> CaseClause
501 %type <clause_> CaseClausesOpt
503 %type <identifier_> CatchParameter
504 %type <statement_> ClassDeclaration
505 %type <target_> ClassExpression
506 %type <classTail_> ClassHeritage
507 %type <classTail_> ClassHeritageOpt
508 %type <classTail_> ClassTail
509 %type <target_> Comprehension
510 %type <comprehension_> ComprehensionFor
511 %type <comprehension_> ComprehensionIf
512 %type <comprehension_> ComprehensionTail
513 %type <propertyName_> ComputedPropertyName
514 %type <expression_> ConditionalExpression
515 %type <statement_> ContinueStatement
516 %type <statement_> ConciseBody
517 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
518 %type <statement_> DebuggerStatement
519 %type <statement_> Declaration_
520 %type <statement_> Declaration
521 %type <clause_> DefaultClause
522 %type <element_> ElementList
523 %type <element_> ElementListOpt
524 %type <statement_> ElseStatementOpt
525 %type <for_> EmptyStatement
526 %type <expression_> EqualityExpression
527 %type <expression_> Expression
528 %type <expression_> ExpressionOpt
529 %type <for_> ExpressionStatement_
530 %type <statement_> ExpressionStatement
531 %type <statement_> ExternC
532 %type <statement_> ExternCStatement
533 %type <statement_> ExternCStatementListOpt
534 %type <finally_> Finally
535 %type <binding_> ForBinding
536 %type <forin_> ForDeclaration
537 %type <forin_> ForInStatementInitializer
538 %type <for_> ForStatementInitializer
539 %type <binding_> FormalParameter
540 %type <functionParameter_> FormalParameterList_
541 %type <functionParameter_> FormalParameterList
542 %type <functionParameter_> FormalParameters
543 %type <string_> FromClause
544 %type <statement_> FunctionBody
545 %type <statement_> FunctionDeclaration
546 %type <target_> FunctionExpression
547 %type <statement_> FunctionStatementList
548 %type <statement_> GeneratorBody
549 %type <statement_> GeneratorDeclaration
550 %type <target_> GeneratorExpression
551 %type <method_> GeneratorMethod
552 %type <statement_> HoistableDeclaration
553 %type <identifier_> Identifier
554 %type <identifier_> IdentifierNoOf
555 %type <identifier_> IdentifierType
556 %type <identifier_> IdentifierTypeNoOf
557 %type <identifier_> IdentifierTypeOpt
558 %type <word_> IdentifierName
559 %type <variable_> IdentifierReference
560 %type <statement_> IfStatement
561 %type <import_> ImportClause
562 %type <statement_> ImportDeclaration
563 %type <import_> ImportSpecifier
564 %type <identifier_> ImportedBinding
565 %type <import_> ImportedDefaultBinding
566 %type <import_> ImportsList_
567 %type <import_> ImportsList
568 %type <import_> ImportsListOpt
569 %type <target_> IndirectExpression
570 %type <expression_> Initializer
571 %type <expression_> InitializerOpt
572 %type <statement_> IterationStatement
573 %type <identifier_> LabelIdentifier
574 %type <statement_> LabelledItem
575 %type <statement_> LabelledStatement
576 %type <assignment_> LeftHandSideAssignment
577 %type <target_> LeftHandSideExpression
578 %type <bool_> LetOrConst
579 %type <binding_> LexicalBinding
580 %type <for_> LexicalDeclaration_
581 %type <statement_> LexicalDeclaration
582 %type <literal_> Literal
583 %type <propertyName_> LiteralPropertyName
584 %type <expression_> LogicalANDExpression
585 %type <expression_> LogicalORExpression
586 %type <access_> MemberAccess
587 %type <target_> MemberExpression
588 %type <method_> MethodDefinition
589 %type <statement_> ModuleBody
590 %type <statement_> ModuleBodyOpt
591 %type <statement_> ModuleItem
592 %type <statement_> ModuleItemList
593 %type <statement_> ModuleItemListOpt
594 %type <module_> ModulePath
595 %type <string_> ModuleSpecifier
596 %type <expression_> MultiplicativeExpression
597 %type <import_> NameSpaceImport
598 %type <import_> NamedImports
599 %type <target_> NewExpression
600 %type <null_> NullLiteral
601 %type <literal_> ObjectLiteral
602 %type <expression_> PostfixExpression
603 %type <target_> PrimaryExpression
604 %type <propertyName_> PropertyName
605 %type <property_> PropertyDefinition
606 %type <property_> PropertyDefinitionList_
607 %type <property_> PropertyDefinitionList
608 %type <property_> PropertyDefinitionListOpt
609 %type <functionParameter_> PropertySetParameterList
610 %type <literal_> RegularExpressionLiteral
611 %type <bool_> RegularExpressionSlash
612 %type <expression_> RelationalExpression
613 %type <statement_> ReturnStatement
614 %type <target_> RubyBlockExpression_
615 %type <target_> RubyBlockExpression
616 %type <rubyProc_> RubyProcExpression
617 %type <functionParameter_> RubyProcParameterList_
618 %type <functionParameter_> RubyProcParameterList
619 %type <functionParameter_> RubyProcParameters
620 %type <functionParameter_> RubyProcParametersOpt
621 %type <statement_> Script
622 %type <statement_> ScriptBody
623 %type <statement_> ScriptBodyOpt
624 %type <expression_> ShiftExpression
625 %type <binding_> SingleNameBinding
626 %type <statement_> Statement__
627 %type <statement_> Statement_
628 %type <statement_> Statement
629 %type <statement_> StatementList
630 %type <statement_> StatementListOpt
631 %type <statement_> StatementListItem
632 %type <functionParameter_> StrictFormalParameters
633 %type <target_> SuperCall
634 %type <target_> SuperProperty
635 %type <statement_> SwitchStatement
636 %type <target_> TemplateLiteral
637 %type <span_> TemplateSpans
638 %type <statement_> ThrowStatement
639 %type <statement_> TryStatement
640 %type <statement_> TypeDefinition
641 %type <expression_> UnaryExpression_
642 %type <expression_> UnaryExpression
643 %type <binding_> VariableDeclaration
644 %type <bindings_> VariableDeclarationList_
645 %type <bindings_> VariableDeclarationList
646 %type <for_> VariableStatement_
647 %type <statement_> VariableStatement
648 %type <statement_> WithStatement
651 %type <word_> WordOpt
653 %type <expression_> YieldExpression
656 %type <specifier_> IntegerType
657 %type <specifier_> IntegerTypeOpt
658 %type <typedIdentifier_> PrefixedType
659 %type <specifier_> PrimitiveType
660 %type <structField_> StructFieldListOpt
661 %type <typedIdentifier_> SuffixedType
662 %type <typedIdentifier_> SuffixedTypeOpt
663 %type <typedIdentifier_> TypeSignifier
664 %type <typedIdentifier_> TypeSignifierNone
665 %type <typedIdentifier_> TypeSignifierOpt
666 %type <modifier_> ParameterTail
667 %type <modifier_> TypeQualifierLeft
668 %type <modifier_> TypeQualifierLeftOpt
669 %type <typedIdentifier_> TypeQualifierRight
670 %type <typedIdentifier_> TypeQualifierRightOpt
671 %type <typedIdentifier_> TypedIdentifierDefinition
672 %type <typedIdentifier_> TypedIdentifierEncoding
673 %type <typedIdentifier_> TypedIdentifierField
674 %type <typedIdentifier_> TypedIdentifierMaybe
675 %type <typedIdentifier_> TypedIdentifierNo
676 %type <typedIdentifier_> TypedIdentifierYes
677 %type <typedParameter_> TypedParameterList_
678 %type <typedParameter_> TypedParameterList
679 %type <typedParameter_> TypedParameterListOpt
683 %type <expression_> AssignmentExpressionClassic
684 %type <expression_> BoxableExpression
685 %type <statement_> CategoryStatement
686 %type <expression_> ClassSuperOpt
687 %type <expression_> ConditionalExpressionClassic
688 %type <message_> ClassMessageDeclaration
689 %type <message_> ClassMessageDeclarationListOpt
690 %type <protocol_> ClassProtocolListOpt
691 %type <protocol_> ClassProtocols
692 %type <protocol_> ClassProtocolsOpt
693 %type <implementationField_> ImplementationFieldListOpt
694 %type <statement_> ImplementationStatement
695 %type <target_> MessageExpression
696 %type <messageParameter_> MessageParameter
697 %type <messageParameter_> MessageParameters
698 %type <messageParameter_> MessageParameterList
699 %type <messageParameter_> MessageParameterListOpt
700 %type <bool_> MessageScope
701 %type <argument_> SelectorCall_
702 %type <argument_> SelectorCall
703 %type <selector_> SelectorExpression_
704 %type <selector_> SelectorExpression
705 %type <selector_> SelectorExpressionOpt
706 %type <argument_> SelectorList
707 %type <word_> SelectorWordOpt
708 %type <typedIdentifier_> TypeOpt
709 %type <argument_> VariadicCall
713 %type <propertyIdentifier_> PropertyIdentifier_
714 %type <selector_> PropertySelector_
715 %type <selector_> PropertySelector
716 %type <identifier_> QualifiedIdentifier_
717 %type <identifier_> QualifiedIdentifier
718 %type <identifier_> WildcardIdentifier
719 %type <identifier_> XMLComment
720 %type <identifier_> XMLCDATA
721 %type <identifier_> XMLElement
722 %type <identifier_> XMLElementContent
723 %type <identifier_> XMLMarkup
724 %type <identifier_> XMLPI
726 %type <attribute_> AttributeIdentifier
727 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
728 %type <expression_> PropertyIdentifier
729 %type <expression_> XMLListInitilizer
730 %type <expression_> XMLInitilizer
733 /* Token Priorities {{{ */
749 /* Lexer State {{{ */
750 LexPushInOn: { driver.in_.push(true); };
751 LexPushInOff: { driver.in_.push(false); };
752 LexPopIn: { driver.in_.pop(); };
754 LexPushReturnOn: { driver.return_.push(true); };
755 LexPopReturn: { driver.return_.pop(); };
756 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
758 LexPushSuperOn: { driver.super_.push(true); };
759 LexPushSuperOff: { driver.super_.push(false); };
760 LexPopSuper: { driver.super_.pop(); };
761 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
763 LexPushYieldOn: { driver.yield_.push(true); };
764 LexPushYieldOff: { driver.yield_.push(false); };
765 LexPopYield: { driver.yield_.pop(); };
768 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
772 : { 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::__); }
776 : { CYMAP(YieldStar, Star); }
780 : { CYMAP(OpenBrace_, OpenBrace); }
784 : { CYMAP(_class__, _class_); }
788 : { CYMAP(_function__, _function_); }
792 : LexNoBrace LexNoClass LexNoFunction
795 /* Virtual Tokens {{{ */
801 /* 11.6 Names and Keywords {{{ */
803 : Word[pass] { $$ = $pass; }
804 | "for" { $$ = CYNew CYWord("for"); }
805 | "in" { $$ = CYNew CYWord("in"); }
806 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
810 : IdentifierNoOf[pass] { $$ = $pass; }
811 | "break" { $$ = CYNew CYWord("break"); }
812 | "case" { $$ = CYNew CYWord("case"); }
813 | "catch" { $$ = CYNew CYWord("catch"); }
814 | "class" LexOf { $$ = CYNew CYWord("class"); }
815 | ";class" { $$ = CYNew CYWord("class"); }
816 | "const" { $$ = CYNew CYWord("const"); }
817 | "continue" { $$ = CYNew CYWord("continue"); }
818 | "debugger" { $$ = CYNew CYWord("debugger"); }
819 | "default" { $$ = CYNew CYWord("default"); }
820 | "delete" { $$ = CYNew CYWord("delete"); }
821 | "do" { $$ = CYNew CYWord("do"); }
822 | "else" { $$ = CYNew CYWord("else"); }
823 | "enum" { $$ = CYNew CYWord("enum"); }
824 | "export" { $$ = CYNew CYWord("export"); }
825 | "extends" { $$ = CYNew CYWord("extends"); }
826 | "false" { $$ = CYNew CYWord("false"); }
827 | "finally" { $$ = CYNew CYWord("finally"); }
828 | "function" LexOf { $$ = CYNew CYWord("function"); }
829 | "if" { $$ = CYNew CYWord("if"); }
830 | "import" { $$ = CYNew CYWord("import"); }
831 | "!in" { $$ = CYNew CYWord("in"); }
832 | "!of" { $$ = CYNew CYWord("of"); }
833 | "new" { $$ = CYNew CYWord("new"); }
834 | "null" { $$ = CYNew CYWord("null"); }
835 | "return" { $$ = CYNew CYWord("return"); }
836 | "super" { $$ = CYNew CYWord("super"); }
837 | "switch" { $$ = CYNew CYWord("switch"); }
838 | "this" { $$ = CYNew CYWord("this"); }
839 | "throw" { $$ = CYNew CYWord("throw"); }
840 | "true" { $$ = CYNew CYWord("true"); }
841 | "try" { $$ = CYNew CYWord("try"); }
842 | "typeof" { $$ = CYNew CYWord("typeof"); }
843 | "var" { $$ = CYNew CYWord("var"); }
844 | "void" { $$ = CYNew CYWord("void"); }
845 | "while" { $$ = CYNew CYWord("while"); }
846 | "with" { $$ = CYNew CYWord("with"); }
847 | "yield" { $$ = CYNew CYIdentifier("yield"); }
852 : Word[pass] { $$ = $pass; }
857 /* 11.8.1 Null Literals {{{ */
859 : "null" { $$ = CYNew CYNull(); }
862 /* 11.8.2 Boolean Literals {{{ */
864 : "true" { $$ = CYNew CYTrue(); }
865 | "false" { $$ = CYNew CYFalse(); }
868 /* 11.8.5 Regular Expression Literals {{{ */
869 RegularExpressionSlash
870 : "/" { $$ = false; }
871 | "/=" { $$ = true; }
874 RegularExpressionLiteral
875 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
879 /* 11.9 Automatic Semicolon Insertion {{{ */
881 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
889 : LexNewLineOrNot "\n"
894 : LexNewLineOrNot "\n" StrictSemi
895 | NewLineNot LexOf Terminator
900 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
905 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
910 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
914 /* 12.1 Identifiers {{{ */
916 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
917 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
921 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
922 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
923 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
927 : BindingIdentifier[pass] { $$ = $pass; }
928 | LexOf { $$ = NULL; }
932 : Identifier[pass] { $$ = $pass; }
933 | "yield" { $$ = CYNew CYIdentifier("yield"); }
937 : Identifier_[pass] { $$ = $pass; }
938 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
939 | "as" { $$ = CYNew CYIdentifier("as"); }
940 | "await" { $$ = CYNew CYIdentifier("await"); }
941 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
942 | "byte" { $$ = CYNew CYIdentifier("byte"); }
943 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
944 | "double" { $$ = CYNew CYIdentifier("double"); }
945 | "each" { $$ = CYNew CYIdentifier("each"); }
946 | "eval" { $$ = CYNew CYIdentifier("eval"); }
947 | "final" { $$ = CYNew CYIdentifier("final"); }
948 | "float" { $$ = CYNew CYIdentifier("float"); }
949 | "from" { $$ = CYNew CYIdentifier("from"); }
950 | "get" { $$ = CYNew CYIdentifier("get"); }
951 | "goto" { $$ = CYNew CYIdentifier("goto"); }
952 | "implements" { $$ = CYNew CYIdentifier("implements"); }
953 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
954 | "interface" { $$ = CYNew CYIdentifier("interface"); }
955 | "let" { $$ = CYNew CYIdentifier("let"); }
956 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
957 | "native" { $$ = CYNew CYIdentifier("native"); }
958 | "package" { $$ = CYNew CYIdentifier("package"); }
959 | "private" { $$ = CYNew CYIdentifier("private"); }
960 | "protected" { $$ = CYNew CYIdentifier("protected"); }
961 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
962 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
963 | "public" { $$ = CYNew CYIdentifier("public"); }
964 | "set" { $$ = CYNew CYIdentifier("set"); }
965 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
966 | "target" { $$ = CYNew CYIdentifier("target"); }
967 | "throws" { $$ = CYNew CYIdentifier("throws"); }
968 | "transient" { $$ = CYNew CYIdentifier("transient"); }
969 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
971 | "bool" { $$ = CYNew CYIdentifier("bool"); }
972 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
973 | "id" { $$ = CYNew CYIdentifier("id"); }
974 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
979 : IdentifierTypeNoOf[pass] { $$ = $pass; }
980 | "of" { $$ = CYNew CYIdentifier("of"); }
984 : IdentifierType[pass] { $$ = $pass; }
990 | "char" { $$ = CYNew CYIdentifier("char"); }
991 | "int" { $$ = CYNew CYIdentifier("int"); }
992 | "long" { $$ = CYNew CYIdentifier("long"); }
993 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
994 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
995 | "short" { $$ = CYNew CYIdentifier("short"); }
996 | "static" { $$ = CYNew CYIdentifier("static"); }
997 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
999 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1000 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1003 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1004 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1005 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1006 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1011 : IdentifierNoOf[pass] { $$ = $pass; }
1012 | "of" { $$ = CYNew CYIdentifier("of"); }
1013 | "!of" { $$ = CYNew CYIdentifier("of"); }
1016 /* 12.2 Primary Expression {{{ */
1018 : "this" { $$ = CYNew CYThis(); }
1019 | IdentifierReference[pass] { $$ = $pass; }
1020 | Literal[pass] { $$ = $pass; }
1021 | ArrayLiteral[pass] { $$ = $pass; }
1022 | ObjectLiteral[pass] { $$ = $pass; }
1023 | FunctionExpression[pass] { $$ = $pass; }
1024 | ClassExpression[pass] { $$ = $pass; }
1025 | GeneratorExpression[pass] { $$ = $pass; }
1026 | RegularExpressionLiteral[pass] { $$ = $pass; }
1027 | TemplateLiteral[pass] { $$ = $pass; }
1028 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1029 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1032 CoverParenthesizedExpressionAndArrowParameterList
1033 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1034 | "(" LexOf ")" { $$ = NULL; }
1035 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1036 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1039 /* 12.2.4 Literals {{{ */
1041 : NullLiteral[pass] { $$ = $pass; }
1042 | BooleanLiteral[pass] { $$ = $pass; }
1043 | NumericLiteral[pass] { $$ = $pass; }
1044 | StringLiteral[pass] { $$ = $pass; }
1047 /* 12.2.5 Array Initializer {{{ */
1049 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1053 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1054 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1055 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1059 : ElementList[pass] { $$ = $pass; }
1060 | LexOf { $$ = NULL; }
1063 /* 12.2.6 Object Initializer {{{ */
1065 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1068 PropertyDefinitionList_
1069 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1073 PropertyDefinitionList
1074 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1077 PropertyDefinitionListOpt
1078 : PropertyDefinitionList[properties] { $$ = $properties; }
1083 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1084 | CoverInitializedName[name] { CYNOT(@$); }
1085 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1086 | MethodDefinition[pass] { $$ = $pass; }
1090 : LiteralPropertyName[pass] { $$ = $pass; }
1091 | ComputedPropertyName[pass] { $$ = $pass; }
1095 : IdentifierName[pass] { $$ = $pass; }
1096 | StringLiteral[pass] { $$ = $pass; }
1097 | NumericLiteral[pass] { $$ = $pass; }
1100 ComputedPropertyName
1101 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1104 CoverInitializedName
1105 : IdentifierReference Initializer
1109 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1113 : Initializer[pass] { $$ = $pass; }
1117 /* 12.2.9 Template Literals {{{ */
1119 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1120 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1124 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1125 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1129 /* 12.3 Left-Hand-Side Expressions {{{ */
1131 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1132 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1133 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1134 | TemplateLiteral { CYNOT(@$); }
1138 : PrimaryExpression[pass] { $$ = $pass; }
1139 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1140 | SuperProperty[pass] { $$ = $pass; }
1141 | MetaProperty { CYNOT(@$); }
1142 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1146 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1147 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1155 : "new" "." "target"
1159 : MemberExpression[pass] { $$ = $pass; }
1160 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1164 : MemberExpression[pass] { $$ = $pass; }
1165 | CallExpression[pass] { $$ = $pass; }
1169 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1170 | SuperCall[pass] { $$ = $pass; }
1171 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1175 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1179 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1183 : "," ArgumentList[arguments] { $$ = $arguments; }
1188 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1189 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1193 : ArgumentList[pass] { $$ = $pass; }
1194 | LexOf { $$ = NULL; }
1198 : NewExpression[pass] { $$ = $pass; }
1199 | CallExpression[pass] { $$ = $pass; }
1202 LeftHandSideExpression
1203 : RubyBlockExpression[pass] { $$ = $pass; }
1204 | IndirectExpression[pass] { $$ = $pass; }
1207 /* 12.4 Postfix Expressions {{{ */
1209 : RubyBlockExpression[pass] { $$ = $pass; }
1210 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1211 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1214 /* 12.5 Unary Operators {{{ */
1216 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1217 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1218 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1219 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1220 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1221 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1222 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1223 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1224 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1228 : PostfixExpression[expression] { $$ = $expression; }
1229 | UnaryExpression_[pass] { $$ = $pass; }
1232 /* 12.6 Multiplicative Operators {{{ */
1233 MultiplicativeExpression
1234 : UnaryExpression[pass] { $$ = $pass; }
1235 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1236 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1237 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1240 /* 12.7 Additive Operators {{{ */
1242 : MultiplicativeExpression[pass] { $$ = $pass; }
1243 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1244 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1247 /* 12.8 Bitwise Shift Operators {{{ */
1249 : AdditiveExpression[pass] { $$ = $pass; }
1250 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1251 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1252 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1255 /* 12.9 Relational Operators {{{ */
1256 RelationalExpression
1257 : ShiftExpression[pass] { $$ = $pass; }
1258 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1259 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1260 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1261 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1262 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1263 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1266 /* 12.10 Equality Operators {{{ */
1268 : RelationalExpression[pass] { $$ = $pass; }
1269 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1270 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1271 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1272 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1275 /* 12.11 Binary Bitwise Operators {{{ */
1276 BitwiseANDExpression
1277 : EqualityExpression[pass] { $$ = $pass; }
1278 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1281 BitwiseXORExpression
1282 : BitwiseANDExpression[pass] { $$ = $pass; }
1283 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1287 : BitwiseXORExpression[pass] { $$ = $pass; }
1288 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1291 /* 12.12 Binary Logical Operators {{{ */
1292 LogicalANDExpression
1293 : BitwiseORExpression[pass] { $$ = $pass; }
1294 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1298 : LogicalANDExpression[pass] { $$ = $pass; }
1299 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1302 /* 12.13 Conditional Operator ( ? : ) {{{ */
1304 ConditionalExpressionClassic
1305 : LogicalORExpression[pass] { $$ = $pass; }
1306 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1310 ConditionalExpression
1311 : LogicalORExpression[pass] { $$ = $pass; }
1312 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1315 /* 12.14 Assignment Operators {{{ */
1316 LeftHandSideAssignment
1317 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1318 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1319 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1320 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1321 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1322 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1323 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1324 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1325 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1326 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1327 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1328 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1332 AssignmentExpressionClassic
1333 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1334 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1338 AssignmentExpression
1339 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1340 | LexOf YieldExpression[pass] { $$ = $pass; }
1341 | ArrowFunction[pass] { $$ = $pass; }
1342 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1345 AssignmentExpressionOpt
1346 : AssignmentExpression[pass] { $$ = $pass; }
1347 | LexOf { $$ = NULL; }
1350 /* 12.15 Comma Operator ( , ) {{{ */
1352 : AssignmentExpression[pass] { $$ = $pass; }
1353 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1357 : Expression[pass] { $$ = $pass; }
1358 | LexOf { $$ = NULL; }
1362 /* 13 Statements and Declarations {{{ */
1364 : BlockStatement[pass] { $$ = $pass; }
1365 | VariableStatement[pass] { $$ = $pass; }
1366 | EmptyStatement[pass] { $$ = $pass; }
1367 | IfStatement[pass] { $$ = $pass; }
1368 | BreakableStatement[pass] { $$ = $pass; }
1369 | ContinueStatement[pass] { $$ = $pass; }
1370 | BreakStatement[pass] { $$ = $pass; }
1371 | ReturnStatement[pass] { $$ = $pass; }
1372 | WithStatement[pass] { $$ = $pass; }
1373 | LabelledStatement[pass] { $$ = $pass; }
1374 | ThrowStatement[pass] { $$ = $pass; }
1375 | TryStatement[pass] { $$ = $pass; }
1376 | DebuggerStatement[pass] { $$ = $pass; }
1380 : LexOf Statement__[pass] { $$ = $pass; }
1381 | ExpressionStatement[pass] { $$ = $pass; }
1385 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1389 : HoistableDeclaration[pass] { $$ = $pass; }
1390 | ClassDeclaration[pass] { $$ = $pass; }
1394 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1395 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1398 HoistableDeclaration
1399 : FunctionDeclaration[pass] { $$ = $pass; }
1400 | GeneratorDeclaration[pass] { $$ = $pass; }
1404 : IterationStatement[pass] { $$ = $pass; }
1405 | SwitchStatement[pass] { $$ = $pass; }
1408 /* 13.2 Block {{{ */
1410 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1414 : "{" StatementListOpt[code] "}" { $$ = $code; }
1418 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1422 : StatementList[pass] { $$ = $pass; }
1423 | LexSetStatement LexLet LexOf { $$ = NULL; }
1427 : Statement[pass] { $$ = $pass; }
1428 | Declaration[pass] { $$ = $pass; }
1431 /* 13.3 Let and Const Declarations {{{ */
1433 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1437 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1441 : { CYMAP(_let__, _let_); }
1445 : { CYMAP(_of__, _of_); }
1449 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1453 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1454 | LexLet LexOf "const" { $$ = true; }
1458 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1463 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1467 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1468 | LexOf BindingPattern Initializer { CYNOT(@$); }
1471 /* 13.3.2 Variable Statement {{{ */
1473 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1477 : VariableStatement_[statement] Terminator { $$ = $statement; }
1480 VariableDeclarationList_
1481 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1485 VariableDeclarationList
1486 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1490 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1491 | LexOf BindingPattern Initializer { CYNOT(@$); }
1494 /* 13.3.3 Destructuring Binding Patterns {{{ */
1496 : ObjectBindingPattern
1497 | ArrayBindingPattern
1500 ObjectBindingPattern
1501 : "let {" BindingPropertyListOpt "}"
1505 : "let [" BindingElementListOpt "]"
1508 BindingPropertyList_
1509 : "," BindingPropertyListOpt
1514 : BindingProperty BindingPropertyList_
1517 BindingPropertyListOpt
1518 : BindingPropertyList
1523 : BindingElementOpt[element] "," BindingElementListOpt[next]
1524 | BindingRestElement[element]
1525 | BindingElement[element]
1528 BindingElementListOpt
1529 : BindingElementList[pass]
1535 | LexOf PropertyName ":" BindingElement
1539 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1540 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1544 : BindingElement[pass]
1549 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1553 : LexBind LexOf "..." BindingIdentifier
1556 /* 13.4 Empty Statement {{{ */
1558 : ";" { $$ = CYNew CYEmpty(); }
1561 /* 13.5 Expression Statement {{{ */
1562 ExpressionStatement_
1563 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1566 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1569 /* 13.6 The if Statement {{{ */
1571 : "else" Statement[false] { $$ = $false; }
1572 | %prec "if" { $$ = NULL; }
1576 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1579 /* 13.7 Iteration Statements {{{ */
1581 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1582 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1583 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1584 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1585 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1586 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1589 ForStatementInitializer
1590 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1591 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1592 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1593 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1596 ForInStatementInitializer
1597 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1598 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1599 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1600 | ForDeclaration[pass] { $$ = $pass; }
1604 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1608 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1609 | LexOf BindingPattern { CYNOT(@$); }
1612 /* 13.8 The continue Statement {{{ */
1614 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1615 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1618 /* 13.9 The break Statement {{{ */
1620 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1621 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1624 /* 13.10 The return Statement {{{ */
1626 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1627 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1630 /* 13.11 The with Statement {{{ */
1632 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1635 /* 13.12 The switch Statement {{{ */
1637 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1641 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1645 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1649 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1650 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1654 // XXX: the standard makes certain you can only have one of these
1656 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1659 /* 13.13 Labelled Statements {{{ */
1661 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1665 : Statement[pass] { $$ = $pass; }
1666 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1669 /* 13.14 The throw Statement {{{ */
1671 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1672 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1675 /* 13.15 The try Statement {{{ */
1677 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1678 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1679 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1683 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1687 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1691 : BindingIdentifier[pass] { $$ = $pass; }
1692 | LexOf BindingPattern { CYNOT(@$); }
1695 /* 13.16 The debugger Statement {{{ */
1697 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1701 /* 14.1 Function Definitions {{{ */
1703 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1707 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1710 StrictFormalParameters
1711 : FormalParameters[pass] { $$ = $pass; }
1715 : LexBind LexOf { $$ = NULL; }
1716 | FormalParameterList
1719 FormalParameterList_
1720 : "," FormalParameterList[parameters] { $$ = $parameters; }
1725 : FunctionRestParameter { CYNOT(@$); }
1726 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1729 FunctionRestParameter
1730 : BindingRestElement
1734 : BindingElement[pass] { $$ = $pass; }
1738 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1741 FunctionStatementList
1742 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1745 /* 14.2 Arrow Function Definitions {{{ */
1747 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1751 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1752 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1756 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1757 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1760 /* 14.3 Method Definitions {{{ */
1762 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1763 | GeneratorMethod[pass] { $$ = $pass; }
1764 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1765 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1768 PropertySetParameterList
1769 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1772 /* 14.4 Generator Function Definitions {{{ */
1774 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1777 GeneratorDeclaration
1778 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1782 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1786 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1790 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1791 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1792 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1793 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1796 /* 14.5 Class Definitions {{{ */
1798 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1802 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1806 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1810 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1814 : ClassHeritage[pass] { $$ = $pass; }
1815 | { $$ = CYNew CYClassTail(NULL); }
1828 : ClassElementListOpt ClassElement
1837 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1838 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1843 /* 15.1 Scripts {{{ */
1845 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1849 : StatementList[pass] { $$ = $pass; }
1853 : ScriptBody[pass] { $$ = $pass; }
1854 | LexSetStatement LexLet LexOf { $$ = NULL; }
1857 /* 15.2 Modules {{{ */
1859 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1863 : ModuleItemList[pass] { $$ = $pass; }
1867 : ModuleBody[pass] { $$ = $pass; }
1868 | LexSetStatement LexLet LexOf { $$ = NULL; }
1872 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1876 : ModuleItemList[pass] { $$ = $pass; }
1877 | LexSetStatement LexLet LexOf { $$ = NULL; }
1881 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1882 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1883 | StatementListItem[pass] { $$ = $pass; }
1886 /* 15.2.2 Imports {{{ */
1888 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1889 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1893 : ImportedDefaultBinding[default] { $$ = $default; }
1894 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1895 | LexOf NamedImports[pass] { $$ = $pass; }
1896 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1897 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1900 ImportedDefaultBinding
1901 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1905 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1909 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1913 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1917 : "," ImportsListOpt[pass] { $$ = $pass; }
1922 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1926 : ImportsList[pass] { $$ = $pass; }
1927 | LexOf { $$ = NULL; }
1931 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1932 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1936 : StringLiteral[pass] { $$ = $pass; }
1940 : BindingIdentifier[pass] { $$ = $pass; }
1943 /* 15.2.3 Exports {{{ */
1945 : "*" FromClause Terminator
1946 | ExportClause FromClause Terminator
1947 | ExportClause Terminator
1949 | "default" LexSetStatement LexOf HoistableDeclaration
1950 | "default" LexSetStatement LexOf ClassDeclaration
1951 | "default" LexSetStatement AssignmentExpression Terminator
1955 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1956 | "export" Declaration
1960 : ";{" ExportsListOpt "}"
1964 : "," ExportsListOpt
1969 : ExportSpecifier ExportsList_
1979 | IdentifierName "as" IdentifierName
1984 /* Cycript (C): Type Encoding {{{ */
1986 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1987 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1991 : { $$ = CYNew CYTypedIdentifier(@$); }
1995 : TypeSignifier[pass] { $$ = $pass; }
1996 | TypeSignifierNone[pass] { $$ = $pass; }
2013 ParameterModifierOpt
2019 : TypedParameterListOpt[parameters] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($parameters); }
2023 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2024 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2025 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2026 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2030 : SuffixedType[pass] { $$ = $pass; }
2031 | TypeSignifierOpt[pass] { $$ = $pass; }
2035 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2039 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2040 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2043 TypeQualifierLeftOpt
2044 : TypeQualifierLeft[pass] { $$ = $pass; }
2049 : SuffixedType[pass] { $$ = $pass; }
2050 | PrefixedType[pass] { $$ = $pass; }
2051 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2052 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2053 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2056 TypeQualifierRightOpt
2057 : TypeQualifierRight[pass] { $$ = $pass; }
2058 | TypeSignifierOpt[pass] { $$ = $pass; }
2062 : "int" { $$ = CYNew CYTypeVariable("int"); }
2063 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
2064 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
2065 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
2066 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
2070 : IntegerType[pass] { $$ = $pass; }
2071 | { $$ = CYNew CYTypeVariable("int"); }
2075 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2080 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2081 | IntegerType[pass] { $$ = $pass; }
2082 | "char" { $$ = CYNew CYTypeVariable("char"); }
2083 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
2084 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2085 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2088 TypedIdentifierMaybe
2089 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2090 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2091 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2095 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2099 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2102 TypedIdentifierField
2103 : TypedIdentifierYes[pass] { $$ = $pass; }
2104 | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2107 TypedIdentifierEncoding
2108 : TypedIdentifierNo[pass] { $$ = $pass; }
2109 | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2112 TypedIdentifierDefinition
2113 : TypedIdentifierYes[pass] { $$ = $pass; }
2114 | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2118 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2124 /* Cycript (Objective-C): @class Declaration {{{ */
2126 /* XXX: why the hell did I choose MemberExpression? */
2127 : ":" MemberExpression[extends] { $$ = $extends; }
2131 ImplementationFieldListOpt
2132 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2137 : "+" { $$ = false; }
2138 | "-" { $$ = true; }
2142 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2143 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2147 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2150 MessageParameterList
2151 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2154 MessageParameterListOpt
2155 : MessageParameterList[pass] { $$ = $pass; }
2160 : MessageParameterList[pass] { $$ = $pass; }
2161 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2164 ClassMessageDeclaration
2165 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2168 ClassMessageDeclarationListOpt
2169 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2173 // XXX: this should be AssignmentExpressionNoRight
2175 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2179 : "," ClassProtocols[protocols] { $$ = $protocols; }
2183 ClassProtocolListOpt
2184 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2188 ImplementationStatement
2189 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2197 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2201 : ImplementationStatement[pass] { $$ = $pass; }
2202 | CategoryStatement[pass] { $$ = $pass; }
2205 /* Cycript (Objective-C): Send Message {{{ */
2207 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2212 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2213 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2217 : SelectorCall[pass] { $$ = $pass; }
2218 | VariadicCall[pass] { $$ = $pass; }
2222 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2226 : SelectorCall[pass] { $$ = $pass; }
2227 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2231 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2232 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2236 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2240 : SelectorExpression_[pass] { $$ = $pass; }
2241 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2244 SelectorExpressionOpt
2245 : SelectorExpression_[pass] { $$ = $pass; }
2250 : MessageExpression[pass] { $$ = $pass; }
2251 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2256 /* Cycript: @import Directive {{{ */
2258 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2259 | Word[part] { $$ = CYNew CYModule($part); }
2263 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2268 /* Cycript (Objective-C): Boxed Expressions {{{ */
2270 : NullLiteral[pass] { $$ = $pass; }
2271 | BooleanLiteral[pass] { $$ = $pass; }
2272 | NumericLiteral[pass] { $$ = $pass; }
2273 | StringLiteral[pass] { $$ = $pass; }
2274 | ArrayLiteral[pass] { $$ = $pass; }
2275 | ObjectLiteral[pass] { $$ = $pass; }
2276 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2277 | "YES" { $$ = CYNew CYTrue(); }
2278 | "NO" { $$ = CYNew CYFalse(); }
2282 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2283 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2284 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2285 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2286 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2287 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2290 /* Cycript (Objective-C): Block Expressions {{{ */
2292 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2295 /* Cycript (Objective-C): Instance Literals {{{ */
2297 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2303 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2305 : IndirectExpression[pass] { $$ = $pass; }
2309 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2313 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2317 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2318 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2319 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2322 /* Cycript (C): Lambda Expressions {{{ */
2324 : "," TypedParameterList[parameters] { $$ = $parameters; }
2329 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2332 TypedParameterListOpt
2333 : TypedParameterList[pass] { $$ = $pass; }
2334 | "void" { $$ = NULL; }
2339 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2342 /* Cycript (C): Structure Definitions {{{ */
2344 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2348 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2352 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2355 /* Cycript (C): Type Definitions {{{ */
2357 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2361 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2365 : TypeDefinition[pass] { $$ = $pass; }
2369 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2372 /* Cycript (C): extern "C" {{{ */
2374 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2378 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2379 | TypeDefinition[pass] { $$ = $pass; }
2382 ExternCStatementListOpt
2383 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2388 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2389 | ExternCStatement[pass] { $$ = $pass; }
2393 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2399 /* Lexer State {{{ */
2401 : { driver.PushCondition(CYDriver::RegExpCondition); }
2405 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2409 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2413 : { driver.PopCondition(); }
2417 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2421 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2424 /* Virtual Tokens {{{ */
2431 /* 8.1 Context Keywords {{{ */
2433 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2434 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2437 /* 8.3 XML Initializer Input Elements {{{ */
2439 : XMLComment { $$ = $1; }
2440 | XMLCDATA { $$ = $1; }
2441 | XMLPI { $$ = $1; }
2445 /* 11.1 Primary Expressions {{{ */
2447 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2448 | XMLInitilizer { $$ = $1; }
2449 | XMLListInitilizer { $$ = $1; }
2453 : AttributeIdentifier { $$ = $1; }
2454 | QualifiedIdentifier { $$ = $1; }
2455 | WildcardIdentifier { $$ = $1; }
2458 /* 11.1.1 Attribute Identifiers {{{ */
2460 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2464 : PropertySelector { $$ = $1; }
2465 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2469 : Identifier { $$ = CYNew CYSelector($1); }
2470 | WildcardIdentifier { $$ = $1; }
2473 /* 11.1.2 Qualified Identifiers {{{ */
2474 QualifiedIdentifier_
2475 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2476 | QualifiedIdentifier { $$ = $1; }
2480 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2483 /* 11.1.3 Wildcard Identifiers {{{ */
2485 : "*" { $$ = CYNew CYWildcard(); }
2488 /* 11.1.4 XML Initializer {{{ */
2490 : XMLMarkup { $$ = $1; }
2491 | XMLElement { $$ = $1; }
2495 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2496 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2500 : LexPushXMLTag XMLTagName XMLAttributes
2504 : "{" LexPushRegExp Expression LexPop "}"
2513 : XMLAttributes_ XMLAttribute
2518 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2519 | XMLAttributes_ XMLWhitespaceOpt
2528 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2532 : XMLExpression XMLElementContentOpt
2533 | XMLMarkup XMLElementContentOpt
2534 | XMLText XMLElementContentOpt
2535 | XMLElement XMLElementContentOpt
2538 XMLElementContentOpt
2543 /* 11.1.5 XMLList Initializer {{{ */
2545 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2549 /* 11.2 Left-Hand-Side Expressions {{{ */
2551 : Identifier { $$ = $1; }
2552 | PropertyIdentifier { $$ = $1; }
2556 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2557 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2558 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2561 /* 12.1 The default xml namespace Statement {{{ */
2562 /* XXX: DefaultXMLNamespaceStatement
2563 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2567 : DefaultXMLNamespaceStatement { $$ = $1; }
2572 /* JavaScript FTL: Array Comprehensions {{{ */
2574 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2578 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2581 /* JavaScript FTL: for each {{{ */
2583 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2587 /* JavaScript FTW: Array Comprehensions {{{ */
2589 : ArrayComprehension
2593 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2597 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2602 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2603 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2607 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2608 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2612 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2615 /* JavaScript FTW: Coalesce Operator {{{ */
2616 ConditionalExpression
2617 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2620 /* JavaScript FTW: Named Arguments {{{ */
2622 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2625 /* JavaScript FTW: Ruby Blocks {{{ */
2626 RubyProcParameterList_
2627 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2631 RubyProcParameterList
2632 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2633 | LexOf { $$ = NULL; }
2637 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2638 | "||" { $$ = NULL; }
2641 RubyProcParametersOpt
2642 : RubyProcParameters[pass] { $$ = $pass; }
2647 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2651 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2654 RubyBlockExpression_
2655 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2656 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2660 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2661 | RubyBlockExpression_[pass] { $$ = $pass; }
2667 bool CYDriver::Parse(CYMark mark) {
2669 CYLocal<CYPool> local(&pool_);
2670 cy::parser parser(*this);
2672 parser.set_debug_level(debug_);
2674 return parser.parse() != 0;
2677 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2681 CYDriver::Error error;
2682 error.warning_ = true;
2683 error.location_ = location;
2684 error.message_ = message;
2685 errors_.push_back(error);
2688 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2689 CYDriver::Error error;
2690 error.warning_ = false;
2691 error.location_ = location;
2692 error.message_ = message;
2693 driver.errors_.push_back(error);