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"
428 %token _short_ "short"
429 %token _static_ "static"
430 %token _synchronized_ "synchronized"
431 %token _throws_ "throws"
432 %token _transient_ "transient"
433 %token _volatile_ "volatile"
434 %token _yield_ "yield"
435 %token _yield__ "!yield"
437 %token _undefined_ "undefined"
453 %token _namespace_ "namespace"
458 %token YieldStar "yield *"
460 %token <identifier_> Identifier_
461 %token <number_> NumericLiteral
462 %token <string_> StringLiteral
463 %token <literal_> RegularExpressionLiteral_
465 %token <string_> NoSubstitutionTemplate
466 %token <string_> TemplateHead
467 %token <string_> TemplateMiddle
468 %token <string_> TemplateTail
470 %type <target_> AccessExpression
471 %type <expression_> AdditiveExpression
472 %type <argument_> ArgumentList_
473 %type <argument_> ArgumentList
474 %type <argument_> ArgumentListOpt
475 %type <argument_> Arguments
476 %type <target_> ArrayComprehension
477 %type <literal_> ArrayLiteral
478 %type <expression_> ArrowFunction
479 %type <functionParameter_> ArrowParameters
480 %type <expression_> AssignmentExpression
481 %type <expression_> AssignmentExpressionOpt
482 %type <identifier_> BindingIdentifier
483 %type <identifier_> BindingIdentifierOpt
484 %type <bindings_> BindingList_
485 %type <bindings_> BindingList
486 %type <expression_> BitwiseANDExpression
487 %type <statement_> Block
488 %type <statement_> BlockStatement
489 %type <boolean_> BooleanLiteral
490 %type <binding_> BindingElement
491 %type <expression_> BitwiseORExpression
492 %type <expression_> BitwiseXORExpression
493 %type <statement_> BreakStatement
494 %type <statement_> BreakableStatement
495 %type <expression_> CallExpression_
496 %type <target_> CallExpression
497 %type <clause_> CaseBlock
498 %type <clause_> CaseClause
499 %type <clause_> CaseClausesOpt
501 %type <identifier_> CatchParameter
502 %type <statement_> ClassDeclaration
503 %type <target_> ClassExpression
504 %type <classTail_> ClassHeritage
505 %type <classTail_> ClassHeritageOpt
506 %type <classTail_> ClassTail
507 %type <target_> Comprehension
508 %type <comprehension_> ComprehensionFor
509 %type <comprehension_> ComprehensionIf
510 %type <comprehension_> ComprehensionTail
511 %type <propertyName_> ComputedPropertyName
512 %type <expression_> ConditionalExpression
513 %type <statement_> ContinueStatement
514 %type <statement_> ConciseBody
515 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
516 %type <statement_> DebuggerStatement
517 %type <statement_> Declaration_
518 %type <statement_> Declaration
519 %type <clause_> DefaultClause
520 %type <element_> ElementList
521 %type <element_> ElementListOpt
522 %type <statement_> ElseStatementOpt
523 %type <for_> EmptyStatement
524 %type <expression_> EqualityExpression
525 %type <expression_> Expression
526 %type <expression_> ExpressionOpt
527 %type <for_> ExpressionStatement_
528 %type <statement_> ExpressionStatement
529 %type <statement_> ExternC
530 %type <statement_> ExternCStatement
531 %type <statement_> ExternCStatementListOpt
532 %type <finally_> Finally
533 %type <binding_> ForBinding
534 %type <forin_> ForDeclaration
535 %type <forin_> ForInStatementInitializer
536 %type <for_> ForStatementInitializer
537 %type <binding_> FormalParameter
538 %type <functionParameter_> FormalParameterList_
539 %type <functionParameter_> FormalParameterList
540 %type <functionParameter_> FormalParameters
541 %type <string_> FromClause
542 %type <statement_> FunctionBody
543 %type <statement_> FunctionDeclaration
544 %type <target_> FunctionExpression
545 %type <statement_> FunctionStatementList
546 %type <statement_> GeneratorBody
547 %type <statement_> GeneratorDeclaration
548 %type <target_> GeneratorExpression
549 %type <method_> GeneratorMethod
550 %type <statement_> HoistableDeclaration
551 %type <identifier_> Identifier
552 %type <identifier_> IdentifierNoOf
553 %type <identifier_> IdentifierType
554 %type <identifier_> IdentifierTypeNoOf
555 %type <identifier_> IdentifierTypeOpt
556 %type <word_> IdentifierName
557 %type <variable_> IdentifierReference
558 %type <statement_> IfStatement
559 %type <import_> ImportClause
560 %type <statement_> ImportDeclaration
561 %type <import_> ImportSpecifier
562 %type <identifier_> ImportedBinding
563 %type <import_> ImportedDefaultBinding
564 %type <import_> ImportsList_
565 %type <import_> ImportsList
566 %type <import_> ImportsListOpt
567 %type <target_> IndirectExpression
568 %type <expression_> Initializer
569 %type <expression_> InitializerOpt
570 %type <statement_> IterationStatement
571 %type <identifier_> LabelIdentifier
572 %type <statement_> LabelledItem
573 %type <statement_> LabelledStatement
574 %type <assignment_> LeftHandSideAssignment
575 %type <target_> LeftHandSideExpression
576 %type <bool_> LetOrConst
577 %type <binding_> LexicalBinding
578 %type <for_> LexicalDeclaration_
579 %type <statement_> LexicalDeclaration
580 %type <literal_> Literal
581 %type <propertyName_> LiteralPropertyName
582 %type <expression_> LogicalANDExpression
583 %type <expression_> LogicalORExpression
584 %type <access_> MemberAccess
585 %type <target_> MemberExpression
586 %type <method_> MethodDefinition
587 %type <statement_> ModuleBody
588 %type <statement_> ModuleBodyOpt
589 %type <statement_> ModuleItem
590 %type <statement_> ModuleItemList
591 %type <statement_> ModuleItemListOpt
592 %type <module_> ModulePath
593 %type <string_> ModuleSpecifier
594 %type <expression_> MultiplicativeExpression
595 %type <import_> NameSpaceImport
596 %type <import_> NamedImports
597 %type <target_> NewExpression
598 %type <null_> NullLiteral
599 %type <literal_> ObjectLiteral
600 %type <expression_> PostfixExpression
601 %type <target_> PrimaryExpression
602 %type <propertyName_> PropertyName
603 %type <property_> PropertyDefinition
604 %type <property_> PropertyDefinitionList_
605 %type <property_> PropertyDefinitionList
606 %type <property_> PropertyDefinitionListOpt
607 %type <functionParameter_> PropertySetParameterList
608 %type <literal_> RegularExpressionLiteral
609 %type <bool_> RegularExpressionSlash
610 %type <expression_> RelationalExpression
611 %type <statement_> ReturnStatement
612 %type <target_> RubyBlockExpression_
613 %type <target_> RubyBlockExpression
614 %type <rubyProc_> RubyProcExpression
615 %type <functionParameter_> RubyProcParameterList_
616 %type <functionParameter_> RubyProcParameterList
617 %type <functionParameter_> RubyProcParameters
618 %type <functionParameter_> RubyProcParametersOpt
619 %type <statement_> Script
620 %type <statement_> ScriptBody
621 %type <statement_> ScriptBodyOpt
622 %type <expression_> ShiftExpression
623 %type <binding_> SingleNameBinding
624 %type <statement_> Statement__
625 %type <statement_> Statement_
626 %type <statement_> Statement
627 %type <statement_> StatementList
628 %type <statement_> StatementListOpt
629 %type <statement_> StatementListItem
630 %type <functionParameter_> StrictFormalParameters
631 %type <target_> SuperCall
632 %type <target_> SuperProperty
633 %type <statement_> SwitchStatement
634 %type <target_> TemplateLiteral
635 %type <span_> TemplateSpans
636 %type <statement_> ThrowStatement
637 %type <statement_> TryStatement
638 %type <statement_> TypeDefinition
639 %type <expression_> UnaryExpression_
640 %type <expression_> UnaryExpression
641 %type <binding_> VariableDeclaration
642 %type <bindings_> VariableDeclarationList_
643 %type <bindings_> VariableDeclarationList
644 %type <for_> VariableStatement_
645 %type <statement_> VariableStatement
646 %type <statement_> WithStatement
649 %type <word_> WordOpt
651 %type <expression_> YieldExpression
654 %type <specifier_> IntegerType
655 %type <specifier_> IntegerTypeOpt
656 %type <typedIdentifier_> PrefixedType
657 %type <specifier_> PrimitiveType
658 %type <structField_> StructFieldListOpt
659 %type <typedIdentifier_> SuffixedType
660 %type <typedIdentifier_> SuffixedTypeOpt
661 %type <typedIdentifier_> TypeSignifier
662 %type <typedIdentifier_> TypeSignifierNone
663 %type <typedIdentifier_> TypeSignifierOpt
664 %type <modifier_> TypeQualifierLeft
665 %type <modifier_> TypeQualifierLeftOpt
666 %type <typedIdentifier_> TypeQualifierRight
667 %type <typedIdentifier_> TypeQualifierRightOpt
668 %type <typedIdentifier_> TypedIdentifierDefinition
669 %type <typedIdentifier_> TypedIdentifierEncoding
670 %type <typedIdentifier_> TypedIdentifierField
671 %type <typedIdentifier_> TypedIdentifierMaybe
672 %type <typedIdentifier_> TypedIdentifierNo
673 %type <typedIdentifier_> TypedIdentifierYes
674 %type <typedParameter_> TypedParameterList_
675 %type <typedParameter_> TypedParameterList
676 %type <typedParameter_> TypedParameterListOpt
680 %type <expression_> AssignmentExpressionClassic
681 %type <expression_> BoxableExpression
682 %type <statement_> CategoryStatement
683 %type <expression_> ClassSuperOpt
684 %type <expression_> ConditionalExpressionClassic
685 %type <message_> ClassMessageDeclaration
686 %type <message_> ClassMessageDeclarationListOpt
687 %type <protocol_> ClassProtocolListOpt
688 %type <protocol_> ClassProtocols
689 %type <protocol_> ClassProtocolsOpt
690 %type <implementationField_> ImplementationFieldListOpt
691 %type <statement_> ImplementationStatement
692 %type <target_> MessageExpression
693 %type <messageParameter_> MessageParameter
694 %type <messageParameter_> MessageParameters
695 %type <messageParameter_> MessageParameterList
696 %type <messageParameter_> MessageParameterListOpt
697 %type <bool_> MessageScope
698 %type <argument_> SelectorCall_
699 %type <argument_> SelectorCall
700 %type <selector_> SelectorExpression_
701 %type <selector_> SelectorExpression
702 %type <selector_> SelectorExpressionOpt
703 %type <argument_> SelectorList
704 %type <word_> SelectorWordOpt
705 %type <typedIdentifier_> TypeOpt
706 %type <argument_> VariadicCall
710 %type <propertyIdentifier_> PropertyIdentifier_
711 %type <selector_> PropertySelector_
712 %type <selector_> PropertySelector
713 %type <identifier_> QualifiedIdentifier_
714 %type <identifier_> QualifiedIdentifier
715 %type <identifier_> WildcardIdentifier
716 %type <identifier_> XMLComment
717 %type <identifier_> XMLCDATA
718 %type <identifier_> XMLElement
719 %type <identifier_> XMLElementContent
720 %type <identifier_> XMLMarkup
721 %type <identifier_> XMLPI
723 %type <attribute_> AttributeIdentifier
724 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
725 %type <expression_> PropertyIdentifier
726 %type <expression_> XMLListInitilizer
727 %type <expression_> XMLInitilizer
730 /* Token Priorities {{{ */
746 /* Lexer State {{{ */
747 LexPushInOn: { driver.in_.push(true); };
748 LexPushInOff: { driver.in_.push(false); };
749 LexPopIn: { driver.in_.pop(); };
751 LexPushReturnOn: { driver.return_.push(true); };
752 LexPopReturn: { driver.return_.pop(); };
753 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
755 LexPushSuperOn: { driver.super_.push(true); };
756 LexPushSuperOff: { driver.super_.push(false); };
757 LexPopSuper: { driver.super_.pop(); };
758 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
760 LexPushYieldOn: { driver.yield_.push(true); };
761 LexPushYieldOff: { driver.yield_.push(false); };
762 LexPopYield: { driver.yield_.pop(); };
765 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
769 : { 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::__); }
773 : { CYMAP(YieldStar, Star); }
777 : { CYMAP(OpenBrace_, OpenBrace); }
781 : { CYMAP(_class__, _class_); }
785 : { CYMAP(_function__, _function_); }
789 : LexNoBrace LexNoClass LexNoFunction
792 /* Virtual Tokens {{{ */
798 /* 11.6 Names and Keywords {{{ */
800 : Word[pass] { $$ = $pass; }
801 | "for" { $$ = CYNew CYWord("for"); }
802 | "in" { $$ = CYNew CYWord("in"); }
803 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
807 : IdentifierNoOf[pass] { $$ = $pass; }
808 | "break" { $$ = CYNew CYWord("break"); }
809 | "case" { $$ = CYNew CYWord("case"); }
810 | "catch" { $$ = CYNew CYWord("catch"); }
811 | "class" LexOf { $$ = CYNew CYWord("class"); }
812 | ";class" { $$ = CYNew CYWord("class"); }
813 | "const" { $$ = CYNew CYWord("const"); }
814 | "continue" { $$ = CYNew CYWord("continue"); }
815 | "debugger" { $$ = CYNew CYWord("debugger"); }
816 | "default" { $$ = CYNew CYWord("default"); }
817 | "delete" { $$ = CYNew CYWord("delete"); }
818 | "do" { $$ = CYNew CYWord("do"); }
819 | "else" { $$ = CYNew CYWord("else"); }
820 | "enum" { $$ = CYNew CYWord("enum"); }
821 | "export" { $$ = CYNew CYWord("export"); }
822 | "extends" { $$ = CYNew CYWord("extends"); }
823 | "false" { $$ = CYNew CYWord("false"); }
824 | "finally" { $$ = CYNew CYWord("finally"); }
825 | "function" LexOf { $$ = CYNew CYWord("function"); }
826 | "if" { $$ = CYNew CYWord("if"); }
827 | "import" { $$ = CYNew CYWord("import"); }
828 | "!in" { $$ = CYNew CYWord("in"); }
829 | "!of" { $$ = CYNew CYWord("of"); }
830 | "new" { $$ = CYNew CYWord("new"); }
831 | "null" { $$ = CYNew CYWord("null"); }
832 | "return" { $$ = CYNew CYWord("return"); }
833 | "super" { $$ = CYNew CYWord("super"); }
834 | "switch" { $$ = CYNew CYWord("switch"); }
835 | "this" { $$ = CYNew CYWord("this"); }
836 | "throw" { $$ = CYNew CYWord("throw"); }
837 | "true" { $$ = CYNew CYWord("true"); }
838 | "try" { $$ = CYNew CYWord("try"); }
839 | "typeof" { $$ = CYNew CYWord("typeof"); }
840 | "var" { $$ = CYNew CYWord("var"); }
841 | "void" { $$ = CYNew CYWord("void"); }
842 | "while" { $$ = CYNew CYWord("while"); }
843 | "with" { $$ = CYNew CYWord("with"); }
844 | "yield" { $$ = CYNew CYIdentifier("yield"); }
849 : Word[pass] { $$ = $pass; }
854 /* 11.8.1 Null Literals {{{ */
856 : "null" { $$ = CYNew CYNull(); }
859 /* 11.8.2 Boolean Literals {{{ */
861 : "true" { $$ = CYNew CYTrue(); }
862 | "false" { $$ = CYNew CYFalse(); }
865 /* 11.8.5 Regular Expression Literals {{{ */
866 RegularExpressionSlash
867 : "/" { $$ = false; }
868 | "/=" { $$ = true; }
871 RegularExpressionLiteral
872 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
876 /* 11.9 Automatic Semicolon Insertion {{{ */
878 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
886 : LexNewLineOrNot "\n"
891 : LexNewLineOrNot "\n" StrictSemi
892 | NewLineNot LexOf Terminator
897 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
902 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
907 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
911 /* 12.1 Identifiers {{{ */
913 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
914 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
918 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
919 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
920 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
924 : BindingIdentifier[pass] { $$ = $pass; }
925 | LexOf { $$ = NULL; }
929 : Identifier[pass] { $$ = $pass; }
930 | "yield" { $$ = CYNew CYIdentifier("yield"); }
934 : Identifier_[pass] { $$ = $pass; }
935 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
936 | "as" { $$ = CYNew CYIdentifier("as"); }
937 | "await" { $$ = CYNew CYIdentifier("await"); }
938 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
939 | "byte" { $$ = CYNew CYIdentifier("byte"); }
940 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
941 | "double" { $$ = CYNew CYIdentifier("double"); }
942 | "each" { $$ = CYNew CYIdentifier("each"); }
943 | "eval" { $$ = CYNew CYIdentifier("eval"); }
944 | "final" { $$ = CYNew CYIdentifier("final"); }
945 | "float" { $$ = CYNew CYIdentifier("float"); }
946 | "from" { $$ = CYNew CYIdentifier("from"); }
947 | "get" { $$ = CYNew CYIdentifier("get"); }
948 | "goto" { $$ = CYNew CYIdentifier("goto"); }
949 | "implements" { $$ = CYNew CYIdentifier("implements"); }
950 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
951 | "interface" { $$ = CYNew CYIdentifier("interface"); }
952 | "let" { $$ = CYNew CYIdentifier("let"); }
953 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
954 | "native" { $$ = CYNew CYIdentifier("native"); }
955 | "package" { $$ = CYNew CYIdentifier("package"); }
956 | "private" { $$ = CYNew CYIdentifier("private"); }
957 | "protected" { $$ = CYNew CYIdentifier("protected"); }
958 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
959 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
960 | "public" { $$ = CYNew CYIdentifier("public"); }
961 | "set" { $$ = CYNew CYIdentifier("set"); }
962 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
963 | "target" { $$ = CYNew CYIdentifier("target"); }
964 | "throws" { $$ = CYNew CYIdentifier("throws"); }
965 | "transient" { $$ = CYNew CYIdentifier("transient"); }
966 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
968 | "bool" { $$ = CYNew CYIdentifier("bool"); }
969 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
970 | "id" { $$ = CYNew CYIdentifier("id"); }
971 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
976 : IdentifierTypeNoOf[pass] { $$ = $pass; }
977 | "of" { $$ = CYNew CYIdentifier("of"); }
981 : IdentifierType[pass] { $$ = $pass; }
987 | "char" { $$ = CYNew CYIdentifier("char"); }
988 | "int" { $$ = CYNew CYIdentifier("int"); }
989 | "long" { $$ = CYNew CYIdentifier("long"); }
990 | "short" { $$ = CYNew CYIdentifier("short"); }
991 | "static" { $$ = CYNew CYIdentifier("static"); }
992 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
994 | "signed" { $$ = CYNew CYIdentifier("signed"); }
995 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
998 | "nil" { $$ = CYNew CYIdentifier("nil"); }
999 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1000 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1001 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1006 : IdentifierNoOf[pass] { $$ = $pass; }
1007 | "of" { $$ = CYNew CYIdentifier("of"); }
1008 | "!of" { $$ = CYNew CYIdentifier("of"); }
1011 /* 12.2 Primary Expression {{{ */
1013 : "this" { $$ = CYNew CYThis(); }
1014 | IdentifierReference[pass] { $$ = $pass; }
1015 | Literal[pass] { $$ = $pass; }
1016 | ArrayLiteral[pass] { $$ = $pass; }
1017 | ObjectLiteral[pass] { $$ = $pass; }
1018 | FunctionExpression[pass] { $$ = $pass; }
1019 | ClassExpression[pass] { $$ = $pass; }
1020 | GeneratorExpression[pass] { $$ = $pass; }
1021 | RegularExpressionLiteral[pass] { $$ = $pass; }
1022 | TemplateLiteral[pass] { $$ = $pass; }
1023 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1024 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1027 CoverParenthesizedExpressionAndArrowParameterList
1028 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1029 | "(" LexOf ")" { $$ = NULL; }
1030 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1031 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1034 /* 12.2.4 Literals {{{ */
1036 : NullLiteral[pass] { $$ = $pass; }
1037 | BooleanLiteral[pass] { $$ = $pass; }
1038 | NumericLiteral[pass] { $$ = $pass; }
1039 | StringLiteral[pass] { $$ = $pass; }
1042 /* 12.2.5 Array Initializer {{{ */
1044 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1048 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1049 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1050 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1054 : ElementList[pass] { $$ = $pass; }
1055 | LexOf { $$ = NULL; }
1058 /* 12.2.6 Object Initializer {{{ */
1060 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1063 PropertyDefinitionList_
1064 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1068 PropertyDefinitionList
1069 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1072 PropertyDefinitionListOpt
1073 : PropertyDefinitionList[properties] { $$ = $properties; }
1078 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1079 | CoverInitializedName[name] { CYNOT(@$); }
1080 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1081 | MethodDefinition[pass] { $$ = $pass; }
1085 : LiteralPropertyName[pass] { $$ = $pass; }
1086 | ComputedPropertyName[pass] { $$ = $pass; }
1090 : IdentifierName[pass] { $$ = $pass; }
1091 | StringLiteral[pass] { $$ = $pass; }
1092 | NumericLiteral[pass] { $$ = $pass; }
1095 ComputedPropertyName
1096 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1099 CoverInitializedName
1100 : IdentifierReference Initializer
1104 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1108 : Initializer[pass] { $$ = $pass; }
1112 /* 12.2.9 Template Literals {{{ */
1114 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1115 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1119 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1120 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1124 /* 12.3 Left-Hand-Side Expressions {{{ */
1126 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1127 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1128 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1129 | TemplateLiteral { CYNOT(@$); }
1133 : PrimaryExpression[pass] { $$ = $pass; }
1134 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1135 | SuperProperty[pass] { $$ = $pass; }
1136 | MetaProperty { CYNOT(@$); }
1137 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1141 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1142 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1150 : "new" "." "target"
1154 : MemberExpression[pass] { $$ = $pass; }
1155 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1159 : MemberExpression[pass] { $$ = $pass; }
1160 | CallExpression[pass] { $$ = $pass; }
1164 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1165 | SuperCall[pass] { $$ = $pass; }
1166 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1170 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1174 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1178 : "," ArgumentList[arguments] { $$ = $arguments; }
1183 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1184 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1188 : ArgumentList[pass] { $$ = $pass; }
1189 | LexOf { $$ = NULL; }
1193 : NewExpression[pass] { $$ = $pass; }
1194 | CallExpression[pass] { $$ = $pass; }
1197 LeftHandSideExpression
1198 : RubyBlockExpression[pass] { $$ = $pass; }
1199 | IndirectExpression[pass] { $$ = $pass; }
1202 /* 12.4 Postfix Expressions {{{ */
1204 : RubyBlockExpression[pass] { $$ = $pass; }
1205 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1206 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1209 /* 12.5 Unary Operators {{{ */
1211 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1212 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1213 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1214 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1215 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1216 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1217 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1218 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1219 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1223 : PostfixExpression[expression] { $$ = $expression; }
1224 | UnaryExpression_[pass] { $$ = $pass; }
1227 /* 12.6 Multiplicative Operators {{{ */
1228 MultiplicativeExpression
1229 : UnaryExpression[pass] { $$ = $pass; }
1230 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1231 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1232 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1235 /* 12.7 Additive Operators {{{ */
1237 : MultiplicativeExpression[pass] { $$ = $pass; }
1238 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1239 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1242 /* 12.8 Bitwise Shift Operators {{{ */
1244 : AdditiveExpression[pass] { $$ = $pass; }
1245 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1246 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1247 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1250 /* 12.9 Relational Operators {{{ */
1251 RelationalExpression
1252 : ShiftExpression[pass] { $$ = $pass; }
1253 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1254 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1255 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1256 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1257 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1258 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1261 /* 12.10 Equality Operators {{{ */
1263 : RelationalExpression[pass] { $$ = $pass; }
1264 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1265 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1266 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1267 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1270 /* 12.11 Binary Bitwise Operators {{{ */
1271 BitwiseANDExpression
1272 : EqualityExpression[pass] { $$ = $pass; }
1273 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1276 BitwiseXORExpression
1277 : BitwiseANDExpression[pass] { $$ = $pass; }
1278 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1282 : BitwiseXORExpression[pass] { $$ = $pass; }
1283 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1286 /* 12.12 Binary Logical Operators {{{ */
1287 LogicalANDExpression
1288 : BitwiseORExpression[pass] { $$ = $pass; }
1289 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1293 : LogicalANDExpression[pass] { $$ = $pass; }
1294 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1297 /* 12.13 Conditional Operator ( ? : ) {{{ */
1299 ConditionalExpressionClassic
1300 : LogicalORExpression[pass] { $$ = $pass; }
1301 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1305 ConditionalExpression
1306 : LogicalORExpression[pass] { $$ = $pass; }
1307 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1310 /* 12.14 Assignment Operators {{{ */
1311 LeftHandSideAssignment
1312 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1313 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1314 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1315 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1316 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1317 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1318 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1319 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1320 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1321 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1322 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1323 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1327 AssignmentExpressionClassic
1328 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1329 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1333 AssignmentExpression
1334 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1335 | LexOf YieldExpression[pass] { $$ = $pass; }
1336 | ArrowFunction[pass] { $$ = $pass; }
1337 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1340 AssignmentExpressionOpt
1341 : AssignmentExpression[pass] { $$ = $pass; }
1342 | LexOf { $$ = NULL; }
1345 /* 12.15 Comma Operator ( , ) {{{ */
1347 : AssignmentExpression[pass] { $$ = $pass; }
1348 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1352 : Expression[pass] { $$ = $pass; }
1353 | LexOf { $$ = NULL; }
1357 /* 13 Statements and Declarations {{{ */
1359 : BlockStatement[pass] { $$ = $pass; }
1360 | VariableStatement[pass] { $$ = $pass; }
1361 | EmptyStatement[pass] { $$ = $pass; }
1362 | IfStatement[pass] { $$ = $pass; }
1363 | BreakableStatement[pass] { $$ = $pass; }
1364 | ContinueStatement[pass] { $$ = $pass; }
1365 | BreakStatement[pass] { $$ = $pass; }
1366 | ReturnStatement[pass] { $$ = $pass; }
1367 | WithStatement[pass] { $$ = $pass; }
1368 | LabelledStatement[pass] { $$ = $pass; }
1369 | ThrowStatement[pass] { $$ = $pass; }
1370 | TryStatement[pass] { $$ = $pass; }
1371 | DebuggerStatement[pass] { $$ = $pass; }
1375 : LexOf Statement__[pass] { $$ = $pass; }
1376 | ExpressionStatement[pass] { $$ = $pass; }
1380 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1384 : HoistableDeclaration[pass] { $$ = $pass; }
1385 | ClassDeclaration[pass] { $$ = $pass; }
1389 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1390 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1393 HoistableDeclaration
1394 : FunctionDeclaration[pass] { $$ = $pass; }
1395 | GeneratorDeclaration[pass] { $$ = $pass; }
1399 : IterationStatement[pass] { $$ = $pass; }
1400 | SwitchStatement[pass] { $$ = $pass; }
1403 /* 13.2 Block {{{ */
1405 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1409 : "{" StatementListOpt[code] "}" { $$ = $code; }
1413 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1417 : StatementList[pass] { $$ = $pass; }
1418 | LexSetStatement LexLet LexOf { $$ = NULL; }
1422 : Statement[pass] { $$ = $pass; }
1423 | Declaration[pass] { $$ = $pass; }
1426 /* 13.3 Let and Const Declarations {{{ */
1428 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1432 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1436 : { CYMAP(_let__, _let_); }
1440 : { CYMAP(_of__, _of_); }
1444 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1448 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1449 | LexLet LexOf "const" { $$ = true; }
1453 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1458 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1462 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1463 | LexOf BindingPattern Initializer { CYNOT(@$); }
1466 /* 13.3.2 Variable Statement {{{ */
1468 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1472 : VariableStatement_[statement] Terminator { $$ = $statement; }
1475 VariableDeclarationList_
1476 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1480 VariableDeclarationList
1481 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1485 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1486 | LexOf BindingPattern Initializer { CYNOT(@$); }
1489 /* 13.3.3 Destructuring Binding Patterns {{{ */
1491 : ObjectBindingPattern
1492 | ArrayBindingPattern
1495 ObjectBindingPattern
1496 : "let {" BindingPropertyListOpt "}"
1500 : "let [" BindingElementListOpt "]"
1503 BindingPropertyList_
1504 : "," BindingPropertyListOpt
1509 : BindingProperty BindingPropertyList_
1512 BindingPropertyListOpt
1513 : BindingPropertyList
1518 : BindingElementOpt[element] "," BindingElementListOpt[next]
1519 | BindingRestElement[element]
1520 | BindingElement[element]
1523 BindingElementListOpt
1524 : BindingElementList[pass]
1530 | LexOf PropertyName ":" BindingElement
1534 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1535 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1539 : BindingElement[pass]
1544 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1548 : LexBind LexOf "..." BindingIdentifier
1551 /* 13.4 Empty Statement {{{ */
1553 : ";" { $$ = CYNew CYEmpty(); }
1556 /* 13.5 Expression Statement {{{ */
1557 ExpressionStatement_
1558 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1561 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1564 /* 13.6 The if Statement {{{ */
1566 : "else" Statement[false] { $$ = $false; }
1567 | %prec "if" { $$ = NULL; }
1571 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1574 /* 13.7 Iteration Statements {{{ */
1576 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1577 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1578 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1579 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1580 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1581 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1584 ForStatementInitializer
1585 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1586 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1587 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1588 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1591 ForInStatementInitializer
1592 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1593 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1594 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1595 | ForDeclaration[pass] { $$ = $pass; }
1599 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1603 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1604 | LexOf BindingPattern { CYNOT(@$); }
1607 /* 13.8 The continue Statement {{{ */
1609 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1610 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1613 /* 13.9 The break Statement {{{ */
1615 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1616 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1619 /* 13.10 The return Statement {{{ */
1621 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1622 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1625 /* 13.11 The with Statement {{{ */
1627 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1630 /* 13.12 The switch Statement {{{ */
1632 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1636 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1640 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1644 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1645 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1649 // XXX: the standard makes certain you can only have one of these
1651 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1654 /* 13.13 Labelled Statements {{{ */
1656 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1660 : Statement[pass] { $$ = $pass; }
1661 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1664 /* 13.14 The throw Statement {{{ */
1666 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1667 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1670 /* 13.15 The try Statement {{{ */
1672 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1673 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1674 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1678 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1682 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1686 : BindingIdentifier[pass] { $$ = $pass; }
1687 | LexOf BindingPattern { CYNOT(@$); }
1690 /* 13.16 The debugger Statement {{{ */
1692 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1696 /* 14.1 Function Definitions {{{ */
1698 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1702 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1705 StrictFormalParameters
1706 : FormalParameters[pass] { $$ = $pass; }
1710 : LexBind LexOf { $$ = NULL; }
1711 | FormalParameterList
1714 FormalParameterList_
1715 : "," FormalParameterList[parameters] { $$ = $parameters; }
1720 : FunctionRestParameter { CYNOT(@$); }
1721 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1724 FunctionRestParameter
1725 : BindingRestElement
1729 : BindingElement[pass] { $$ = $pass; }
1733 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1736 FunctionStatementList
1737 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1740 /* 14.2 Arrow Function Definitions {{{ */
1742 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1746 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1747 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1751 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1752 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1755 /* 14.3 Method Definitions {{{ */
1757 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1758 | GeneratorMethod[pass] { $$ = $pass; }
1759 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1760 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1763 PropertySetParameterList
1764 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1767 /* 14.4 Generator Function Definitions {{{ */
1769 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1772 GeneratorDeclaration
1773 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1777 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1781 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1785 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1786 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1787 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1788 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1791 /* 14.5 Class Definitions {{{ */
1793 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1797 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1801 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1805 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1809 : ClassHeritage[pass] { $$ = $pass; }
1810 | { $$ = CYNew CYClassTail(NULL); }
1823 : ClassElementListOpt ClassElement
1832 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1833 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1838 /* 15.1 Scripts {{{ */
1840 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1844 : StatementList[pass] { $$ = $pass; }
1848 : ScriptBody[pass] { $$ = $pass; }
1849 | LexSetStatement LexLet LexOf { $$ = NULL; }
1852 /* 15.2 Modules {{{ */
1854 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1858 : ModuleItemList[pass] { $$ = $pass; }
1862 : ModuleBody[pass] { $$ = $pass; }
1863 | LexSetStatement LexLet LexOf { $$ = NULL; }
1867 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1871 : ModuleItemList[pass] { $$ = $pass; }
1872 | LexSetStatement LexLet LexOf { $$ = NULL; }
1876 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1877 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1878 | StatementListItem[pass] { $$ = $pass; }
1881 /* 15.2.2 Imports {{{ */
1883 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1884 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1888 : ImportedDefaultBinding[default] { $$ = $default; }
1889 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1890 | LexOf NamedImports[pass] { $$ = $pass; }
1891 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1892 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1895 ImportedDefaultBinding
1896 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1900 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1904 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1908 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1912 : "," ImportsListOpt[pass] { $$ = $pass; }
1917 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1921 : ImportsList[pass] { $$ = $pass; }
1922 | LexOf { $$ = NULL; }
1926 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1927 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1931 : StringLiteral[pass] { $$ = $pass; }
1935 : BindingIdentifier[pass] { $$ = $pass; }
1938 /* 15.2.3 Exports {{{ */
1940 : "*" FromClause Terminator
1941 | ExportClause FromClause Terminator
1942 | ExportClause Terminator
1944 | "default" LexSetStatement LexOf HoistableDeclaration
1945 | "default" LexSetStatement LexOf ClassDeclaration
1946 | "default" LexSetStatement AssignmentExpression Terminator
1950 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1951 | "export" Declaration
1955 : ";{" ExportsListOpt "}"
1959 : "," ExportsListOpt
1964 : ExportSpecifier ExportsList_
1974 | IdentifierName "as" IdentifierName
1979 /* Cycript (C): Type Encoding {{{ */
1981 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1982 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1986 : { $$ = CYNew CYTypedIdentifier(@$); }
1990 : TypeSignifier[pass] { $$ = $pass; }
1991 | TypeSignifierNone[pass] { $$ = $pass; }
1995 : SuffixedTypeOpt[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1996 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1997 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1998 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
2002 : SuffixedType[pass] { $$ = $pass; }
2003 | TypeSignifierOpt[pass] { $$ = $pass; }
2007 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2011 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2012 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2015 TypeQualifierLeftOpt
2016 : TypeQualifierLeft[pass] { $$ = $pass; }
2021 : SuffixedType[pass] { $$ = $pass; }
2022 | PrefixedType[pass] { $$ = $pass; }
2023 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2024 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2027 TypeQualifierRightOpt
2028 : TypeQualifierRight[pass] { $$ = $pass; }
2029 | TypeSignifierOpt[pass] { $$ = $pass; }
2033 : "int" { $$ = CYNew CYTypeVariable("int"); }
2034 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
2035 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
2036 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
2037 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
2041 : IntegerType[pass] { $$ = $pass; }
2042 | { $$ = CYNew CYTypeVariable("int"); }
2046 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2051 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2052 | IntegerType[pass] { $$ = $pass; }
2053 | "char" { $$ = CYNew CYTypeVariable("char"); }
2054 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
2055 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2056 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2059 TypedIdentifierMaybe
2060 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2061 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2062 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2066 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2070 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2073 TypedIdentifierField
2074 : TypedIdentifierYes[pass] { $$ = $pass; }
2075 | 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; }
2078 TypedIdentifierEncoding
2079 : TypedIdentifierNo[pass] { $$ = $pass; }
2080 | 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; }
2083 TypedIdentifierDefinition
2084 : TypedIdentifierYes[pass] { $$ = $pass; }
2085 | 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; }
2089 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2095 /* Cycript (Objective-C): @class Declaration {{{ */
2097 /* XXX: why the hell did I choose MemberExpression? */
2098 : ":" MemberExpression[extends] { $$ = $extends; }
2102 ImplementationFieldListOpt
2103 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2108 : "+" { $$ = false; }
2109 | "-" { $$ = true; }
2113 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2114 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2118 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2121 MessageParameterList
2122 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2125 MessageParameterListOpt
2126 : MessageParameterList[pass] { $$ = $pass; }
2131 : MessageParameterList[pass] { $$ = $pass; }
2132 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2135 ClassMessageDeclaration
2136 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2139 ClassMessageDeclarationListOpt
2140 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2144 // XXX: this should be AssignmentExpressionNoRight
2146 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2150 : "," ClassProtocols[protocols] { $$ = $protocols; }
2154 ClassProtocolListOpt
2155 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2159 ImplementationStatement
2160 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2168 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2172 : ImplementationStatement[pass] { $$ = $pass; }
2173 | CategoryStatement[pass] { $$ = $pass; }
2176 /* Cycript (Objective-C): Send Message {{{ */
2178 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2183 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2184 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2188 : SelectorCall[pass] { $$ = $pass; }
2189 | VariadicCall[pass] { $$ = $pass; }
2193 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2197 : SelectorCall[pass] { $$ = $pass; }
2198 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2202 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2203 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2207 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2211 : SelectorExpression_[pass] { $$ = $pass; }
2212 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2215 SelectorExpressionOpt
2216 : SelectorExpression_[pass] { $$ = $pass; }
2221 : MessageExpression[pass] { $$ = $pass; }
2222 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2227 /* Cycript: @import Directive {{{ */
2229 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2230 | Word[part] { $$ = CYNew CYModule($part); }
2234 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2239 /* Cycript (Objective-C): Boxed Expressions {{{ */
2241 : NullLiteral[pass] { $$ = $pass; }
2242 | BooleanLiteral[pass] { $$ = $pass; }
2243 | NumericLiteral[pass] { $$ = $pass; }
2244 | StringLiteral[pass] { $$ = $pass; }
2245 | ArrayLiteral[pass] { $$ = $pass; }
2246 | ObjectLiteral[pass] { $$ = $pass; }
2247 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2248 | "YES" { $$ = CYNew CYTrue(); }
2249 | "NO" { $$ = CYNew CYFalse(); }
2253 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2254 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2255 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2256 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2257 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2258 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2261 /* Cycript (Objective-C): Block Expressions {{{ */
2263 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2266 /* Cycript (Objective-C): Instance Literals {{{ */
2268 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2274 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2276 : IndirectExpression[pass] { $$ = $pass; }
2280 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2284 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2288 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2289 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2290 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2293 /* Cycript (C): Lambda Expressions {{{ */
2295 : "," TypedParameterList[parameters] { $$ = $parameters; }
2300 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2303 TypedParameterListOpt
2304 : TypedParameterList[pass] { $$ = $pass; }
2305 | "void" { $$ = NULL; }
2310 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2313 /* Cycript (C): Structure Definitions {{{ */
2315 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2319 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2323 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2326 /* Cycript (C): Type Definitions {{{ */
2328 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2332 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2336 : TypeDefinition[pass] { $$ = $pass; }
2340 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2343 /* Cycript (C): extern "C" {{{ */
2345 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2349 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2350 | TypeDefinition[pass] { $$ = $pass; }
2353 ExternCStatementListOpt
2354 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2359 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2360 | ExternCStatement[pass] { $$ = $pass; }
2364 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2370 /* Lexer State {{{ */
2372 : { driver.PushCondition(CYDriver::RegExpCondition); }
2376 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2380 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2384 : { driver.PopCondition(); }
2388 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2392 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2395 /* Virtual Tokens {{{ */
2402 /* 8.1 Context Keywords {{{ */
2404 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2405 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2408 /* 8.3 XML Initializer Input Elements {{{ */
2410 : XMLComment { $$ = $1; }
2411 | XMLCDATA { $$ = $1; }
2412 | XMLPI { $$ = $1; }
2416 /* 11.1 Primary Expressions {{{ */
2418 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2419 | XMLInitilizer { $$ = $1; }
2420 | XMLListInitilizer { $$ = $1; }
2424 : AttributeIdentifier { $$ = $1; }
2425 | QualifiedIdentifier { $$ = $1; }
2426 | WildcardIdentifier { $$ = $1; }
2429 /* 11.1.1 Attribute Identifiers {{{ */
2431 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2435 : PropertySelector { $$ = $1; }
2436 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2440 : Identifier { $$ = CYNew CYSelector($1); }
2441 | WildcardIdentifier { $$ = $1; }
2444 /* 11.1.2 Qualified Identifiers {{{ */
2445 QualifiedIdentifier_
2446 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2447 | QualifiedIdentifier { $$ = $1; }
2451 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2454 /* 11.1.3 Wildcard Identifiers {{{ */
2456 : "*" { $$ = CYNew CYWildcard(); }
2459 /* 11.1.4 XML Initializer {{{ */
2461 : XMLMarkup { $$ = $1; }
2462 | XMLElement { $$ = $1; }
2466 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2467 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2471 : LexPushXMLTag XMLTagName XMLAttributes
2475 : "{" LexPushRegExp Expression LexPop "}"
2484 : XMLAttributes_ XMLAttribute
2489 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2490 | XMLAttributes_ XMLWhitespaceOpt
2499 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2503 : XMLExpression XMLElementContentOpt
2504 | XMLMarkup XMLElementContentOpt
2505 | XMLText XMLElementContentOpt
2506 | XMLElement XMLElementContentOpt
2509 XMLElementContentOpt
2514 /* 11.1.5 XMLList Initializer {{{ */
2516 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2520 /* 11.2 Left-Hand-Side Expressions {{{ */
2522 : Identifier { $$ = $1; }
2523 | PropertyIdentifier { $$ = $1; }
2527 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2528 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2529 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2532 /* 12.1 The default xml namespace Statement {{{ */
2533 /* XXX: DefaultXMLNamespaceStatement
2534 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2538 : DefaultXMLNamespaceStatement { $$ = $1; }
2543 /* JavaScript FTL: Array Comprehensions {{{ */
2545 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2549 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2552 /* JavaScript FTL: for each {{{ */
2554 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2558 /* JavaScript FTW: Array Comprehensions {{{ */
2560 : ArrayComprehension
2564 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2568 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2573 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2574 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2578 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2579 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2583 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2586 /* JavaScript FTW: Coalesce Operator {{{ */
2587 ConditionalExpression
2588 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2591 /* JavaScript FTW: Named Arguments {{{ */
2593 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2596 /* JavaScript FTW: Ruby Blocks {{{ */
2597 RubyProcParameterList_
2598 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2602 RubyProcParameterList
2603 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2604 | LexOf { $$ = NULL; }
2608 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2609 | "||" { $$ = NULL; }
2612 RubyProcParametersOpt
2613 : RubyProcParameters[pass] { $$ = $pass; }
2618 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2622 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2625 RubyBlockExpression_
2626 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2627 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2631 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2632 | RubyBlockExpression_[pass] { $$ = $pass; }
2638 bool CYDriver::Parse(CYMark mark) {
2640 CYLocal<CYPool> local(&pool_);
2641 cy::parser parser(*this);
2643 parser.set_debug_level(debug_);
2645 return parser.parse() != 0;
2648 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2652 CYDriver::Error error;
2653 error.warning_ = true;
2654 error.location_ = location;
2655 error.message_ = message;
2656 errors_.push_back(error);
2659 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2660 CYDriver::Error error;
2661 error.warning_ = false;
2662 error.location_ = location;
2663 error.message_ = message;
2664 driver.errors_.push_back(error);