1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 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
31 #define CYNew new(driver.pool_)
34 #include "ObjectiveC/Syntax.hpp"
38 #include "E4X/Syntax.hpp"
41 #include "Highlight.hpp"
44 %union { bool bool_; }
46 %union { CYMember *access_; }
47 %union { CYArgument *argument_; }
48 %union { CYAssignment *assignment_; }
49 %union { CYBinding *binding_; }
50 %union { CYBindings *bindings_; }
51 %union { CYBoolean *boolean_; }
52 %union { CYBraced *braced_; }
53 %union { CYClause *clause_; }
54 %union { cy::Syntax::Catch *catch_; }
55 %union { CYClassTail *classTail_; }
56 %union { CYComprehension *comprehension_; }
57 %union { CYElement *element_; }
58 %union { CYExpression *expression_; }
59 %union { CYFalse *false_; }
60 %union { CYVariable *variable_; }
61 %union { CYFinally *finally_; }
62 %union { CYForInitializer *for_; }
63 %union { CYForInInitializer *forin_; }
64 %union { CYFunctionParameter *functionParameter_; }
65 %union { CYIdentifier *identifier_; }
66 %union { CYImportSpecifier *import_; }
67 %union { CYInfix *infix_; }
68 %union { CYLiteral *literal_; }
69 %union { CYMethod *method_; }
70 %union { CYModule *module_; }
71 %union { CYNull *null_; }
72 %union { CYNumber *number_; }
73 %union { CYParenthetical *parenthetical_; }
74 %union { CYProperty *property_; }
75 %union { CYPropertyName *propertyName_; }
76 %union { CYTypeSigning signing_; }
77 %union { CYSpan *span_; }
78 %union { CYStatement *statement_; }
79 %union { CYString *string_; }
80 %union { CYTarget *target_; }
81 %union { CYThis *this_; }
82 %union { CYTrue *true_; }
83 %union { CYWord *word_; }
86 %union { CYTypeIntegral *integral_; }
87 %union { CYTypeStructField *structField_; }
88 %union { CYTypeModifier *modifier_; }
89 %union { CYTypeSpecifier *specifier_; }
90 %union { CYTypedFormal *typedFormal_; }
91 %union { CYTypedIdentifier *typedIdentifier_; }
92 %union { CYTypedParameter *typedParameter_; }
96 %union { CYObjCKeyValue *keyValue_; }
97 %union { CYImplementationField *implementationField_; }
98 %union { CYMessage *message_; }
99 %union { CYMessageParameter *messageParameter_; }
100 %union { CYProtocol *protocol_; }
101 %union { CYSelectorPart *selector_; }
105 %union { CYAttribute *attribute_; }
106 %union { CYPropertyIdentifier *propertyIdentifier_; }
107 %union { CYSelector *selector_; }
113 cy::parser::semantic_type semantic_;
114 hi::Value highlight_;
117 int cylex(YYSTYPE *, CYLocation *, void *);
125 typedef cy::parser::token tk;
127 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
128 driver.newline_ = false;
131 int token(cylex(&data, location, driver.scanner_));
132 *semantic = data.semantic_;
136 case tk::OpenBracket:
138 driver.in_.push(false);
142 if (driver.in_.top())
147 case tk::CloseBracket:
154 if (driver.yield_.top())
155 token = tk::_yield__;
159 driver.newline_ = true;
167 #define yylex_(semantic, location, driver) ({ \
169 if (driver.hold_ == cy::parser::empty_symbol) \
170 type = yytranslate_(cylex_(semantic, location, driver)); \
172 type = driver.hold_; \
173 driver.hold_ = cy::parser::empty_symbol; \
177 #define CYLEX() do if (yyla.empty()) { \
178 YYCDEBUG << "Mapping a token: "; \
179 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
180 YY_SYMBOL_PRINT("Next token is", yyla); \
183 #define CYMAP(to, from) do { \
185 if (yyla.type == yytranslate_(token::from)) \
186 yyla.type = yytranslate_(token::to); \
189 #define CYHLD(location, token) do { \
190 if (driver.hold_ != empty_symbol) \
191 CYERR(location, "unexpected hold"); \
192 driver.hold_ = yyla.type; \
193 yyla.type = yytranslate_(token); \
196 #define CYERR(location, message) do { \
197 error(location, message); \
201 #define CYEOK() do { \
203 driver.errors_.pop_back(); \
206 #define CYNOT(location) \
207 CYERR(location, "unimplemented feature")
209 #define CYMPT(location) do { \
210 if (!yyla.empty() && yyla.type_get() != yyeof_) \
211 CYERR(location, "unexpected lookahead"); \
221 @$.begin.filename = @$.end.filename = &driver.filename_;
223 switch (driver.mark_) {
225 driver.hold_ = yytranslate_(token::MarkScript);
228 driver.hold_ = yytranslate_(token::MarkModule);
236 %define api.location.type { CYLocation }
243 %param { CYDriver &driver }
245 /* Token Declarations {{{ */
251 %token XMLAttributeValue
253 %token XMLTagCharacters
259 %token LeftRight "<>"
260 %token LeftSlashRight "</>"
262 %token SlashRight "/>"
263 %token LeftSlash "</"
265 %token PeriodPeriod ".."
268 @begin E4X ObjectiveC
273 %token AmpersandAmpersand "&&"
274 %token AmpersandEqual "&="
276 %token CarrotEqual "^="
278 %token EqualEqual "=="
279 %token EqualEqualEqual "==="
280 %token EqualRight "=>"
281 %token Exclamation "!"
282 %token ExclamationEqual "!="
283 %token ExclamationEqualEqual "!=="
285 %token HyphenEqual "-="
286 %token HyphenHyphen "--"
287 %token HyphenRight "->"
289 %token LeftEqual "<="
291 %token LeftLeftEqual "<<="
293 %token PercentEqual "%="
295 %token PeriodPeriodPeriod "..."
297 %token PipeEqual "|="
300 %token PlusEqual "+="
303 %token RightEqual ">="
304 %token RightRight ">>"
305 %token RightRightEqual ">>="
306 %token RightRightRight ">>>"
307 %token RightRightRightEqual ">>>="
309 %token SlashEqual "/="
311 %token StarEqual "*="
315 %token ColonColon "::"
326 %token CloseParen ")"
329 %token OpenBrace_ ";{"
330 %token OpenBrace_let "let {"
331 %token CloseBrace "}"
333 %token OpenBracket "["
334 %token OpenBracket_let "let ["
335 %token CloseBracket "]"
337 %token At_error_ "@error"
340 %token At_class_ "@class"
344 %token _typedef_ "typedef"
345 %token _unsigned_ "unsigned"
346 %token _signed_ "signed"
347 %token _struct_ "struct"
348 %token _extern_ "extern"
352 %token At_encode_ "@encode"
356 %token At_implementation_ "@implementation"
357 %token At_import_ "@import"
358 %token At_end_ "@end"
359 %token At_selector_ "@selector"
360 %token At_null_ "@null"
361 %token At_YES_ "@YES"
363 %token At_true_ "@true"
364 %token At_false_ "@false"
369 %token _false_ "false"
374 %token _break_ "break"
376 %token _catch_ "catch"
377 %token _class_ "class"
378 %token _class__ ";class"
379 %token _const_ "const"
380 %token _continue_ "continue"
381 %token _debugger_ "debugger"
382 %token _default_ "default"
383 %token _delete_ "delete"
387 %token _export_ "export"
388 %token _extends_ "extends"
389 %token _finally_ "finally"
391 %token _function_ "function"
392 %token _function__ ";function"
394 %token _import_ "import"
397 %token _Infinity_ "Infinity"
398 %token _instanceof_ "instanceof"
400 %token _return_ "return"
401 %token _super_ "super"
402 %token _switch_ "switch"
403 %token _target_ "target"
405 %token _throw_ "throw"
407 %token _typeof_ "typeof"
410 %token _while_ "while"
413 %token _abstract_ "abstract"
414 %token _await_ "await"
415 %token _boolean_ "boolean"
418 %token _constructor_ "constructor"
419 %token _double_ "double"
421 %token _final_ "final"
422 %token _float_ "float"
426 %token _implements_ "implements"
428 %token ___int128_ "__int128"
429 %token _interface_ "interface"
433 %token _native_ "native"
434 %token _package_ "package"
435 %token _private_ "private"
436 %token _protected_ "protected"
437 %token ___proto___ "__proto__"
438 %token _prototype_ "prototype"
439 %token _public_ "public"
440 %token ___restrict_ "__restrict"
441 %token _restrict_ "restrict"
443 %token _short_ "short"
444 %token _static_ "static"
445 %token _synchronized_ "synchronized"
446 %token _throws_ "throws"
447 %token _transient_ "transient"
448 %token _typeid_ "typeid"
449 %token _volatile_ "volatile"
450 %token _yield_ "yield"
451 %token _yield__ "!yield"
453 %token _undefined_ "undefined"
469 %token _namespace_ "namespace"
474 %token YieldStar "yield *"
476 %token <identifier_> Identifier_
477 %token <number_> NumericLiteral
478 %token <string_> StringLiteral
479 %token <literal_> RegularExpressionLiteral_
481 %token <string_> NoSubstitutionTemplate
482 %token <string_> TemplateHead
483 %token <string_> TemplateMiddle
484 %token <string_> TemplateTail
486 %type <target_> AccessExpression
487 %type <expression_> AdditiveExpression
488 %type <argument_> ArgumentList_
489 %type <argument_> ArgumentList
490 %type <argument_> ArgumentListOpt
491 %type <argument_> Arguments
492 %type <target_> ArrayComprehension
493 %type <element_> ArrayElement
494 %type <literal_> ArrayLiteral
495 %type <expression_> ArrowFunction
496 %type <functionParameter_> ArrowParameters
497 %type <expression_> AssignmentExpression
498 %type <identifier_> BindingIdentifier
499 %type <identifier_> BindingIdentifierOpt
500 %type <bindings_> BindingList_
501 %type <bindings_> BindingList
502 %type <expression_> BitwiseANDExpression
503 %type <statement_> Block
504 %type <statement_> BlockStatement
505 %type <boolean_> BooleanLiteral
506 %type <binding_> BindingElement
507 %type <expression_> BitwiseORExpression
508 %type <expression_> BitwiseXORExpression
509 %type <target_> BracedExpression_
510 %type <target_> BracedExpression
511 %type <statement_> BreakStatement
512 %type <statement_> BreakableStatement
513 %type <expression_> CallExpression_
514 %type <target_> CallExpression
515 %type <clause_> CaseBlock
516 %type <clause_> CaseClause
517 %type <clause_> CaseClausesOpt
519 %type <identifier_> CatchParameter
520 %type <statement_> ClassDeclaration
521 %type <target_> ClassExpression
522 %type <classTail_> ClassHeritage
523 %type <classTail_> ClassHeritageOpt
524 %type <classTail_> ClassTail
525 %type <target_> Comprehension
526 %type <comprehension_> ComprehensionFor
527 %type <comprehension_> ComprehensionIf
528 %type <comprehension_> ComprehensionTail
529 %type <propertyName_> ComputedPropertyName
530 %type <expression_> ConditionalExpression
531 %type <statement_> ContinueStatement
532 %type <statement_> ConciseBody
533 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
534 %type <statement_> DebuggerStatement
535 %type <statement_> Declaration_
536 %type <statement_> Declaration
537 %type <clause_> DefaultClause
538 %type <element_> ElementList_
539 %type <element_> ElementList
540 %type <element_> ElementListOpt
541 %type <statement_> ElseStatementOpt
542 %type <for_> EmptyStatement
543 %type <expression_> EqualityExpression
544 %type <expression_> Expression
545 %type <expression_> ExpressionOpt
546 %type <for_> ExpressionStatement_
547 %type <statement_> ExpressionStatement
548 %type <statement_> ExternC
549 %type <statement_> ExternCStatement
550 %type <statement_> ExternCStatementListOpt
551 %type <finally_> Finally
552 %type <binding_> ForBinding
553 %type <forin_> ForDeclaration
554 %type <forin_> ForInStatementInitializer
555 %type <for_> ForStatementInitializer
556 %type <binding_> FormalParameter
557 %type <functionParameter_> FormalParameterList_
558 %type <functionParameter_> FormalParameterList
559 %type <functionParameter_> FormalParameters
560 %type <string_> FromClause
561 %type <statement_> FunctionBody
562 %type <statement_> FunctionDeclaration
563 %type <target_> FunctionExpression
564 %type <statement_> FunctionStatementList
565 %type <statement_> GeneratorBody
566 %type <statement_> GeneratorDeclaration
567 %type <target_> GeneratorExpression
568 %type <method_> GeneratorMethod
569 %type <statement_> HoistableDeclaration
570 %type <identifier_> Identifier
571 %type <identifier_> IdentifierNoOf
572 %type <identifier_> IdentifierType
573 %type <identifier_> IdentifierTypeNoOf
574 %type <identifier_> IdentifierTypeOpt
575 %type <word_> IdentifierName
576 %type <variable_> IdentifierReference
577 %type <statement_> IfStatement
578 %type <import_> ImportClause
579 %type <statement_> ImportDeclaration
580 %type <import_> ImportSpecifier
581 %type <identifier_> ImportedBinding
582 %type <import_> ImportedDefaultBinding
583 %type <import_> ImportsList_
584 %type <import_> ImportsList
585 %type <import_> ImportsListOpt
586 %type <target_> IndirectExpression
587 %type <expression_> Initializer
588 %type <expression_> InitializerOpt
589 %type <statement_> IterationStatement
590 %type <identifier_> LabelIdentifier
591 %type <statement_> LabelledItem
592 %type <statement_> LabelledStatement
593 %type <assignment_> LeftHandSideAssignment
594 %type <target_> LeftHandSideExpression
595 %type <bool_> LetOrConst
596 %type <binding_> LexicalBinding
597 %type <for_> LexicalDeclaration_
598 %type <statement_> LexicalDeclaration
599 %type <literal_> Literal
600 %type <propertyName_> LiteralPropertyName
601 %type <expression_> LogicalANDExpression
602 %type <expression_> LogicalORExpression
603 %type <access_> MemberAccess
604 %type <target_> MemberExpression
605 %type <method_> MethodDefinition
606 %type <statement_> ModuleBody
607 %type <statement_> ModuleBodyOpt
608 %type <statement_> ModuleItem
609 %type <statement_> ModuleItemList
610 %type <statement_> ModuleItemListOpt
611 %type <module_> ModulePath
612 %type <string_> ModuleSpecifier
613 %type <expression_> MultiplicativeExpression
614 %type <import_> NameSpaceImport
615 %type <import_> NamedImports
616 %type <target_> NewExpression
617 %type <null_> NullLiteral
618 %type <literal_> ObjectLiteral
619 %type <expression_> PostfixExpression
620 %type <target_> PrimaryExpression
621 %type <propertyName_> PropertyName
622 %type <property_> PropertyDefinition
623 %type <property_> PropertyDefinitionList_
624 %type <property_> PropertyDefinitionList
625 %type <property_> PropertyDefinitionListOpt
626 %type <functionParameter_> PropertySetParameterList
627 %type <literal_> RegularExpressionLiteral
628 %type <bool_> RegularExpressionSlash
629 %type <expression_> RelationalExpression
630 %type <statement_> ReturnStatement
631 %type <braced_> BracedParameter
632 %type <functionParameter_> RubyProcParameterList_
633 %type <functionParameter_> RubyProcParameterList
634 %type <functionParameter_> RubyProcParameters
635 %type <functionParameter_> RubyProcParametersOpt
636 %type <statement_> Script
637 %type <statement_> ScriptBody
638 %type <statement_> ScriptBodyOpt
639 %type <expression_> ShiftExpression
640 %type <binding_> SingleNameBinding
641 %type <statement_> Statement__
642 %type <statement_> Statement_
643 %type <statement_> Statement
644 %type <statement_> StatementList
645 %type <statement_> StatementListOpt
646 %type <statement_> StatementListItem
647 %type <functionParameter_> StrictFormalParameters
648 %type <target_> SuperCall
649 %type <target_> SuperProperty
650 %type <statement_> SwitchStatement
651 %type <target_> TemplateLiteral
652 %type <span_> TemplateSpans
653 %type <statement_> ThrowStatement
654 %type <statement_> TryStatement
655 %type <statement_> TypeDefinition
656 %type <expression_> UnaryExpression_
657 %type <expression_> UnaryExpression
658 %type <binding_> VariableDeclaration
659 %type <bindings_> VariableDeclarationList_
660 %type <bindings_> VariableDeclarationList
661 %type <for_> VariableStatement_
662 %type <statement_> VariableStatement
663 %type <statement_> WithStatement
665 %type <word_> WordNoUnary
667 %type <word_> WordOpt
669 %type <expression_> YieldExpression
672 %type <integral_> IntegerType
673 %type <integral_> IntegerTypeOpt
674 %type <typedIdentifier_> PrefixedType
675 %type <specifier_> PrimitiveType
676 %type <structField_> StructFieldListOpt
677 %type <typedIdentifier_> SuffixedType
678 %type <typedIdentifier_> SuffixedTypeOpt
679 %type <typedIdentifier_> TypeSignifier
680 %type <typedIdentifier_> TypeSignifierNone
681 %type <typedIdentifier_> TypeSignifierOpt
682 %type <signing_> TypeSigning
683 %type <modifier_> ParameterTail
684 %type <modifier_> TypeQualifierLeft
685 %type <modifier_> TypeQualifierLeftOpt
686 %type <typedIdentifier_> TypeQualifierRight
687 %type <typedIdentifier_> TypeQualifierRightOpt
688 %type <typedIdentifier_> TypedIdentifierDefinition
689 %type <typedIdentifier_> TypedIdentifierEncoding
690 %type <typedIdentifier_> TypedIdentifierField
691 %type <typedIdentifier_> TypedIdentifierMaybe
692 %type <typedIdentifier_> TypedIdentifierNo
693 %type <typedIdentifier_> TypedIdentifierYes
694 %type <typedFormal_> TypedParameterList_
695 %type <typedFormal_> TypedParameterList
696 %type <typedFormal_> TypedParameterListOpt
697 %type <typedParameter_> TypedParameters
701 %type <expression_> AssignmentExpressionClassic
702 %type <expression_> BoxableExpression
703 %type <statement_> CategoryStatement
704 %type <expression_> ClassSuperOpt
705 %type <expression_> ConditionalExpressionClassic
706 %type <message_> ClassMessageDeclaration
707 %type <message_> ClassMessageDeclarationListOpt
708 %type <protocol_> ClassProtocolListOpt
709 %type <protocol_> ClassProtocols
710 %type <protocol_> ClassProtocolsOpt
711 %type <implementationField_> ImplementationFieldListOpt
712 %type <statement_> ImplementationStatement
713 %type <keyValue_> KeyValuePairList_
714 %type <keyValue_> KeyValuePairList
715 %type <keyValue_> KeyValuePairListOpt
716 %type <target_> MessageExpression
717 %type <messageParameter_> MessageParameter
718 %type <messageParameter_> MessageParameters
719 %type <messageParameter_> MessageParameterList
720 %type <messageParameter_> MessageParameterListOpt
721 %type <bool_> MessageScope
722 %type <argument_> SelectorCall_
723 %type <argument_> SelectorCall
724 %type <selector_> SelectorExpression_
725 %type <selector_> SelectorExpression
726 %type <selector_> SelectorExpressionOpt
727 %type <argument_> SelectorList
728 %type <word_> SelectorWordOpt
729 %type <typedIdentifier_> TypeOpt
730 %type <argument_> VariadicCall
734 %type <propertyIdentifier_> PropertyIdentifier_
735 %type <selector_> PropertySelector_
736 %type <selector_> PropertySelector
737 %type <identifier_> QualifiedIdentifier_
738 %type <identifier_> QualifiedIdentifier
739 %type <identifier_> WildcardIdentifier
740 %type <identifier_> XMLComment
741 %type <identifier_> XMLCDATA
742 %type <identifier_> XMLElement
743 %type <identifier_> XMLElementContent
744 %type <identifier_> XMLMarkup
745 %type <identifier_> XMLPI
747 %type <attribute_> AttributeIdentifier
748 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
749 %type <expression_> PropertyIdentifier
750 %type <expression_> XMLListInitilizer
751 %type <expression_> XMLInitilizer
754 /* Token Priorities {{{ */
773 /* Lexer State {{{ */
774 LexPushInOn: { driver.in_.push(true); };
775 LexPushInOff: { driver.in_.push(false); };
776 LexPopIn: { driver.in_.pop(); };
778 LexPushReturnOn: { driver.return_.push(true); };
779 LexPopReturn: { driver.return_.pop(); };
780 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
782 LexPushSuperOn: { driver.super_.push(true); };
783 LexPushSuperOff: { driver.super_.push(false); };
784 LexPopSuper: { driver.super_.pop(); };
785 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
787 LexPushYieldOn: { driver.yield_.push(true); };
788 LexPushYieldOff: { driver.yield_.push(false); };
789 LexPopYield: { driver.yield_.pop(); };
792 : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } }
796 : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); }
800 : { CYMAP(YieldStar, Star); }
804 : { CYMAP(OpenBrace_, OpenBrace); }
808 : { CYMAP(_class__, _class_); }
812 : { CYMAP(_function__, _function_); }
816 : LexNoBrace LexNoClass LexNoFunction
819 /* Virtual Tokens {{{ */
825 /* 11.6 Names and Keywords {{{ */
827 : Word[pass] { $$ = $pass; }
828 | "for" { $$ = CYNew CYWord("for"); }
829 | "in" { $$ = CYNew CYWord("in"); }
830 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
834 : IdentifierNoOf[pass] { $$ = $pass; }
835 | "break" { $$ = CYNew CYWord("break"); }
836 | "case" { $$ = CYNew CYWord("case"); }
837 | "catch" { $$ = CYNew CYWord("catch"); }
838 | "class" LexOf { $$ = CYNew CYWord("class"); }
839 | ";class" { $$ = CYNew CYWord("class"); }
840 | "const" { $$ = CYNew CYWord("const"); }
841 | "continue" { $$ = CYNew CYWord("continue"); }
842 | "debugger" { $$ = CYNew CYWord("debugger"); }
843 | "default" { $$ = CYNew CYWord("default"); }
844 | "do" { $$ = CYNew CYWord("do"); }
845 | "else" { $$ = CYNew CYWord("else"); }
846 | "enum" { $$ = CYNew CYWord("enum"); }
847 | "export" { $$ = CYNew CYWord("export"); }
848 | "extends" { $$ = CYNew CYWord("extends"); }
849 | "false" { $$ = CYNew CYWord("false"); }
850 | "finally" { $$ = CYNew CYWord("finally"); }
851 | "function" LexOf { $$ = CYNew CYWord("function"); }
852 | "if" { $$ = CYNew CYWord("if"); }
853 | "import" { $$ = CYNew CYWord("import"); }
854 | "!in" { $$ = CYNew CYWord("in"); }
855 | "!of" { $$ = CYNew CYWord("of"); }
856 | "null" { $$ = CYNew CYWord("null"); }
857 | "return" { $$ = CYNew CYWord("return"); }
858 | "super" { $$ = CYNew CYWord("super"); }
859 | "switch" { $$ = CYNew CYWord("switch"); }
860 | "this" { $$ = CYNew CYWord("this"); }
861 | "throw" { $$ = CYNew CYWord("throw"); }
862 | "true" { $$ = CYNew CYWord("true"); }
863 | "try" { $$ = CYNew CYWord("try"); }
864 | "var" { $$ = CYNew CYWord("var"); }
865 | "while" { $$ = CYNew CYWord("while"); }
866 | "with" { $$ = CYNew CYWord("with"); }
870 : WordNoUnary[pass] { $$ = $pass; }
871 | "delete" { $$ = CYNew CYWord("delete"); }
872 | "typeof" { $$ = CYNew CYWord("typeof"); }
873 | "void" { $$ = CYNew CYWord("void"); }
874 | "yield" { $$ = CYNew CYIdentifier("yield"); }
879 : Word[pass] { $$ = $pass; }
884 /* 11.8.1 Null Literals {{{ */
886 : "null" { $$ = CYNew CYNull(); }
889 /* 11.8.2 Boolean Literals {{{ */
891 : "true" { $$ = CYNew CYTrue(); }
892 | "false" { $$ = CYNew CYFalse(); }
895 /* 11.8.5 Regular Expression Literals {{{ */
896 RegularExpressionSlash
897 : "/" { $$ = false; }
898 | "/=" { $$ = true; }
901 RegularExpressionLiteral
902 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
906 /* 11.9 Automatic Semicolon Insertion {{{ */
908 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
916 : LexNewLineOrNot "\n"
921 : LexNewLineOrNot "\n" StrictSemi
922 | NewLineNot LexOf Terminator
927 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
932 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
937 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
941 /* 12.1 Identifiers {{{ */
943 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
944 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
948 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
949 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
950 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
954 : BindingIdentifier[pass] { $$ = $pass; }
955 | LexOf { $$ = NULL; }
959 : Identifier[pass] { $$ = $pass; }
960 | "yield" { $$ = CYNew CYIdentifier("yield"); }
964 : Identifier_[pass] { $$ = $pass; }
965 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
966 | "as" { $$ = CYNew CYIdentifier("as"); }
967 | "await" { $$ = CYNew CYIdentifier("await"); }
968 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
969 | "byte" { $$ = CYNew CYIdentifier("byte"); }
970 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
971 | "double" { $$ = CYNew CYIdentifier("double"); }
972 | "each" { $$ = CYNew CYIdentifier("each"); }
973 | "eval" { $$ = CYNew CYIdentifier("eval"); }
974 | "final" { $$ = CYNew CYIdentifier("final"); }
975 | "float" { $$ = CYNew CYIdentifier("float"); }
976 | "from" { $$ = CYNew CYIdentifier("from"); }
977 | "get" { $$ = CYNew CYIdentifier("get"); }
978 | "goto" { $$ = CYNew CYIdentifier("goto"); }
979 | "implements" { $$ = CYNew CYIdentifier("implements"); }
980 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
981 | "interface" { $$ = CYNew CYIdentifier("interface"); }
982 | "let" { $$ = CYNew CYIdentifier("let"); }
983 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
984 | "native" { $$ = CYNew CYIdentifier("native"); }
985 | "package" { $$ = CYNew CYIdentifier("package"); }
986 | "private" { $$ = CYNew CYIdentifier("private"); }
987 | "protected" { $$ = CYNew CYIdentifier("protected"); }
988 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
989 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
990 | "public" { $$ = CYNew CYIdentifier("public"); }
991 | "set" { $$ = CYNew CYIdentifier("set"); }
992 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
993 | "target" { $$ = CYNew CYIdentifier("target"); }
994 | "throws" { $$ = CYNew CYIdentifier("throws"); }
995 | "transient" { $$ = CYNew CYIdentifier("transient"); }
996 | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
997 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
999 | "bool" { $$ = CYNew CYIdentifier("bool"); }
1000 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
1001 | "id" { $$ = CYNew CYIdentifier("id"); }
1002 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
1007 : IdentifierTypeNoOf[pass] { $$ = $pass; }
1008 | "of" { $$ = CYNew CYIdentifier("of"); }
1012 : IdentifierType[pass] { $$ = $pass; }
1017 : IdentifierTypeNoOf
1018 | "char" { $$ = CYNew CYIdentifier("char"); }
1019 | "int" { $$ = CYNew CYIdentifier("int"); }
1020 | "__int128" { $$ = CYNew CYIdentifier("__int128"); }
1021 | "long" { $$ = CYNew CYIdentifier("long"); }
1022 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1023 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1024 | "short" { $$ = CYNew CYIdentifier("short"); }
1025 | "static" { $$ = CYNew CYIdentifier("static"); }
1026 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1028 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1029 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1032 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1033 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1034 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1035 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1040 : IdentifierNoOf[pass] { $$ = $pass; }
1041 | "of" { $$ = CYNew CYIdentifier("of"); }
1042 | "!of" { $$ = CYNew CYIdentifier("of"); }
1045 /* 12.2 Primary Expression {{{ */
1047 : "this" { $$ = CYNew CYThis(); }
1048 | IdentifierReference[pass] { $$ = $pass; }
1049 | Literal[pass] { $$ = $pass; }
1050 | ArrayLiteral[pass] { $$ = $pass; }
1051 | ObjectLiteral[pass] { $$ = $pass; }
1052 | FunctionExpression[pass] { $$ = $pass; }
1053 | ClassExpression[pass] { $$ = $pass; }
1054 | GeneratorExpression[pass] { $$ = $pass; }
1055 | RegularExpressionLiteral[pass] { $$ = $pass; }
1056 | TemplateLiteral[pass] { $$ = $pass; }
1057 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1058 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1061 CoverParenthesizedExpressionAndArrowParameterList
1062 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1063 | "(" LexOf ")" { $$ = NULL; }
1064 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1065 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1068 /* 12.2.4 Literals {{{ */
1070 : NullLiteral[pass] { $$ = $pass; }
1071 | BooleanLiteral[pass] { $$ = $pass; }
1072 | NumericLiteral[pass] { $$ = $pass; }
1073 | StringLiteral[pass] { $$ = $pass; }
1076 /* 12.2.5 Array Initializer {{{ */
1078 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1082 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1083 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1087 : "," ElementListOpt[elements] { $$ = $elements; }
1092 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1093 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1097 : ElementList[pass] { $$ = $pass; }
1098 | LexOf { $$ = NULL; }
1101 /* 12.2.6 Object Initializer {{{ */
1103 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1106 PropertyDefinitionList_
1107 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1111 PropertyDefinitionList
1112 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1115 PropertyDefinitionListOpt
1116 : PropertyDefinitionList[properties] { $$ = $properties; }
1121 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1122 | CoverInitializedName[name] { CYNOT(@$); }
1123 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1124 | MethodDefinition[pass] { $$ = $pass; }
1128 : LiteralPropertyName[pass] { $$ = $pass; }
1129 | ComputedPropertyName[pass] { $$ = $pass; }
1133 : IdentifierName[pass] { $$ = $pass; }
1134 | StringLiteral[pass] { $$ = $pass; }
1135 | NumericLiteral[pass] { $$ = $pass; }
1138 ComputedPropertyName
1139 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1142 CoverInitializedName
1143 : IdentifierReference Initializer
1147 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1151 : Initializer[pass] { $$ = $pass; }
1155 /* 12.2.9 Template Literals {{{ */
1157 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1158 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1162 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1163 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1167 /* 12.3 Left-Hand-Side Expressions {{{ */
1169 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1170 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1171 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1172 | TemplateLiteral { CYNOT(@$); }
1176 : PrimaryExpression[pass] { $$ = $pass; }
1177 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1178 | SuperProperty[pass] { $$ = $pass; }
1179 | MetaProperty { CYNOT(@$); }
1180 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1184 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1185 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1193 : "new" "." "target"
1197 : MemberExpression[pass] { $$ = $pass; }
1198 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1202 : MemberExpression[pass] { $$ = $pass; }
1203 | CallExpression[pass] { $$ = $pass; }
1207 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1208 | SuperCall[pass] { $$ = $pass; }
1209 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1213 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1217 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1221 : "," ArgumentList[arguments] { $$ = $arguments; }
1226 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1227 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1231 : ArgumentList[pass] { $$ = $pass; }
1232 | LexOf { $$ = NULL; }
1236 : NewExpression[pass] { $$ = $pass; }
1237 | CallExpression[pass] { $$ = $pass; }
1240 LeftHandSideExpression
1241 : BracedExpression[pass] { $$ = $pass; }
1242 | IndirectExpression[pass] { $$ = $pass; }
1245 /* 12.4 Postfix Expressions {{{ */
1247 : BracedExpression[pass] { $$ = $pass; }
1248 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1249 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1252 /* 12.5 Unary Operators {{{ */
1254 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1255 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1256 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1257 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1258 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1259 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1260 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1261 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1262 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1266 : PostfixExpression[expression] { $$ = $expression; }
1267 | UnaryExpression_[pass] { $$ = $pass; }
1270 /* 12.6 Multiplicative Operators {{{ */
1271 MultiplicativeExpression
1272 : UnaryExpression[pass] { $$ = $pass; }
1273 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1274 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1275 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1278 /* 12.7 Additive Operators {{{ */
1280 : MultiplicativeExpression[pass] { $$ = $pass; }
1281 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1282 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1285 /* 12.8 Bitwise Shift Operators {{{ */
1287 : AdditiveExpression[pass] { $$ = $pass; }
1288 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1289 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1290 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1293 /* 12.9 Relational Operators {{{ */
1294 RelationalExpression
1295 : ShiftExpression[pass] { $$ = $pass; }
1296 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1297 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1298 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1299 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1300 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1301 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1304 /* 12.10 Equality Operators {{{ */
1306 : RelationalExpression[pass] { $$ = $pass; }
1307 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1308 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1309 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1310 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1313 /* 12.11 Binary Bitwise Operators {{{ */
1314 BitwiseANDExpression
1315 : EqualityExpression[pass] { $$ = $pass; }
1316 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1319 BitwiseXORExpression
1320 : BitwiseANDExpression[pass] { $$ = $pass; }
1321 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1325 : BitwiseXORExpression[pass] { $$ = $pass; }
1326 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1329 /* 12.12 Binary Logical Operators {{{ */
1330 LogicalANDExpression
1331 : BitwiseORExpression[pass] { $$ = $pass; }
1332 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1336 : LogicalANDExpression[pass] { $$ = $pass; }
1337 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1340 /* 12.13 Conditional Operator ( ? : ) {{{ */
1342 ConditionalExpressionClassic
1343 : LogicalORExpression[pass] { $$ = $pass; }
1344 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1348 ConditionalExpression
1349 : LogicalORExpression[pass] { $$ = $pass; }
1350 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1353 /* 12.14 Assignment Operators {{{ */
1354 LeftHandSideAssignment
1355 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1356 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1357 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1358 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1359 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1360 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1361 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1362 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1363 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1364 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1365 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1366 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1370 AssignmentExpressionClassic
1371 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1372 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1376 AssignmentExpression
1377 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1378 | LexOf YieldExpression[pass] { $$ = $pass; }
1379 | ArrowFunction[pass] { $$ = $pass; }
1380 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1383 /* 12.15 Comma Operator ( , ) {{{ */
1385 : AssignmentExpression[pass] { $$ = $pass; }
1386 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1390 : Expression[pass] { $$ = $pass; }
1391 | LexOf { $$ = NULL; }
1395 /* 13 Statements and Declarations {{{ */
1397 : BlockStatement[pass] { $$ = $pass; }
1398 | VariableStatement[pass] { $$ = $pass; }
1399 | EmptyStatement[pass] { $$ = $pass; }
1400 | IfStatement[pass] { $$ = $pass; }
1401 | BreakableStatement[pass] { $$ = $pass; }
1402 | ContinueStatement[pass] { $$ = $pass; }
1403 | BreakStatement[pass] { $$ = $pass; }
1404 | ReturnStatement[pass] { $$ = $pass; }
1405 | WithStatement[pass] { $$ = $pass; }
1406 | LabelledStatement[pass] { $$ = $pass; }
1407 | ThrowStatement[pass] { $$ = $pass; }
1408 | TryStatement[pass] { $$ = $pass; }
1409 | DebuggerStatement[pass] { $$ = $pass; }
1413 : LexOf Statement__[pass] { $$ = $pass; }
1414 | ExpressionStatement[pass] { $$ = $pass; }
1418 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1422 : HoistableDeclaration[pass] { $$ = $pass; }
1423 | ClassDeclaration[pass] { $$ = $pass; }
1427 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1428 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1431 HoistableDeclaration
1432 : FunctionDeclaration[pass] { $$ = $pass; }
1433 | GeneratorDeclaration[pass] { $$ = $pass; }
1437 : IterationStatement[pass] { $$ = $pass; }
1438 | SwitchStatement[pass] { $$ = $pass; }
1441 /* 13.2 Block {{{ */
1443 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1447 : "{" StatementListOpt[code] "}" { $$ = $code; }
1451 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1455 : StatementList[pass] { $$ = $pass; }
1456 | LexSetStatement LexLet LexOf { $$ = NULL; }
1460 : Statement[pass] { $$ = $pass; }
1461 | Declaration[pass] { $$ = $pass; }
1464 /* 13.3 Let and Const Declarations {{{ */
1466 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1470 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1474 : { CYMAP(_let__, _let_); }
1478 : { CYMAP(_of__, _of_); }
1482 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1486 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1487 | LexLet LexOf "const" { $$ = true; }
1491 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1496 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1500 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1501 | LexOf BindingPattern Initializer { CYNOT(@$); }
1504 /* 13.3.2 Variable Statement {{{ */
1506 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1510 : VariableStatement_[statement] Terminator { $$ = $statement; }
1513 VariableDeclarationList_
1514 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1518 VariableDeclarationList
1519 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1523 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1524 | LexOf BindingPattern Initializer { CYNOT(@$); }
1527 /* 13.3.3 Destructuring Binding Patterns {{{ */
1529 : ObjectBindingPattern
1530 | ArrayBindingPattern
1533 ObjectBindingPattern
1534 : "let {" BindingPropertyListOpt "}"
1538 : "let [" BindingElementListOpt "]"
1541 BindingPropertyList_
1542 : "," BindingPropertyListOpt
1547 : BindingProperty BindingPropertyList_
1550 BindingPropertyListOpt
1551 : BindingPropertyList
1556 : BindingElementOpt[element] "," BindingElementListOpt[next]
1557 | BindingRestElement[element]
1558 | BindingElement[element]
1561 BindingElementListOpt
1562 : BindingElementList[pass]
1568 | LexOf PropertyName ":" BindingElement
1572 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1573 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1577 : BindingElement[pass]
1582 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1586 : LexBind LexOf "..." BindingIdentifier
1589 /* 13.4 Empty Statement {{{ */
1591 : ";" { $$ = CYNew CYEmpty(); }
1594 /* 13.5 Expression Statement {{{ */
1595 ExpressionStatement_
1596 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1599 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1602 /* 13.6 The if Statement {{{ */
1604 : "else" Statement[false] { $$ = $false; }
1605 | %prec "if" { $$ = NULL; }
1609 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1612 /* 13.7 Iteration Statements {{{ */
1614 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1615 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1616 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1617 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1618 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1619 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1622 ForStatementInitializer
1623 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1624 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1625 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1626 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1629 ForInStatementInitializer
1630 : LexLet LexOf BracedExpression[pass] { $$ = $pass; }
1631 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1632 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1633 | ForDeclaration[pass] { $$ = $pass; }
1637 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1641 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1642 | LexOf BindingPattern { CYNOT(@$); }
1645 /* 13.8 The continue Statement {{{ */
1647 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1648 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1651 /* 13.9 The break Statement {{{ */
1653 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1654 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1657 /* 13.10 The return Statement {{{ */
1659 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1660 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1663 /* 13.11 The with Statement {{{ */
1665 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1668 /* 13.12 The switch Statement {{{ */
1670 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1674 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1678 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1682 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1683 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1687 // XXX: the standard makes certain you can only have one of these
1689 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1692 /* 13.13 Labelled Statements {{{ */
1694 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1698 : Statement[pass] { $$ = $pass; }
1699 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1702 /* 13.14 The throw Statement {{{ */
1704 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1705 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1708 /* 13.15 The try Statement {{{ */
1710 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1711 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1712 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1716 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1720 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1724 : BindingIdentifier[pass] { $$ = $pass; }
1725 | LexOf BindingPattern { CYNOT(@$); }
1728 /* 13.16 The debugger Statement {{{ */
1730 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1734 /* 14.1 Function Definitions {{{ */
1736 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1740 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1743 StrictFormalParameters
1744 : FormalParameters[pass] { $$ = $pass; }
1748 : LexBind LexOf { $$ = NULL; }
1749 | FormalParameterList
1752 FormalParameterList_
1753 : "," FormalParameterList[parameters] { $$ = $parameters; }
1758 : FunctionRestParameter { CYNOT(@$); }
1759 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1762 FunctionRestParameter
1763 : BindingRestElement
1767 : BindingElement[pass] { $$ = $pass; }
1771 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1774 FunctionStatementList
1775 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1778 /* 14.2 Arrow Function Definitions {{{ */
1780 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1784 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1785 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1789 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1790 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1793 /* 14.3 Method Definitions {{{ */
1795 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1796 | GeneratorMethod[pass] { $$ = $pass; }
1797 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1798 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1801 PropertySetParameterList
1802 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1805 /* 14.4 Generator Function Definitions {{{ */
1807 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1810 GeneratorDeclaration
1811 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1815 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1819 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1823 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1824 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield"
1825 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1826 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1829 /* 14.5 Class Definitions {{{ */
1831 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1835 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1839 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1843 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1847 : ClassHeritage[pass] { $$ = $pass; }
1848 | { $$ = CYNew CYClassTail(NULL); }
1861 : ClassElementListOpt ClassElement
1870 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1871 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1876 /* 15.1 Scripts {{{ */
1878 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1882 : StatementList[pass] { $$ = $pass; }
1886 : ScriptBody[pass] { $$ = $pass; }
1887 | LexSetStatement LexLet LexOf { $$ = NULL; }
1890 /* 15.2 Modules {{{ */
1892 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1896 : ModuleItemList[pass] { $$ = $pass; }
1900 : ModuleBody[pass] { $$ = $pass; }
1901 | LexSetStatement LexLet LexOf { $$ = NULL; }
1905 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1909 : ModuleItemList[pass] { $$ = $pass; }
1910 | LexSetStatement LexLet LexOf { $$ = NULL; }
1914 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1915 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1916 | StatementListItem[pass] { $$ = $pass; }
1919 /* 15.2.2 Imports {{{ */
1921 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1922 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1926 : ImportedDefaultBinding[default] { $$ = $default; }
1927 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1928 | LexOf NamedImports[pass] { $$ = $pass; }
1929 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1930 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1933 ImportedDefaultBinding
1934 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1938 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1942 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1946 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1950 : "," ImportsListOpt[pass] { $$ = $pass; }
1955 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1959 : ImportsList[pass] { $$ = $pass; }
1960 | LexOf { $$ = NULL; }
1964 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1965 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1969 : StringLiteral[pass] { $$ = $pass; }
1973 : BindingIdentifier[pass] { $$ = $pass; }
1976 /* 15.2.3 Exports {{{ */
1978 : "*" FromClause Terminator
1979 | ExportClause FromClause Terminator
1980 | ExportClause Terminator
1982 | "default" LexSetStatement LexOf HoistableDeclaration
1983 | "default" LexSetStatement LexOf ClassDeclaration
1984 | "default" LexSetStatement AssignmentExpression Terminator
1988 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1989 | "export" Declaration
1993 : ";{" ExportsListOpt "}"
1997 : "," ExportsListOpt
2002 : ExportSpecifier ExportsList_
2012 | IdentifierName "as" IdentifierName
2017 /* Cycript (C): Type Encoding {{{ */
2019 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
2020 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2024 : { $$ = CYNew CYTypedIdentifier(@$); }
2028 : TypeSignifier[pass] { $$ = $pass; }
2029 | TypeSignifierNone[pass] { $$ = $pass; }
2046 ParameterModifierOpt
2052 : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
2056 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2057 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2058 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2059 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2063 : SuffixedType[pass] { $$ = $pass; }
2064 | TypeSignifierOpt[pass] { $$ = $pass; }
2068 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2072 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2073 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2076 TypeQualifierLeftOpt
2077 : TypeQualifierLeft[pass] { $$ = $pass; }
2082 : SuffixedType[pass] { $$ = $pass; }
2083 | PrefixedType[pass] { $$ = $pass; }
2084 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2085 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2086 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2089 TypeQualifierRightOpt
2090 : TypeQualifierRight[pass] { $$ = $pass; }
2091 | TypeSignifierOpt[pass] { $$ = $pass; }
2095 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2096 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2097 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2098 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2099 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2103 : IntegerType[pass] { $$ = $pass; }
2104 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2108 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2113 : { $$ = CYTypeNeutral; }
2114 | "signed" { $$ = CYTypeSigned; }
2115 | "unsigned" { $$ = CYTypeUnsigned; }
2119 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2120 | IntegerType[pass] { $$ = $pass; }
2121 | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); }
2122 | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); }
2123 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2126 TypedIdentifierMaybe
2127 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2128 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2129 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2133 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2137 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2140 TypedIdentifierField
2141 : TypedIdentifierYes[pass] { $$ = $pass; }
2142 | 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; }
2145 TypedIdentifierEncoding
2146 : TypedIdentifierNo[pass] { $$ = $pass; }
2147 | 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; }
2150 TypedIdentifierDefinition
2151 : TypedIdentifierYes[pass] { $$ = $pass; }
2152 | 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; }
2156 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2162 /* Cycript (Objective-C): @class Declaration {{{ */
2164 /* XXX: why the hell did I choose MemberExpression? */
2165 : ":" MemberExpression[extends] { $$ = $extends; }
2169 ImplementationFieldListOpt
2170 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2175 : "+" { $$ = false; }
2176 | "-" { $$ = true; }
2180 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2181 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2185 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2188 MessageParameterList
2189 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2192 MessageParameterListOpt
2193 : MessageParameterList[pass] { $$ = $pass; }
2194 | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
2198 : MessageParameterList[pass] { $$ = $pass; }
2199 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2202 ClassMessageDeclaration
2203 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2206 ClassMessageDeclarationListOpt
2207 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2211 // XXX: this should be AssignmentExpressionNoRight
2213 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2217 : "," ClassProtocols[protocols] { $$ = $protocols; }
2221 ClassProtocolListOpt
2222 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2226 ImplementationStatement
2227 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2235 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2239 : ImplementationStatement[pass] { $$ = $pass; }
2240 | CategoryStatement[pass] { $$ = $pass; }
2243 /* Cycript (Objective-C): Send Message {{{ */
2245 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2250 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2251 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2255 : SelectorCall[pass] { $$ = $pass; }
2256 | VariadicCall[pass] { $$ = $pass; }
2260 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2264 : SelectorCall[pass] { $$ = $pass; }
2265 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2269 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2270 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2274 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2278 : SelectorExpression_[pass] { $$ = $pass; }
2279 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2282 SelectorExpressionOpt
2283 : SelectorExpression_[pass] { $$ = $pass; }
2288 : MessageExpression[pass] { $$ = $pass; }
2289 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2294 /* Cycript: @import Directive {{{ */
2296 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2297 | Word[part] { $$ = CYNew CYModule($part); }
2301 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2306 /* Cycript (Objective-C): Boxed Expressions {{{ */
2308 : NullLiteral[pass] { $$ = $pass; }
2309 | BooleanLiteral[pass] { $$ = $pass; }
2310 | NumericLiteral[pass] { $$ = $pass; }
2311 | StringLiteral[pass] { $$ = $pass; }
2312 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2313 | "YES" { $$ = CYNew CYTrue(); }
2314 | "NO" { $$ = CYNew CYFalse(); }
2318 : "," KeyValuePairListOpt[next] { $$ = $next; }
2322 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2326 : KeyValuePairList[pass] { $$ = $pass; }
2327 | LexOf { $$ = NULL; }
2331 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2332 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2333 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2335 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2336 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2337 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2338 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2339 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2342 /* Cycript (Objective-C): Block Expressions {{{ */
2344 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2347 /* Cycript (Objective-C): Instance Literals {{{ */
2349 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2355 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2357 : IndirectExpression[pass] { $$ = $pass; }
2361 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2365 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2369 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2370 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2371 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2374 /* Cycript (C): Lambda Expressions {{{ */
2376 : "," TypedParameterList[parameters] { $$ = $parameters; }
2377 | { $$ = CYNew CYTypedFormal(false); }
2381 : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
2382 | "..." { $$ = CYNew CYTypedFormal(true); }
2385 TypedParameterListOpt
2386 : TypedParameterList[pass] { $$ = $pass; }
2387 | "void" { $$ = CYNew CYTypedFormal(false); }
2388 | { $$ = CYNew CYTypedFormal(false); }
2392 : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
2396 : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2399 /* Cycript (C): Structure Definitions {{{ */
2401 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2405 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2409 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2412 /* Cycript (C): Type Definitions {{{ */
2414 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2418 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2422 : TypeDefinition[pass] { $$ = $pass; }
2426 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2429 /* Cycript (C): extern "C" {{{ */
2431 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2435 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternalDefinition(CYNew CYString("C"), $typed); }
2436 | TypeDefinition[pass] { $$ = $pass; }
2439 ExternCStatementListOpt
2440 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2445 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2446 | ExternCStatement[pass] { $$ = $pass; }
2450 : StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); }
2454 : "extern" NewLineNot ABI[abi] ExternC[pass] { $$ = $pass; }
2458 : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed); }
2464 /* Lexer State {{{ */
2466 : { driver.PushCondition(CYDriver::RegExpCondition); }
2470 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2474 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2478 : { driver.PopCondition(); }
2482 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2486 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2489 /* Virtual Tokens {{{ */
2496 /* 8.1 Context Keywords {{{ */
2498 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2499 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2502 /* 8.3 XML Initializer Input Elements {{{ */
2504 : XMLComment { $$ = $1; }
2505 | XMLCDATA { $$ = $1; }
2506 | XMLPI { $$ = $1; }
2510 /* 11.1 Primary Expressions {{{ */
2512 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2513 | XMLInitilizer { $$ = $1; }
2514 | XMLListInitilizer { $$ = $1; }
2518 : AttributeIdentifier { $$ = $1; }
2519 | QualifiedIdentifier { $$ = $1; }
2520 | WildcardIdentifier { $$ = $1; }
2523 /* 11.1.1 Attribute Identifiers {{{ */
2525 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2529 : PropertySelector { $$ = $1; }
2530 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2534 : Identifier { $$ = CYNew CYSelector($1); }
2535 | WildcardIdentifier { $$ = $1; }
2538 /* 11.1.2 Qualified Identifiers {{{ */
2539 QualifiedIdentifier_
2540 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2541 | QualifiedIdentifier { $$ = $1; }
2545 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2548 /* 11.1.3 Wildcard Identifiers {{{ */
2550 : "*" { $$ = CYNew CYWildcard(); }
2553 /* 11.1.4 XML Initializer {{{ */
2555 : XMLMarkup { $$ = $1; }
2556 | XMLElement { $$ = $1; }
2560 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2561 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2565 : LexPushXMLTag XMLTagName XMLAttributes
2569 : "{" LexPushRegExp Expression LexPop "}"
2578 : XMLAttributes_ XMLAttribute
2583 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2584 | XMLAttributes_ XMLWhitespaceOpt
2593 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2597 : XMLExpression XMLElementContentOpt
2598 | XMLMarkup XMLElementContentOpt
2599 | XMLText XMLElementContentOpt
2600 | XMLElement XMLElementContentOpt
2603 XMLElementContentOpt
2608 /* 11.1.5 XMLList Initializer {{{ */
2610 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2614 /* 11.2 Left-Hand-Side Expressions {{{ */
2616 : Identifier { $$ = $1; }
2617 | PropertyIdentifier { $$ = $1; }
2621 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2622 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2623 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2626 /* 12.1 The default xml namespace Statement {{{ */
2627 /* XXX: DefaultXMLNamespaceStatement
2628 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2632 : DefaultXMLNamespaceStatement { $$ = $1; }
2637 /* JavaScript FTL: Array Comprehensions {{{ */
2639 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2643 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2646 /* JavaScript FTL: for each {{{ */
2648 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2652 /* JavaScript FTW: Array Comprehensions {{{ */
2654 : ArrayComprehension
2658 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2662 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2667 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2668 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2672 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2673 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2677 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2680 /* JavaScript FTW: Named Arguments {{{ */
2682 : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2685 /* JavaScript FTW: Subscript Access {{{ */
2687 : "." "[" AssignmentExpression[property] "]" { $$ = CYNew CYSubscriptMember(NULL, $property); }
2691 /* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */
2693 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); }
2697 /* JavaScript FTW: Ruby Blocks {{{ */
2698 RubyProcParameterList_
2699 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2703 RubyProcParameterList
2704 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2705 | LexOf { $$ = NULL; }
2709 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2710 | "||" { $$ = NULL; }
2713 RubyProcParametersOpt
2714 : RubyProcParameters[pass] { $$ = $pass; }
2719 : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); }
2723 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2727 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2728 | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; }
2732 : BracedExpression_[pass] "\n" { $$ = $pass; }
2733 | BracedExpression_[pass] { $$ = $pass; }
2736 /* JavaScript FTW: Ruby Scopes {{{ */
2738 : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); }
2739 | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); }
2740 | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; }
2743 /* JavaScript FTW: Ruby Symbols {{{ */
2745 : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); }
2751 bool CYDriver::Parse(CYMark mark) {
2753 CYLocal<CYPool> local(&pool_);
2754 cy::parser parser(*this);
2756 parser.set_debug_level(debug_);
2758 return parser.parse() != 0;
2761 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2765 CYDriver::Error error;
2766 error.warning_ = true;
2767 error.location_ = location;
2768 error.message_ = message;
2769 errors_.push_back(error);
2772 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2773 CYDriver::Error error;
2774 error.warning_ = false;
2775 error.location_ = location;
2776 error.message_ = message;
2777 driver.errors_.push_back(error);