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 { CYTypeIntegral *integral_; }
85 %union { CYTypeStructField *structField_; }
86 %union { CYTypeModifier *modifier_; }
87 %union { CYTypeSpecifier *specifier_; }
88 %union { CYTypedIdentifier *typedIdentifier_; }
89 %union { CYTypedParameter *typedParameter_; }
93 %union { CYObjCKeyValue *keyValue_; }
94 %union { CYImplementationField *implementationField_; }
95 %union { CYMessage *message_; }
96 %union { CYMessageParameter *messageParameter_; }
97 %union { CYProtocol *protocol_; }
98 %union { CYSelectorPart *selector_; }
102 %union { CYAttribute *attribute_; }
103 %union { CYPropertyIdentifier *propertyIdentifier_; }
104 %union { CYSelector *selector_; }
110 cy::parser::semantic_type semantic_;
111 hi::Value highlight_;
114 int cylex(YYSTYPE *, CYLocation *, void *);
122 typedef cy::parser::token tk;
124 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
125 driver.newline_ = false;
128 int token(cylex(&data, location, driver.scanner_));
129 *semantic = data.semantic_;
133 case tk::OpenBracket:
135 driver.in_.push(false);
139 if (driver.in_.top())
144 case tk::CloseBracket:
151 if (driver.yield_.top())
152 token = tk::_yield__;
156 driver.newline_ = true;
164 #define yylex_(semantic, location, driver) ({ \
166 if (driver.hold_ == cy::parser::empty_symbol) \
167 type = yytranslate_(cylex_(semantic, location, driver)); \
169 type = driver.hold_; \
170 driver.hold_ = cy::parser::empty_symbol; \
174 #define CYLEX() do if (yyla.empty()) { \
175 YYCDEBUG << "Mapping a token: "; \
176 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
177 YY_SYMBOL_PRINT("Next token is", yyla); \
180 #define CYMAP(to, from) do { \
182 if (yyla.type == yytranslate_(token::from)) \
183 yyla.type = yytranslate_(token::to); \
186 #define CYERR(location, message) do { \
187 error(location, message); \
191 #define CYEOK() do { \
193 driver.errors_.pop_back(); \
196 #define CYNOT(location) \
197 CYERR(location, "unimplemented feature")
199 #define CYMPT(location) do { \
200 if (!yyla.empty() && yyla.type_get() != yyeof_) \
201 CYERR(location, "unexpected lookahead"); \
211 @$.begin.filename = @$.end.filename = &driver.filename_;
213 switch (driver.mark_) {
215 driver.hold_ = yytranslate_(token::MarkScript);
218 driver.hold_ = yytranslate_(token::MarkModule);
226 %define api.location.type { CYLocation }
233 %param { CYDriver &driver }
235 /* Token Declarations {{{ */
241 %token XMLAttributeValue
243 %token XMLTagCharacters
249 %token LeftRight "<>"
250 %token LeftSlashRight "</>"
252 %token SlashRight "/>"
253 %token LeftSlash "</"
255 %token ColonColon "::"
256 %token PeriodPeriod ".."
259 @begin E4X ObjectiveC
265 %token AmpersandAmpersand "&&"
266 %token AmpersandEqual "&="
268 %token CarrotEqual "^="
270 %token EqualEqual "=="
271 %token EqualEqualEqual "==="
272 %token EqualRight "=>"
273 %token Exclamation "!"
274 %token ExclamationEqual "!="
275 %token ExclamationEqualEqual "!=="
277 %token HyphenEqual "-="
278 %token HyphenHyphen "--"
279 %token HyphenRight "->"
281 %token LeftEqual "<="
283 %token LeftLeftEqual "<<="
285 %token PercentEqual "%="
287 %token PeriodPeriodPeriod "..."
289 %token PipeEqual "|="
292 %token PlusEqual "+="
295 %token RightEqual ">="
296 %token RightRight ">>"
297 %token RightRightEqual ">>="
298 %token RightRightRight ">>>"
299 %token RightRightRightEqual ">>>="
301 %token SlashEqual "/="
303 %token StarEqual "*="
316 %token CloseParen ")"
319 %token OpenBrace_ ";{"
320 %token OpenBrace_let "let {"
321 %token CloseBrace "}"
323 %token OpenBracket "["
324 %token OpenBracket_let "let ["
325 %token CloseBracket "]"
327 %token At_error_ "@error"
330 %token At_class_ "@class"
334 %token _typedef_ "typedef"
335 %token _unsigned_ "unsigned"
336 %token _signed_ "signed"
337 %token _struct_ "struct"
338 %token _extern_ "extern"
342 %token At_encode_ "@encode"
346 %token At_implementation_ "@implementation"
347 %token At_import_ "@import"
348 %token At_end_ "@end"
349 %token At_selector_ "@selector"
350 %token At_null_ "@null"
351 %token At_YES_ "@YES"
353 %token At_true_ "@true"
354 %token At_false_ "@false"
359 %token _false_ "false"
364 %token _break_ "break"
366 %token _catch_ "catch"
367 %token _class_ "class"
368 %token _class__ ";class"
369 %token _const_ "const"
370 %token _continue_ "continue"
371 %token _debugger_ "debugger"
372 %token _default_ "default"
373 %token _delete_ "delete"
377 %token _export_ "export"
378 %token _extends_ "extends"
379 %token _finally_ "finally"
381 %token _function_ "function"
382 %token _function__ ";function"
384 %token _import_ "import"
387 %token _Infinity_ "Infinity"
388 %token _instanceof_ "instanceof"
390 %token _return_ "return"
391 %token _super_ "super"
392 %token _switch_ "switch"
393 %token _target_ "target"
395 %token _throw_ "throw"
397 %token _typeof_ "typeof"
400 %token _while_ "while"
403 %token _abstract_ "abstract"
404 %token _await_ "await"
405 %token _boolean_ "boolean"
408 %token _constructor_ "constructor"
409 %token _double_ "double"
411 %token _final_ "final"
412 %token _float_ "float"
416 %token _implements_ "implements"
418 %token _interface_ "interface"
422 %token _native_ "native"
423 %token _package_ "package"
424 %token _private_ "private"
425 %token _protected_ "protected"
426 %token ___proto___ "__proto__"
427 %token _prototype_ "prototype"
428 %token _public_ "public"
429 %token ___restrict_ "__restrict"
430 %token _restrict_ "restrict"
432 %token _short_ "short"
433 %token _static_ "static"
434 %token _synchronized_ "synchronized"
435 %token _throws_ "throws"
436 %token _transient_ "transient"
437 %token _volatile_ "volatile"
438 %token _yield_ "yield"
439 %token _yield__ "!yield"
441 %token _undefined_ "undefined"
457 %token _namespace_ "namespace"
462 %token YieldStar "yield *"
464 %token <identifier_> Identifier_
465 %token <number_> NumericLiteral
466 %token <string_> StringLiteral
467 %token <literal_> RegularExpressionLiteral_
469 %token <string_> NoSubstitutionTemplate
470 %token <string_> TemplateHead
471 %token <string_> TemplateMiddle
472 %token <string_> TemplateTail
474 %type <target_> AccessExpression
475 %type <expression_> AdditiveExpression
476 %type <argument_> ArgumentList_
477 %type <argument_> ArgumentList
478 %type <argument_> ArgumentListOpt
479 %type <argument_> Arguments
480 %type <target_> ArrayComprehension
481 %type <element_> ArrayElement
482 %type <literal_> ArrayLiteral
483 %type <expression_> ArrowFunction
484 %type <functionParameter_> ArrowParameters
485 %type <expression_> AssignmentExpression
486 %type <identifier_> BindingIdentifier
487 %type <identifier_> BindingIdentifierOpt
488 %type <bindings_> BindingList_
489 %type <bindings_> BindingList
490 %type <expression_> BitwiseANDExpression
491 %type <statement_> Block
492 %type <statement_> BlockStatement
493 %type <boolean_> BooleanLiteral
494 %type <binding_> BindingElement
495 %type <expression_> BitwiseORExpression
496 %type <expression_> BitwiseXORExpression
497 %type <statement_> BreakStatement
498 %type <statement_> BreakableStatement
499 %type <expression_> CallExpression_
500 %type <target_> CallExpression
501 %type <clause_> CaseBlock
502 %type <clause_> CaseClause
503 %type <clause_> CaseClausesOpt
505 %type <identifier_> CatchParameter
506 %type <statement_> ClassDeclaration
507 %type <target_> ClassExpression
508 %type <classTail_> ClassHeritage
509 %type <classTail_> ClassHeritageOpt
510 %type <classTail_> ClassTail
511 %type <target_> Comprehension
512 %type <comprehension_> ComprehensionFor
513 %type <comprehension_> ComprehensionIf
514 %type <comprehension_> ComprehensionTail
515 %type <propertyName_> ComputedPropertyName
516 %type <expression_> ConditionalExpression
517 %type <statement_> ContinueStatement
518 %type <statement_> ConciseBody
519 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
520 %type <statement_> DebuggerStatement
521 %type <statement_> Declaration_
522 %type <statement_> Declaration
523 %type <clause_> DefaultClause
524 %type <element_> ElementList_
525 %type <element_> ElementList
526 %type <element_> ElementListOpt
527 %type <statement_> ElseStatementOpt
528 %type <for_> EmptyStatement
529 %type <expression_> EqualityExpression
530 %type <expression_> Expression
531 %type <expression_> ExpressionOpt
532 %type <for_> ExpressionStatement_
533 %type <statement_> ExpressionStatement
534 %type <statement_> ExternC
535 %type <statement_> ExternCStatement
536 %type <statement_> ExternCStatementListOpt
537 %type <finally_> Finally
538 %type <binding_> ForBinding
539 %type <forin_> ForDeclaration
540 %type <forin_> ForInStatementInitializer
541 %type <for_> ForStatementInitializer
542 %type <binding_> FormalParameter
543 %type <functionParameter_> FormalParameterList_
544 %type <functionParameter_> FormalParameterList
545 %type <functionParameter_> FormalParameters
546 %type <string_> FromClause
547 %type <statement_> FunctionBody
548 %type <statement_> FunctionDeclaration
549 %type <target_> FunctionExpression
550 %type <statement_> FunctionStatementList
551 %type <statement_> GeneratorBody
552 %type <statement_> GeneratorDeclaration
553 %type <target_> GeneratorExpression
554 %type <method_> GeneratorMethod
555 %type <statement_> HoistableDeclaration
556 %type <identifier_> Identifier
557 %type <identifier_> IdentifierNoOf
558 %type <identifier_> IdentifierType
559 %type <identifier_> IdentifierTypeNoOf
560 %type <identifier_> IdentifierTypeOpt
561 %type <word_> IdentifierName
562 %type <variable_> IdentifierReference
563 %type <statement_> IfStatement
564 %type <import_> ImportClause
565 %type <statement_> ImportDeclaration
566 %type <import_> ImportSpecifier
567 %type <identifier_> ImportedBinding
568 %type <import_> ImportedDefaultBinding
569 %type <import_> ImportsList_
570 %type <import_> ImportsList
571 %type <import_> ImportsListOpt
572 %type <target_> IndirectExpression
573 %type <expression_> Initializer
574 %type <expression_> InitializerOpt
575 %type <statement_> IterationStatement
576 %type <identifier_> LabelIdentifier
577 %type <statement_> LabelledItem
578 %type <statement_> LabelledStatement
579 %type <assignment_> LeftHandSideAssignment
580 %type <target_> LeftHandSideExpression
581 %type <bool_> LetOrConst
582 %type <binding_> LexicalBinding
583 %type <for_> LexicalDeclaration_
584 %type <statement_> LexicalDeclaration
585 %type <literal_> Literal
586 %type <propertyName_> LiteralPropertyName
587 %type <expression_> LogicalANDExpression
588 %type <expression_> LogicalORExpression
589 %type <access_> MemberAccess
590 %type <target_> MemberExpression
591 %type <method_> MethodDefinition
592 %type <statement_> ModuleBody
593 %type <statement_> ModuleBodyOpt
594 %type <statement_> ModuleItem
595 %type <statement_> ModuleItemList
596 %type <statement_> ModuleItemListOpt
597 %type <module_> ModulePath
598 %type <string_> ModuleSpecifier
599 %type <expression_> MultiplicativeExpression
600 %type <import_> NameSpaceImport
601 %type <import_> NamedImports
602 %type <target_> NewExpression
603 %type <null_> NullLiteral
604 %type <literal_> ObjectLiteral
605 %type <expression_> PostfixExpression
606 %type <target_> PrimaryExpression
607 %type <propertyName_> PropertyName
608 %type <property_> PropertyDefinition
609 %type <property_> PropertyDefinitionList_
610 %type <property_> PropertyDefinitionList
611 %type <property_> PropertyDefinitionListOpt
612 %type <functionParameter_> PropertySetParameterList
613 %type <literal_> RegularExpressionLiteral
614 %type <bool_> RegularExpressionSlash
615 %type <expression_> RelationalExpression
616 %type <statement_> ReturnStatement
617 %type <target_> RubyBlockExpression_
618 %type <target_> RubyBlockExpression
619 %type <rubyProc_> RubyProcExpression
620 %type <functionParameter_> RubyProcParameterList_
621 %type <functionParameter_> RubyProcParameterList
622 %type <functionParameter_> RubyProcParameters
623 %type <functionParameter_> RubyProcParametersOpt
624 %type <statement_> Script
625 %type <statement_> ScriptBody
626 %type <statement_> ScriptBodyOpt
627 %type <expression_> ShiftExpression
628 %type <binding_> SingleNameBinding
629 %type <statement_> Statement__
630 %type <statement_> Statement_
631 %type <statement_> Statement
632 %type <statement_> StatementList
633 %type <statement_> StatementListOpt
634 %type <statement_> StatementListItem
635 %type <functionParameter_> StrictFormalParameters
636 %type <target_> SuperCall
637 %type <target_> SuperProperty
638 %type <statement_> SwitchStatement
639 %type <target_> TemplateLiteral
640 %type <span_> TemplateSpans
641 %type <statement_> ThrowStatement
642 %type <statement_> TryStatement
643 %type <statement_> TypeDefinition
644 %type <expression_> UnaryExpression_
645 %type <expression_> UnaryExpression
646 %type <binding_> VariableDeclaration
647 %type <bindings_> VariableDeclarationList_
648 %type <bindings_> VariableDeclarationList
649 %type <for_> VariableStatement_
650 %type <statement_> VariableStatement
651 %type <statement_> WithStatement
654 %type <word_> WordOpt
656 %type <expression_> YieldExpression
659 %type <integral_> IntegerType
660 %type <integral_> IntegerTypeOpt
661 %type <typedIdentifier_> PrefixedType
662 %type <specifier_> PrimitiveType
663 %type <structField_> StructFieldListOpt
664 %type <typedIdentifier_> SuffixedType
665 %type <typedIdentifier_> SuffixedTypeOpt
666 %type <typedIdentifier_> TypeSignifier
667 %type <typedIdentifier_> TypeSignifierNone
668 %type <typedIdentifier_> TypeSignifierOpt
669 %type <modifier_> ParameterTail
670 %type <modifier_> TypeQualifierLeft
671 %type <modifier_> TypeQualifierLeftOpt
672 %type <typedIdentifier_> TypeQualifierRight
673 %type <typedIdentifier_> TypeQualifierRightOpt
674 %type <typedIdentifier_> TypedIdentifierDefinition
675 %type <typedIdentifier_> TypedIdentifierEncoding
676 %type <typedIdentifier_> TypedIdentifierField
677 %type <typedIdentifier_> TypedIdentifierMaybe
678 %type <typedIdentifier_> TypedIdentifierNo
679 %type <typedIdentifier_> TypedIdentifierYes
680 %type <typedParameter_> TypedParameterList_
681 %type <typedParameter_> TypedParameterList
682 %type <typedParameter_> TypedParameterListOpt
686 %type <expression_> AssignmentExpressionClassic
687 %type <expression_> BoxableExpression
688 %type <statement_> CategoryStatement
689 %type <expression_> ClassSuperOpt
690 %type <expression_> ConditionalExpressionClassic
691 %type <message_> ClassMessageDeclaration
692 %type <message_> ClassMessageDeclarationListOpt
693 %type <protocol_> ClassProtocolListOpt
694 %type <protocol_> ClassProtocols
695 %type <protocol_> ClassProtocolsOpt
696 %type <implementationField_> ImplementationFieldListOpt
697 %type <statement_> ImplementationStatement
698 %type <keyValue_> KeyValuePairList_
699 %type <keyValue_> KeyValuePairList
700 %type <keyValue_> KeyValuePairListOpt
701 %type <target_> MessageExpression
702 %type <messageParameter_> MessageParameter
703 %type <messageParameter_> MessageParameters
704 %type <messageParameter_> MessageParameterList
705 %type <messageParameter_> MessageParameterListOpt
706 %type <bool_> MessageScope
707 %type <argument_> SelectorCall_
708 %type <argument_> SelectorCall
709 %type <selector_> SelectorExpression_
710 %type <selector_> SelectorExpression
711 %type <selector_> SelectorExpressionOpt
712 %type <argument_> SelectorList
713 %type <word_> SelectorWordOpt
714 %type <typedIdentifier_> TypeOpt
715 %type <argument_> VariadicCall
719 %type <propertyIdentifier_> PropertyIdentifier_
720 %type <selector_> PropertySelector_
721 %type <selector_> PropertySelector
722 %type <identifier_> QualifiedIdentifier_
723 %type <identifier_> QualifiedIdentifier
724 %type <identifier_> WildcardIdentifier
725 %type <identifier_> XMLComment
726 %type <identifier_> XMLCDATA
727 %type <identifier_> XMLElement
728 %type <identifier_> XMLElementContent
729 %type <identifier_> XMLMarkup
730 %type <identifier_> XMLPI
732 %type <attribute_> AttributeIdentifier
733 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
734 %type <expression_> PropertyIdentifier
735 %type <expression_> XMLListInitilizer
736 %type <expression_> XMLInitilizer
739 /* Token Priorities {{{ */
755 /* Lexer State {{{ */
756 LexPushInOn: { driver.in_.push(true); };
757 LexPushInOff: { driver.in_.push(false); };
758 LexPopIn: { driver.in_.pop(); };
760 LexPushReturnOn: { driver.return_.push(true); };
761 LexPopReturn: { driver.return_.pop(); };
762 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
764 LexPushSuperOn: { driver.super_.push(true); };
765 LexPushSuperOff: { driver.super_.push(false); };
766 LexPopSuper: { driver.super_.pop(); };
767 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
769 LexPushYieldOn: { driver.yield_.push(true); };
770 LexPushYieldOff: { driver.yield_.push(false); };
771 LexPopYield: { driver.yield_.pop(); };
774 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
778 : { 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::__); }
782 : { CYMAP(YieldStar, Star); }
786 : { CYMAP(OpenBrace_, OpenBrace); }
790 : { CYMAP(_class__, _class_); }
794 : { CYMAP(_function__, _function_); }
798 : LexNoBrace LexNoClass LexNoFunction
801 /* Virtual Tokens {{{ */
807 /* 11.6 Names and Keywords {{{ */
809 : Word[pass] { $$ = $pass; }
810 | "for" { $$ = CYNew CYWord("for"); }
811 | "in" { $$ = CYNew CYWord("in"); }
812 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
816 : IdentifierNoOf[pass] { $$ = $pass; }
817 | "break" { $$ = CYNew CYWord("break"); }
818 | "case" { $$ = CYNew CYWord("case"); }
819 | "catch" { $$ = CYNew CYWord("catch"); }
820 | "class" LexOf { $$ = CYNew CYWord("class"); }
821 | ";class" { $$ = CYNew CYWord("class"); }
822 | "const" { $$ = CYNew CYWord("const"); }
823 | "continue" { $$ = CYNew CYWord("continue"); }
824 | "debugger" { $$ = CYNew CYWord("debugger"); }
825 | "default" { $$ = CYNew CYWord("default"); }
826 | "delete" { $$ = CYNew CYWord("delete"); }
827 | "do" { $$ = CYNew CYWord("do"); }
828 | "else" { $$ = CYNew CYWord("else"); }
829 | "enum" { $$ = CYNew CYWord("enum"); }
830 | "export" { $$ = CYNew CYWord("export"); }
831 | "extends" { $$ = CYNew CYWord("extends"); }
832 | "false" { $$ = CYNew CYWord("false"); }
833 | "finally" { $$ = CYNew CYWord("finally"); }
834 | "function" LexOf { $$ = CYNew CYWord("function"); }
835 | "if" { $$ = CYNew CYWord("if"); }
836 | "import" { $$ = CYNew CYWord("import"); }
837 | "!in" { $$ = CYNew CYWord("in"); }
838 | "!of" { $$ = CYNew CYWord("of"); }
839 | "new" { $$ = CYNew CYWord("new"); }
840 | "null" { $$ = CYNew CYWord("null"); }
841 | "return" { $$ = CYNew CYWord("return"); }
842 | "super" { $$ = CYNew CYWord("super"); }
843 | "switch" { $$ = CYNew CYWord("switch"); }
844 | "this" { $$ = CYNew CYWord("this"); }
845 | "throw" { $$ = CYNew CYWord("throw"); }
846 | "true" { $$ = CYNew CYWord("true"); }
847 | "try" { $$ = CYNew CYWord("try"); }
848 | "typeof" { $$ = CYNew CYWord("typeof"); }
849 | "var" { $$ = CYNew CYWord("var"); }
850 | "void" { $$ = CYNew CYWord("void"); }
851 | "while" { $$ = CYNew CYWord("while"); }
852 | "with" { $$ = CYNew CYWord("with"); }
853 | "yield" { $$ = CYNew CYIdentifier("yield"); }
858 : Word[pass] { $$ = $pass; }
863 /* 11.8.1 Null Literals {{{ */
865 : "null" { $$ = CYNew CYNull(); }
868 /* 11.8.2 Boolean Literals {{{ */
870 : "true" { $$ = CYNew CYTrue(); }
871 | "false" { $$ = CYNew CYFalse(); }
874 /* 11.8.5 Regular Expression Literals {{{ */
875 RegularExpressionSlash
876 : "/" { $$ = false; }
877 | "/=" { $$ = true; }
880 RegularExpressionLiteral
881 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
885 /* 11.9 Automatic Semicolon Insertion {{{ */
887 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
895 : LexNewLineOrNot "\n"
900 : LexNewLineOrNot "\n" StrictSemi
901 | NewLineNot LexOf Terminator
906 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
911 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
916 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
920 /* 12.1 Identifiers {{{ */
922 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
923 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
927 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
928 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
929 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
933 : BindingIdentifier[pass] { $$ = $pass; }
934 | LexOf { $$ = NULL; }
938 : Identifier[pass] { $$ = $pass; }
939 | "yield" { $$ = CYNew CYIdentifier("yield"); }
943 : Identifier_[pass] { $$ = $pass; }
944 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
945 | "as" { $$ = CYNew CYIdentifier("as"); }
946 | "await" { $$ = CYNew CYIdentifier("await"); }
947 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
948 | "byte" { $$ = CYNew CYIdentifier("byte"); }
949 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
950 | "double" { $$ = CYNew CYIdentifier("double"); }
951 | "each" { $$ = CYNew CYIdentifier("each"); }
952 | "eval" { $$ = CYNew CYIdentifier("eval"); }
953 | "final" { $$ = CYNew CYIdentifier("final"); }
954 | "float" { $$ = CYNew CYIdentifier("float"); }
955 | "from" { $$ = CYNew CYIdentifier("from"); }
956 | "get" { $$ = CYNew CYIdentifier("get"); }
957 | "goto" { $$ = CYNew CYIdentifier("goto"); }
958 | "implements" { $$ = CYNew CYIdentifier("implements"); }
959 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
960 | "interface" { $$ = CYNew CYIdentifier("interface"); }
961 | "let" { $$ = CYNew CYIdentifier("let"); }
962 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
963 | "native" { $$ = CYNew CYIdentifier("native"); }
964 | "package" { $$ = CYNew CYIdentifier("package"); }
965 | "private" { $$ = CYNew CYIdentifier("private"); }
966 | "protected" { $$ = CYNew CYIdentifier("protected"); }
967 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
968 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
969 | "public" { $$ = CYNew CYIdentifier("public"); }
970 | "set" { $$ = CYNew CYIdentifier("set"); }
971 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
972 | "target" { $$ = CYNew CYIdentifier("target"); }
973 | "throws" { $$ = CYNew CYIdentifier("throws"); }
974 | "transient" { $$ = CYNew CYIdentifier("transient"); }
975 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
977 | "bool" { $$ = CYNew CYIdentifier("bool"); }
978 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
979 | "id" { $$ = CYNew CYIdentifier("id"); }
980 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
985 : IdentifierTypeNoOf[pass] { $$ = $pass; }
986 | "of" { $$ = CYNew CYIdentifier("of"); }
990 : IdentifierType[pass] { $$ = $pass; }
996 | "char" { $$ = CYNew CYIdentifier("char"); }
997 | "int" { $$ = CYNew CYIdentifier("int"); }
998 | "long" { $$ = CYNew CYIdentifier("long"); }
999 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1000 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1001 | "short" { $$ = CYNew CYIdentifier("short"); }
1002 | "static" { $$ = CYNew CYIdentifier("static"); }
1003 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1005 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1006 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1009 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1010 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1011 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1012 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1017 : IdentifierNoOf[pass] { $$ = $pass; }
1018 | "of" { $$ = CYNew CYIdentifier("of"); }
1019 | "!of" { $$ = CYNew CYIdentifier("of"); }
1022 /* 12.2 Primary Expression {{{ */
1024 : "this" { $$ = CYNew CYThis(); }
1025 | IdentifierReference[pass] { $$ = $pass; }
1026 | Literal[pass] { $$ = $pass; }
1027 | ArrayLiteral[pass] { $$ = $pass; }
1028 | ObjectLiteral[pass] { $$ = $pass; }
1029 | FunctionExpression[pass] { $$ = $pass; }
1030 | ClassExpression[pass] { $$ = $pass; }
1031 | GeneratorExpression[pass] { $$ = $pass; }
1032 | RegularExpressionLiteral[pass] { $$ = $pass; }
1033 | TemplateLiteral[pass] { $$ = $pass; }
1034 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1035 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1038 CoverParenthesizedExpressionAndArrowParameterList
1039 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1040 | "(" LexOf ")" { $$ = NULL; }
1041 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1042 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1045 /* 12.2.4 Literals {{{ */
1047 : NullLiteral[pass] { $$ = $pass; }
1048 | BooleanLiteral[pass] { $$ = $pass; }
1049 | NumericLiteral[pass] { $$ = $pass; }
1050 | StringLiteral[pass] { $$ = $pass; }
1053 /* 12.2.5 Array Initializer {{{ */
1055 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1059 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1060 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1064 : "," ElementListOpt[elements] { $$ = $elements; }
1069 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1070 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1074 : ElementList[pass] { $$ = $pass; }
1075 | LexOf { $$ = NULL; }
1078 /* 12.2.6 Object Initializer {{{ */
1080 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1083 PropertyDefinitionList_
1084 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1088 PropertyDefinitionList
1089 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1092 PropertyDefinitionListOpt
1093 : PropertyDefinitionList[properties] { $$ = $properties; }
1098 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1099 | CoverInitializedName[name] { CYNOT(@$); }
1100 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1101 | MethodDefinition[pass] { $$ = $pass; }
1105 : LiteralPropertyName[pass] { $$ = $pass; }
1106 | ComputedPropertyName[pass] { $$ = $pass; }
1110 : IdentifierName[pass] { $$ = $pass; }
1111 | StringLiteral[pass] { $$ = $pass; }
1112 | NumericLiteral[pass] { $$ = $pass; }
1115 ComputedPropertyName
1116 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1119 CoverInitializedName
1120 : IdentifierReference Initializer
1124 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1128 : Initializer[pass] { $$ = $pass; }
1132 /* 12.2.9 Template Literals {{{ */
1134 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1135 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1139 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1140 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1144 /* 12.3 Left-Hand-Side Expressions {{{ */
1146 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1147 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1148 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1149 | TemplateLiteral { CYNOT(@$); }
1153 : PrimaryExpression[pass] { $$ = $pass; }
1154 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1155 | SuperProperty[pass] { $$ = $pass; }
1156 | MetaProperty { CYNOT(@$); }
1157 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1161 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1162 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1170 : "new" "." "target"
1174 : MemberExpression[pass] { $$ = $pass; }
1175 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1179 : MemberExpression[pass] { $$ = $pass; }
1180 | CallExpression[pass] { $$ = $pass; }
1184 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1185 | SuperCall[pass] { $$ = $pass; }
1186 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1190 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1194 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1198 : "," ArgumentList[arguments] { $$ = $arguments; }
1203 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1204 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1208 : ArgumentList[pass] { $$ = $pass; }
1209 | LexOf { $$ = NULL; }
1213 : NewExpression[pass] { $$ = $pass; }
1214 | CallExpression[pass] { $$ = $pass; }
1217 LeftHandSideExpression
1218 : RubyBlockExpression[pass] { $$ = $pass; }
1219 | IndirectExpression[pass] { $$ = $pass; }
1222 /* 12.4 Postfix Expressions {{{ */
1224 : RubyBlockExpression[pass] { $$ = $pass; }
1225 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1226 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1229 /* 12.5 Unary Operators {{{ */
1231 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1232 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1233 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1234 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1235 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1236 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1237 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1238 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1239 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1243 : PostfixExpression[expression] { $$ = $expression; }
1244 | UnaryExpression_[pass] { $$ = $pass; }
1247 /* 12.6 Multiplicative Operators {{{ */
1248 MultiplicativeExpression
1249 : UnaryExpression[pass] { $$ = $pass; }
1250 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1251 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1252 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1255 /* 12.7 Additive Operators {{{ */
1257 : MultiplicativeExpression[pass] { $$ = $pass; }
1258 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1259 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1262 /* 12.8 Bitwise Shift Operators {{{ */
1264 : AdditiveExpression[pass] { $$ = $pass; }
1265 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1266 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1267 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1270 /* 12.9 Relational Operators {{{ */
1271 RelationalExpression
1272 : ShiftExpression[pass] { $$ = $pass; }
1273 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1274 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1275 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1276 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1277 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1278 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1281 /* 12.10 Equality Operators {{{ */
1283 : RelationalExpression[pass] { $$ = $pass; }
1284 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1285 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1286 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1287 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1290 /* 12.11 Binary Bitwise Operators {{{ */
1291 BitwiseANDExpression
1292 : EqualityExpression[pass] { $$ = $pass; }
1293 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1296 BitwiseXORExpression
1297 : BitwiseANDExpression[pass] { $$ = $pass; }
1298 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1302 : BitwiseXORExpression[pass] { $$ = $pass; }
1303 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1306 /* 12.12 Binary Logical Operators {{{ */
1307 LogicalANDExpression
1308 : BitwiseORExpression[pass] { $$ = $pass; }
1309 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1313 : LogicalANDExpression[pass] { $$ = $pass; }
1314 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1317 /* 12.13 Conditional Operator ( ? : ) {{{ */
1319 ConditionalExpressionClassic
1320 : LogicalORExpression[pass] { $$ = $pass; }
1321 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1325 ConditionalExpression
1326 : LogicalORExpression[pass] { $$ = $pass; }
1327 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1330 /* 12.14 Assignment Operators {{{ */
1331 LeftHandSideAssignment
1332 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1333 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1334 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1335 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1336 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1337 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1338 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1339 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1340 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1341 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1342 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1343 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1347 AssignmentExpressionClassic
1348 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1349 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1353 AssignmentExpression
1354 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1355 | LexOf YieldExpression[pass] { $$ = $pass; }
1356 | ArrowFunction[pass] { $$ = $pass; }
1357 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1360 /* 12.15 Comma Operator ( , ) {{{ */
1362 : AssignmentExpression[pass] { $$ = $pass; }
1363 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1367 : Expression[pass] { $$ = $pass; }
1368 | LexOf { $$ = NULL; }
1372 /* 13 Statements and Declarations {{{ */
1374 : BlockStatement[pass] { $$ = $pass; }
1375 | VariableStatement[pass] { $$ = $pass; }
1376 | EmptyStatement[pass] { $$ = $pass; }
1377 | IfStatement[pass] { $$ = $pass; }
1378 | BreakableStatement[pass] { $$ = $pass; }
1379 | ContinueStatement[pass] { $$ = $pass; }
1380 | BreakStatement[pass] { $$ = $pass; }
1381 | ReturnStatement[pass] { $$ = $pass; }
1382 | WithStatement[pass] { $$ = $pass; }
1383 | LabelledStatement[pass] { $$ = $pass; }
1384 | ThrowStatement[pass] { $$ = $pass; }
1385 | TryStatement[pass] { $$ = $pass; }
1386 | DebuggerStatement[pass] { $$ = $pass; }
1390 : LexOf Statement__[pass] { $$ = $pass; }
1391 | ExpressionStatement[pass] { $$ = $pass; }
1395 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1399 : HoistableDeclaration[pass] { $$ = $pass; }
1400 | ClassDeclaration[pass] { $$ = $pass; }
1404 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1405 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1408 HoistableDeclaration
1409 : FunctionDeclaration[pass] { $$ = $pass; }
1410 | GeneratorDeclaration[pass] { $$ = $pass; }
1414 : IterationStatement[pass] { $$ = $pass; }
1415 | SwitchStatement[pass] { $$ = $pass; }
1418 /* 13.2 Block {{{ */
1420 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1424 : "{" StatementListOpt[code] "}" { $$ = $code; }
1428 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1432 : StatementList[pass] { $$ = $pass; }
1433 | LexSetStatement LexLet LexOf { $$ = NULL; }
1437 : Statement[pass] { $$ = $pass; }
1438 | Declaration[pass] { $$ = $pass; }
1441 /* 13.3 Let and Const Declarations {{{ */
1443 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1447 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1451 : { CYMAP(_let__, _let_); }
1455 : { CYMAP(_of__, _of_); }
1459 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1463 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1464 | LexLet LexOf "const" { $$ = true; }
1468 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1473 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1477 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1478 | LexOf BindingPattern Initializer { CYNOT(@$); }
1481 /* 13.3.2 Variable Statement {{{ */
1483 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1487 : VariableStatement_[statement] Terminator { $$ = $statement; }
1490 VariableDeclarationList_
1491 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1495 VariableDeclarationList
1496 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1500 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1501 | LexOf BindingPattern Initializer { CYNOT(@$); }
1504 /* 13.3.3 Destructuring Binding Patterns {{{ */
1506 : ObjectBindingPattern
1507 | ArrayBindingPattern
1510 ObjectBindingPattern
1511 : "let {" BindingPropertyListOpt "}"
1515 : "let [" BindingElementListOpt "]"
1518 BindingPropertyList_
1519 : "," BindingPropertyListOpt
1524 : BindingProperty BindingPropertyList_
1527 BindingPropertyListOpt
1528 : BindingPropertyList
1533 : BindingElementOpt[element] "," BindingElementListOpt[next]
1534 | BindingRestElement[element]
1535 | BindingElement[element]
1538 BindingElementListOpt
1539 : BindingElementList[pass]
1545 | LexOf PropertyName ":" BindingElement
1549 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1550 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1554 : BindingElement[pass]
1559 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1563 : LexBind LexOf "..." BindingIdentifier
1566 /* 13.4 Empty Statement {{{ */
1568 : ";" { $$ = CYNew CYEmpty(); }
1571 /* 13.5 Expression Statement {{{ */
1572 ExpressionStatement_
1573 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1576 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1579 /* 13.6 The if Statement {{{ */
1581 : "else" Statement[false] { $$ = $false; }
1582 | %prec "if" { $$ = NULL; }
1586 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1589 /* 13.7 Iteration Statements {{{ */
1591 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1592 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1593 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1594 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1595 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1596 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1599 ForStatementInitializer
1600 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1601 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1602 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1603 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1606 ForInStatementInitializer
1607 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1608 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1609 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1610 | ForDeclaration[pass] { $$ = $pass; }
1614 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1618 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1619 | LexOf BindingPattern { CYNOT(@$); }
1622 /* 13.8 The continue Statement {{{ */
1624 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1625 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1628 /* 13.9 The break Statement {{{ */
1630 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1631 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1634 /* 13.10 The return Statement {{{ */
1636 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1637 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1640 /* 13.11 The with Statement {{{ */
1642 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1645 /* 13.12 The switch Statement {{{ */
1647 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1651 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1655 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1659 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1660 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1664 // XXX: the standard makes certain you can only have one of these
1666 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1669 /* 13.13 Labelled Statements {{{ */
1671 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1675 : Statement[pass] { $$ = $pass; }
1676 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1679 /* 13.14 The throw Statement {{{ */
1681 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1682 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1685 /* 13.15 The try Statement {{{ */
1687 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1688 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1689 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1693 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1697 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1701 : BindingIdentifier[pass] { $$ = $pass; }
1702 | LexOf BindingPattern { CYNOT(@$); }
1705 /* 13.16 The debugger Statement {{{ */
1707 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1711 /* 14.1 Function Definitions {{{ */
1713 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1717 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1720 StrictFormalParameters
1721 : FormalParameters[pass] { $$ = $pass; }
1725 : LexBind LexOf { $$ = NULL; }
1726 | FormalParameterList
1729 FormalParameterList_
1730 : "," FormalParameterList[parameters] { $$ = $parameters; }
1735 : FunctionRestParameter { CYNOT(@$); }
1736 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1739 FunctionRestParameter
1740 : BindingRestElement
1744 : BindingElement[pass] { $$ = $pass; }
1748 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1751 FunctionStatementList
1752 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1755 /* 14.2 Arrow Function Definitions {{{ */
1757 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1761 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1762 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1766 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1767 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1770 /* 14.3 Method Definitions {{{ */
1772 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1773 | GeneratorMethod[pass] { $$ = $pass; }
1774 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1775 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1778 PropertySetParameterList
1779 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1782 /* 14.4 Generator Function Definitions {{{ */
1784 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1787 GeneratorDeclaration
1788 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1792 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1796 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1800 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1801 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1802 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1803 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1806 /* 14.5 Class Definitions {{{ */
1808 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1812 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1816 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1820 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1824 : ClassHeritage[pass] { $$ = $pass; }
1825 | { $$ = CYNew CYClassTail(NULL); }
1838 : ClassElementListOpt ClassElement
1847 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1848 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1853 /* 15.1 Scripts {{{ */
1855 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1859 : StatementList[pass] { $$ = $pass; }
1863 : ScriptBody[pass] { $$ = $pass; }
1864 | LexSetStatement LexLet LexOf { $$ = NULL; }
1867 /* 15.2 Modules {{{ */
1869 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1873 : ModuleItemList[pass] { $$ = $pass; }
1877 : ModuleBody[pass] { $$ = $pass; }
1878 | LexSetStatement LexLet LexOf { $$ = NULL; }
1882 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1886 : ModuleItemList[pass] { $$ = $pass; }
1887 | LexSetStatement LexLet LexOf { $$ = NULL; }
1891 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1892 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1893 | StatementListItem[pass] { $$ = $pass; }
1896 /* 15.2.2 Imports {{{ */
1898 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1899 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1903 : ImportedDefaultBinding[default] { $$ = $default; }
1904 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1905 | LexOf NamedImports[pass] { $$ = $pass; }
1906 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1907 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1910 ImportedDefaultBinding
1911 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1915 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1919 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1923 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1927 : "," ImportsListOpt[pass] { $$ = $pass; }
1932 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1936 : ImportsList[pass] { $$ = $pass; }
1937 | LexOf { $$ = NULL; }
1941 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1942 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1946 : StringLiteral[pass] { $$ = $pass; }
1950 : BindingIdentifier[pass] { $$ = $pass; }
1953 /* 15.2.3 Exports {{{ */
1955 : "*" FromClause Terminator
1956 | ExportClause FromClause Terminator
1957 | ExportClause Terminator
1959 | "default" LexSetStatement LexOf HoistableDeclaration
1960 | "default" LexSetStatement LexOf ClassDeclaration
1961 | "default" LexSetStatement AssignmentExpression Terminator
1965 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1966 | "export" Declaration
1970 : ";{" ExportsListOpt "}"
1974 : "," ExportsListOpt
1979 : ExportSpecifier ExportsList_
1989 | IdentifierName "as" IdentifierName
1994 /* Cycript (C): Type Encoding {{{ */
1996 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1997 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2001 : { $$ = CYNew CYTypedIdentifier(@$); }
2005 : TypeSignifier[pass] { $$ = $pass; }
2006 | TypeSignifierNone[pass] { $$ = $pass; }
2023 ParameterModifierOpt
2029 : TypedParameterListOpt[parameters] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($parameters); }
2033 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2034 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2035 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2036 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2040 : SuffixedType[pass] { $$ = $pass; }
2041 | TypeSignifierOpt[pass] { $$ = $pass; }
2045 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2049 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2050 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2053 TypeQualifierLeftOpt
2054 : TypeQualifierLeft[pass] { $$ = $pass; }
2059 : SuffixedType[pass] { $$ = $pass; }
2060 | PrefixedType[pass] { $$ = $pass; }
2061 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2062 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2063 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2066 TypeQualifierRightOpt
2067 : TypeQualifierRight[pass] { $$ = $pass; }
2068 | TypeSignifierOpt[pass] { $$ = $pass; }
2072 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2073 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2074 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2075 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2076 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2080 : IntegerType[pass] { $$ = $pass; }
2081 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2085 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2090 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2091 | IntegerType[pass] { $$ = $pass; }
2092 | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
2093 | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
2094 | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
2095 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2098 TypedIdentifierMaybe
2099 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2100 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2101 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2105 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2109 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2112 TypedIdentifierField
2113 : TypedIdentifierYes[pass] { $$ = $pass; }
2114 | 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; }
2117 TypedIdentifierEncoding
2118 : TypedIdentifierNo[pass] { $$ = $pass; }
2119 | 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; }
2122 TypedIdentifierDefinition
2123 : TypedIdentifierYes[pass] { $$ = $pass; }
2124 | 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; }
2128 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2134 /* Cycript (Objective-C): @class Declaration {{{ */
2136 /* XXX: why the hell did I choose MemberExpression? */
2137 : ":" MemberExpression[extends] { $$ = $extends; }
2141 ImplementationFieldListOpt
2142 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2147 : "+" { $$ = false; }
2148 | "-" { $$ = true; }
2152 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2153 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2157 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2160 MessageParameterList
2161 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2164 MessageParameterListOpt
2165 : MessageParameterList[pass] { $$ = $pass; }
2170 : MessageParameterList[pass] { $$ = $pass; }
2171 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2174 ClassMessageDeclaration
2175 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2178 ClassMessageDeclarationListOpt
2179 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2183 // XXX: this should be AssignmentExpressionNoRight
2185 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2189 : "," ClassProtocols[protocols] { $$ = $protocols; }
2193 ClassProtocolListOpt
2194 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2198 ImplementationStatement
2199 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2207 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2211 : ImplementationStatement[pass] { $$ = $pass; }
2212 | CategoryStatement[pass] { $$ = $pass; }
2215 /* Cycript (Objective-C): Send Message {{{ */
2217 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2222 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2223 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2227 : SelectorCall[pass] { $$ = $pass; }
2228 | VariadicCall[pass] { $$ = $pass; }
2232 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2236 : SelectorCall[pass] { $$ = $pass; }
2237 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2241 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2242 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2246 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2250 : SelectorExpression_[pass] { $$ = $pass; }
2251 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2254 SelectorExpressionOpt
2255 : SelectorExpression_[pass] { $$ = $pass; }
2260 : MessageExpression[pass] { $$ = $pass; }
2261 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2266 /* Cycript: @import Directive {{{ */
2268 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2269 | Word[part] { $$ = CYNew CYModule($part); }
2273 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2278 /* Cycript (Objective-C): Boxed Expressions {{{ */
2280 : NullLiteral[pass] { $$ = $pass; }
2281 | BooleanLiteral[pass] { $$ = $pass; }
2282 | NumericLiteral[pass] { $$ = $pass; }
2283 | StringLiteral[pass] { $$ = $pass; }
2284 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2285 | "YES" { $$ = CYNew CYTrue(); }
2286 | "NO" { $$ = CYNew CYFalse(); }
2290 : "," KeyValuePairListOpt[next] { $$ = $next; }
2294 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2298 : KeyValuePairList[pass] { $$ = $pass; }
2299 | LexOf { $$ = NULL; }
2303 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2304 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2305 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2307 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2308 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2309 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2310 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2311 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2314 /* Cycript (Objective-C): Block Expressions {{{ */
2316 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2319 /* Cycript (Objective-C): Instance Literals {{{ */
2321 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2327 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2329 : IndirectExpression[pass] { $$ = $pass; }
2333 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2337 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2341 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2342 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2343 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2346 /* Cycript (C): Lambda Expressions {{{ */
2348 : "," TypedParameterList[parameters] { $$ = $parameters; }
2353 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2356 TypedParameterListOpt
2357 : TypedParameterList[pass] { $$ = $pass; }
2358 | "void" { $$ = NULL; }
2363 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2366 /* Cycript (C): Structure Definitions {{{ */
2368 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2372 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2376 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2379 /* Cycript (C): Type Definitions {{{ */
2381 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2385 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2389 : TypeDefinition[pass] { $$ = $pass; }
2393 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2396 /* Cycript (C): extern "C" {{{ */
2398 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2402 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2403 | TypeDefinition[pass] { $$ = $pass; }
2406 ExternCStatementListOpt
2407 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2412 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2413 | ExternCStatement[pass] { $$ = $pass; }
2417 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2423 /* Lexer State {{{ */
2425 : { driver.PushCondition(CYDriver::RegExpCondition); }
2429 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2433 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2437 : { driver.PopCondition(); }
2441 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2445 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2448 /* Virtual Tokens {{{ */
2455 /* 8.1 Context Keywords {{{ */
2457 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2458 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2461 /* 8.3 XML Initializer Input Elements {{{ */
2463 : XMLComment { $$ = $1; }
2464 | XMLCDATA { $$ = $1; }
2465 | XMLPI { $$ = $1; }
2469 /* 11.1 Primary Expressions {{{ */
2471 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2472 | XMLInitilizer { $$ = $1; }
2473 | XMLListInitilizer { $$ = $1; }
2477 : AttributeIdentifier { $$ = $1; }
2478 | QualifiedIdentifier { $$ = $1; }
2479 | WildcardIdentifier { $$ = $1; }
2482 /* 11.1.1 Attribute Identifiers {{{ */
2484 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2488 : PropertySelector { $$ = $1; }
2489 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2493 : Identifier { $$ = CYNew CYSelector($1); }
2494 | WildcardIdentifier { $$ = $1; }
2497 /* 11.1.2 Qualified Identifiers {{{ */
2498 QualifiedIdentifier_
2499 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2500 | QualifiedIdentifier { $$ = $1; }
2504 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2507 /* 11.1.3 Wildcard Identifiers {{{ */
2509 : "*" { $$ = CYNew CYWildcard(); }
2512 /* 11.1.4 XML Initializer {{{ */
2514 : XMLMarkup { $$ = $1; }
2515 | XMLElement { $$ = $1; }
2519 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2520 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2524 : LexPushXMLTag XMLTagName XMLAttributes
2528 : "{" LexPushRegExp Expression LexPop "}"
2537 : XMLAttributes_ XMLAttribute
2542 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2543 | XMLAttributes_ XMLWhitespaceOpt
2552 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2556 : XMLExpression XMLElementContentOpt
2557 | XMLMarkup XMLElementContentOpt
2558 | XMLText XMLElementContentOpt
2559 | XMLElement XMLElementContentOpt
2562 XMLElementContentOpt
2567 /* 11.1.5 XMLList Initializer {{{ */
2569 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2573 /* 11.2 Left-Hand-Side Expressions {{{ */
2575 : Identifier { $$ = $1; }
2576 | PropertyIdentifier { $$ = $1; }
2580 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2581 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2582 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2585 /* 12.1 The default xml namespace Statement {{{ */
2586 /* XXX: DefaultXMLNamespaceStatement
2587 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2591 : DefaultXMLNamespaceStatement { $$ = $1; }
2596 /* JavaScript FTL: Array Comprehensions {{{ */
2598 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2602 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2605 /* JavaScript FTL: for each {{{ */
2607 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2611 /* JavaScript FTW: Array Comprehensions {{{ */
2613 : ArrayComprehension
2617 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2621 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2626 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2627 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2631 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2632 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2636 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2639 /* JavaScript FTW: Coalesce Operator {{{ */
2640 ConditionalExpression
2641 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2644 /* JavaScript FTW: Named Arguments {{{ */
2646 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2649 /* JavaScript FTW: Ruby Blocks {{{ */
2650 RubyProcParameterList_
2651 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2655 RubyProcParameterList
2656 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2657 | LexOf { $$ = NULL; }
2661 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2662 | "||" { $$ = NULL; }
2665 RubyProcParametersOpt
2666 : RubyProcParameters[pass] { $$ = $pass; }
2671 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2675 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2678 RubyBlockExpression_
2679 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2680 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2684 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2685 | RubyBlockExpression_[pass] { $$ = $pass; }
2691 bool CYDriver::Parse(CYMark mark) {
2693 CYLocal<CYPool> local(&pool_);
2694 cy::parser parser(*this);
2696 parser.set_debug_level(debug_);
2698 return parser.parse() != 0;
2701 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2705 CYDriver::Error error;
2706 error.warning_ = true;
2707 error.location_ = location;
2708 error.message_ = message;
2709 errors_.push_back(error);
2712 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2713 CYDriver::Error error;
2714 error.warning_ = false;
2715 error.location_ = location;
2716 error.message_ = message;
2717 driver.errors_.push_back(error);