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 { CYTypedFormal *typedFormal_; }
89 %union { CYTypedIdentifier *typedIdentifier_; }
90 %union { CYTypedParameter *typedParameter_; }
94 %union { CYObjCKeyValue *keyValue_; }
95 %union { CYImplementationField *implementationField_; }
96 %union { CYMessage *message_; }
97 %union { CYMessageParameter *messageParameter_; }
98 %union { CYProtocol *protocol_; }
99 %union { CYSelectorPart *selector_; }
103 %union { CYAttribute *attribute_; }
104 %union { CYPropertyIdentifier *propertyIdentifier_; }
105 %union { CYSelector *selector_; }
111 cy::parser::semantic_type semantic_;
112 hi::Value highlight_;
115 int cylex(YYSTYPE *, CYLocation *, void *);
123 typedef cy::parser::token tk;
125 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
126 driver.newline_ = false;
129 int token(cylex(&data, location, driver.scanner_));
130 *semantic = data.semantic_;
134 case tk::OpenBracket:
136 driver.in_.push(false);
140 if (driver.in_.top())
145 case tk::CloseBracket:
152 if (driver.yield_.top())
153 token = tk::_yield__;
157 driver.newline_ = true;
165 #define yylex_(semantic, location, driver) ({ \
167 if (driver.hold_ == cy::parser::empty_symbol) \
168 type = yytranslate_(cylex_(semantic, location, driver)); \
170 type = driver.hold_; \
171 driver.hold_ = cy::parser::empty_symbol; \
175 #define CYLEX() do if (yyla.empty()) { \
176 YYCDEBUG << "Mapping a token: "; \
177 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
178 YY_SYMBOL_PRINT("Next token is", yyla); \
181 #define CYMAP(to, from) do { \
183 if (yyla.type == yytranslate_(token::from)) \
184 yyla.type = yytranslate_(token::to); \
187 #define CYERR(location, message) do { \
188 error(location, message); \
192 #define CYEOK() do { \
194 driver.errors_.pop_back(); \
197 #define CYNOT(location) \
198 CYERR(location, "unimplemented feature")
200 #define CYMPT(location) do { \
201 if (!yyla.empty() && yyla.type_get() != yyeof_) \
202 CYERR(location, "unexpected lookahead"); \
212 @$.begin.filename = @$.end.filename = &driver.filename_;
214 switch (driver.mark_) {
216 driver.hold_ = yytranslate_(token::MarkScript);
219 driver.hold_ = yytranslate_(token::MarkModule);
227 %define api.location.type { CYLocation }
234 %param { CYDriver &driver }
236 /* Token Declarations {{{ */
242 %token XMLAttributeValue
244 %token XMLTagCharacters
250 %token LeftRight "<>"
251 %token LeftSlashRight "</>"
253 %token SlashRight "/>"
254 %token LeftSlash "</"
256 %token ColonColon "::"
257 %token PeriodPeriod ".."
260 @begin E4X ObjectiveC
266 %token AmpersandAmpersand "&&"
267 %token AmpersandEqual "&="
269 %token CarrotEqual "^="
271 %token EqualEqual "=="
272 %token EqualEqualEqual "==="
273 %token EqualRight "=>"
274 %token Exclamation "!"
275 %token ExclamationEqual "!="
276 %token ExclamationEqualEqual "!=="
278 %token HyphenEqual "-="
279 %token HyphenHyphen "--"
280 %token HyphenRight "->"
282 %token LeftEqual "<="
284 %token LeftLeftEqual "<<="
286 %token PercentEqual "%="
288 %token PeriodPeriodPeriod "..."
290 %token PipeEqual "|="
293 %token PlusEqual "+="
296 %token RightEqual ">="
297 %token RightRight ">>"
298 %token RightRightEqual ">>="
299 %token RightRightRight ">>>"
300 %token RightRightRightEqual ">>>="
302 %token SlashEqual "/="
304 %token StarEqual "*="
317 %token CloseParen ")"
320 %token OpenBrace_ ";{"
321 %token OpenBrace_let "let {"
322 %token CloseBrace "}"
324 %token OpenBracket "["
325 %token OpenBracket_let "let ["
326 %token CloseBracket "]"
328 %token At_error_ "@error"
331 %token At_class_ "@class"
335 %token _typedef_ "typedef"
336 %token _unsigned_ "unsigned"
337 %token _signed_ "signed"
338 %token _struct_ "struct"
339 %token _extern_ "extern"
343 %token At_encode_ "@encode"
347 %token At_implementation_ "@implementation"
348 %token At_import_ "@import"
349 %token At_end_ "@end"
350 %token At_selector_ "@selector"
351 %token At_null_ "@null"
352 %token At_YES_ "@YES"
354 %token At_true_ "@true"
355 %token At_false_ "@false"
360 %token _false_ "false"
365 %token _break_ "break"
367 %token _catch_ "catch"
368 %token _class_ "class"
369 %token _class__ ";class"
370 %token _const_ "const"
371 %token _continue_ "continue"
372 %token _debugger_ "debugger"
373 %token _default_ "default"
374 %token _delete_ "delete"
378 %token _export_ "export"
379 %token _extends_ "extends"
380 %token _finally_ "finally"
382 %token _function_ "function"
383 %token _function__ ";function"
385 %token _import_ "import"
388 %token _Infinity_ "Infinity"
389 %token _instanceof_ "instanceof"
391 %token _return_ "return"
392 %token _super_ "super"
393 %token _switch_ "switch"
394 %token _target_ "target"
396 %token _throw_ "throw"
398 %token _typeof_ "typeof"
401 %token _while_ "while"
404 %token _abstract_ "abstract"
405 %token _await_ "await"
406 %token _boolean_ "boolean"
409 %token _constructor_ "constructor"
410 %token _double_ "double"
412 %token _final_ "final"
413 %token _float_ "float"
417 %token _implements_ "implements"
419 %token _interface_ "interface"
423 %token _native_ "native"
424 %token _package_ "package"
425 %token _private_ "private"
426 %token _protected_ "protected"
427 %token ___proto___ "__proto__"
428 %token _prototype_ "prototype"
429 %token _public_ "public"
430 %token ___restrict_ "__restrict"
431 %token _restrict_ "restrict"
433 %token _short_ "short"
434 %token _static_ "static"
435 %token _synchronized_ "synchronized"
436 %token _throws_ "throws"
437 %token _transient_ "transient"
438 %token _typeid_ "typeid"
439 %token _volatile_ "volatile"
440 %token _yield_ "yield"
441 %token _yield__ "!yield"
443 %token _undefined_ "undefined"
459 %token _namespace_ "namespace"
464 %token YieldStar "yield *"
466 %token <identifier_> Identifier_
467 %token <number_> NumericLiteral
468 %token <string_> StringLiteral
469 %token <literal_> RegularExpressionLiteral_
471 %token <string_> NoSubstitutionTemplate
472 %token <string_> TemplateHead
473 %token <string_> TemplateMiddle
474 %token <string_> TemplateTail
476 %type <target_> AccessExpression
477 %type <expression_> AdditiveExpression
478 %type <argument_> ArgumentList_
479 %type <argument_> ArgumentList
480 %type <argument_> ArgumentListOpt
481 %type <argument_> Arguments
482 %type <target_> ArrayComprehension
483 %type <element_> ArrayElement
484 %type <literal_> ArrayLiteral
485 %type <expression_> ArrowFunction
486 %type <functionParameter_> ArrowParameters
487 %type <expression_> AssignmentExpression
488 %type <identifier_> BindingIdentifier
489 %type <identifier_> BindingIdentifierOpt
490 %type <bindings_> BindingList_
491 %type <bindings_> BindingList
492 %type <expression_> BitwiseANDExpression
493 %type <statement_> Block
494 %type <statement_> BlockStatement
495 %type <boolean_> BooleanLiteral
496 %type <binding_> BindingElement
497 %type <expression_> BitwiseORExpression
498 %type <expression_> BitwiseXORExpression
499 %type <statement_> BreakStatement
500 %type <statement_> BreakableStatement
501 %type <expression_> CallExpression_
502 %type <target_> CallExpression
503 %type <clause_> CaseBlock
504 %type <clause_> CaseClause
505 %type <clause_> CaseClausesOpt
507 %type <identifier_> CatchParameter
508 %type <statement_> ClassDeclaration
509 %type <target_> ClassExpression
510 %type <classTail_> ClassHeritage
511 %type <classTail_> ClassHeritageOpt
512 %type <classTail_> ClassTail
513 %type <target_> Comprehension
514 %type <comprehension_> ComprehensionFor
515 %type <comprehension_> ComprehensionIf
516 %type <comprehension_> ComprehensionTail
517 %type <propertyName_> ComputedPropertyName
518 %type <expression_> ConditionalExpression
519 %type <statement_> ContinueStatement
520 %type <statement_> ConciseBody
521 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
522 %type <statement_> DebuggerStatement
523 %type <statement_> Declaration_
524 %type <statement_> Declaration
525 %type <clause_> DefaultClause
526 %type <element_> ElementList_
527 %type <element_> ElementList
528 %type <element_> ElementListOpt
529 %type <statement_> ElseStatementOpt
530 %type <for_> EmptyStatement
531 %type <expression_> EqualityExpression
532 %type <expression_> Expression
533 %type <expression_> ExpressionOpt
534 %type <for_> ExpressionStatement_
535 %type <statement_> ExpressionStatement
536 %type <statement_> ExternC
537 %type <statement_> ExternCStatement
538 %type <statement_> ExternCStatementListOpt
539 %type <finally_> Finally
540 %type <binding_> ForBinding
541 %type <forin_> ForDeclaration
542 %type <forin_> ForInStatementInitializer
543 %type <for_> ForStatementInitializer
544 %type <binding_> FormalParameter
545 %type <functionParameter_> FormalParameterList_
546 %type <functionParameter_> FormalParameterList
547 %type <functionParameter_> FormalParameters
548 %type <string_> FromClause
549 %type <statement_> FunctionBody
550 %type <statement_> FunctionDeclaration
551 %type <target_> FunctionExpression
552 %type <statement_> FunctionStatementList
553 %type <statement_> GeneratorBody
554 %type <statement_> GeneratorDeclaration
555 %type <target_> GeneratorExpression
556 %type <method_> GeneratorMethod
557 %type <statement_> HoistableDeclaration
558 %type <identifier_> Identifier
559 %type <identifier_> IdentifierNoOf
560 %type <identifier_> IdentifierType
561 %type <identifier_> IdentifierTypeNoOf
562 %type <identifier_> IdentifierTypeOpt
563 %type <word_> IdentifierName
564 %type <variable_> IdentifierReference
565 %type <statement_> IfStatement
566 %type <import_> ImportClause
567 %type <statement_> ImportDeclaration
568 %type <import_> ImportSpecifier
569 %type <identifier_> ImportedBinding
570 %type <import_> ImportedDefaultBinding
571 %type <import_> ImportsList_
572 %type <import_> ImportsList
573 %type <import_> ImportsListOpt
574 %type <target_> IndirectExpression
575 %type <expression_> Initializer
576 %type <expression_> InitializerOpt
577 %type <statement_> IterationStatement
578 %type <identifier_> LabelIdentifier
579 %type <statement_> LabelledItem
580 %type <statement_> LabelledStatement
581 %type <assignment_> LeftHandSideAssignment
582 %type <target_> LeftHandSideExpression
583 %type <bool_> LetOrConst
584 %type <binding_> LexicalBinding
585 %type <for_> LexicalDeclaration_
586 %type <statement_> LexicalDeclaration
587 %type <literal_> Literal
588 %type <propertyName_> LiteralPropertyName
589 %type <expression_> LogicalANDExpression
590 %type <expression_> LogicalORExpression
591 %type <access_> MemberAccess
592 %type <target_> MemberExpression
593 %type <method_> MethodDefinition
594 %type <statement_> ModuleBody
595 %type <statement_> ModuleBodyOpt
596 %type <statement_> ModuleItem
597 %type <statement_> ModuleItemList
598 %type <statement_> ModuleItemListOpt
599 %type <module_> ModulePath
600 %type <string_> ModuleSpecifier
601 %type <expression_> MultiplicativeExpression
602 %type <import_> NameSpaceImport
603 %type <import_> NamedImports
604 %type <target_> NewExpression
605 %type <null_> NullLiteral
606 %type <literal_> ObjectLiteral
607 %type <expression_> PostfixExpression
608 %type <target_> PrimaryExpression
609 %type <propertyName_> PropertyName
610 %type <property_> PropertyDefinition
611 %type <property_> PropertyDefinitionList_
612 %type <property_> PropertyDefinitionList
613 %type <property_> PropertyDefinitionListOpt
614 %type <functionParameter_> PropertySetParameterList
615 %type <literal_> RegularExpressionLiteral
616 %type <bool_> RegularExpressionSlash
617 %type <expression_> RelationalExpression
618 %type <statement_> ReturnStatement
619 %type <target_> RubyBlockExpression_
620 %type <target_> RubyBlockExpression
621 %type <rubyProc_> RubyProcExpression
622 %type <functionParameter_> RubyProcParameterList_
623 %type <functionParameter_> RubyProcParameterList
624 %type <functionParameter_> RubyProcParameters
625 %type <functionParameter_> RubyProcParametersOpt
626 %type <statement_> Script
627 %type <statement_> ScriptBody
628 %type <statement_> ScriptBodyOpt
629 %type <expression_> ShiftExpression
630 %type <binding_> SingleNameBinding
631 %type <statement_> Statement__
632 %type <statement_> Statement_
633 %type <statement_> Statement
634 %type <statement_> StatementList
635 %type <statement_> StatementListOpt
636 %type <statement_> StatementListItem
637 %type <functionParameter_> StrictFormalParameters
638 %type <target_> SuperCall
639 %type <target_> SuperProperty
640 %type <statement_> SwitchStatement
641 %type <target_> TemplateLiteral
642 %type <span_> TemplateSpans
643 %type <statement_> ThrowStatement
644 %type <statement_> TryStatement
645 %type <statement_> TypeDefinition
646 %type <expression_> UnaryExpression_
647 %type <expression_> UnaryExpression
648 %type <binding_> VariableDeclaration
649 %type <bindings_> VariableDeclarationList_
650 %type <bindings_> VariableDeclarationList
651 %type <for_> VariableStatement_
652 %type <statement_> VariableStatement
653 %type <statement_> WithStatement
656 %type <word_> WordOpt
658 %type <expression_> YieldExpression
661 %type <integral_> IntegerType
662 %type <integral_> IntegerTypeOpt
663 %type <typedIdentifier_> PrefixedType
664 %type <specifier_> PrimitiveType
665 %type <structField_> StructFieldListOpt
666 %type <typedIdentifier_> SuffixedType
667 %type <typedIdentifier_> SuffixedTypeOpt
668 %type <typedIdentifier_> TypeSignifier
669 %type <typedIdentifier_> TypeSignifierNone
670 %type <typedIdentifier_> TypeSignifierOpt
671 %type <modifier_> ParameterTail
672 %type <modifier_> TypeQualifierLeft
673 %type <modifier_> TypeQualifierLeftOpt
674 %type <typedIdentifier_> TypeQualifierRight
675 %type <typedIdentifier_> TypeQualifierRightOpt
676 %type <typedIdentifier_> TypedIdentifierDefinition
677 %type <typedIdentifier_> TypedIdentifierEncoding
678 %type <typedIdentifier_> TypedIdentifierField
679 %type <typedIdentifier_> TypedIdentifierMaybe
680 %type <typedIdentifier_> TypedIdentifierNo
681 %type <typedIdentifier_> TypedIdentifierYes
682 %type <typedFormal_> TypedParameterList_
683 %type <typedFormal_> TypedParameterList
684 %type <typedFormal_> TypedParameterListOpt
685 %type <typedParameter_> TypedParameters
689 %type <expression_> AssignmentExpressionClassic
690 %type <expression_> BoxableExpression
691 %type <statement_> CategoryStatement
692 %type <expression_> ClassSuperOpt
693 %type <expression_> ConditionalExpressionClassic
694 %type <message_> ClassMessageDeclaration
695 %type <message_> ClassMessageDeclarationListOpt
696 %type <protocol_> ClassProtocolListOpt
697 %type <protocol_> ClassProtocols
698 %type <protocol_> ClassProtocolsOpt
699 %type <implementationField_> ImplementationFieldListOpt
700 %type <statement_> ImplementationStatement
701 %type <keyValue_> KeyValuePairList_
702 %type <keyValue_> KeyValuePairList
703 %type <keyValue_> KeyValuePairListOpt
704 %type <target_> MessageExpression
705 %type <messageParameter_> MessageParameter
706 %type <messageParameter_> MessageParameters
707 %type <messageParameter_> MessageParameterList
708 %type <messageParameter_> MessageParameterListOpt
709 %type <bool_> MessageScope
710 %type <argument_> SelectorCall_
711 %type <argument_> SelectorCall
712 %type <selector_> SelectorExpression_
713 %type <selector_> SelectorExpression
714 %type <selector_> SelectorExpressionOpt
715 %type <argument_> SelectorList
716 %type <word_> SelectorWordOpt
717 %type <typedIdentifier_> TypeOpt
718 %type <argument_> VariadicCall
722 %type <propertyIdentifier_> PropertyIdentifier_
723 %type <selector_> PropertySelector_
724 %type <selector_> PropertySelector
725 %type <identifier_> QualifiedIdentifier_
726 %type <identifier_> QualifiedIdentifier
727 %type <identifier_> WildcardIdentifier
728 %type <identifier_> XMLComment
729 %type <identifier_> XMLCDATA
730 %type <identifier_> XMLElement
731 %type <identifier_> XMLElementContent
732 %type <identifier_> XMLMarkup
733 %type <identifier_> XMLPI
735 %type <attribute_> AttributeIdentifier
736 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
737 %type <expression_> PropertyIdentifier
738 %type <expression_> XMLListInitilizer
739 %type <expression_> XMLInitilizer
742 /* Token Priorities {{{ */
758 /* Lexer State {{{ */
759 LexPushInOn: { driver.in_.push(true); };
760 LexPushInOff: { driver.in_.push(false); };
761 LexPopIn: { driver.in_.pop(); };
763 LexPushReturnOn: { driver.return_.push(true); };
764 LexPopReturn: { driver.return_.pop(); };
765 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
767 LexPushSuperOn: { driver.super_.push(true); };
768 LexPushSuperOff: { driver.super_.push(false); };
769 LexPopSuper: { driver.super_.pop(); };
770 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
772 LexPushYieldOn: { driver.yield_.push(true); };
773 LexPushYieldOff: { driver.yield_.push(false); };
774 LexPopYield: { driver.yield_.pop(); };
777 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
781 : { 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::__); }
785 : { CYMAP(YieldStar, Star); }
789 : { CYMAP(OpenBrace_, OpenBrace); }
793 : { CYMAP(_class__, _class_); }
797 : { CYMAP(_function__, _function_); }
801 : LexNoBrace LexNoClass LexNoFunction
804 /* Virtual Tokens {{{ */
810 /* 11.6 Names and Keywords {{{ */
812 : Word[pass] { $$ = $pass; }
813 | "for" { $$ = CYNew CYWord("for"); }
814 | "in" { $$ = CYNew CYWord("in"); }
815 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
819 : IdentifierNoOf[pass] { $$ = $pass; }
820 | "break" { $$ = CYNew CYWord("break"); }
821 | "case" { $$ = CYNew CYWord("case"); }
822 | "catch" { $$ = CYNew CYWord("catch"); }
823 | "class" LexOf { $$ = CYNew CYWord("class"); }
824 | ";class" { $$ = CYNew CYWord("class"); }
825 | "const" { $$ = CYNew CYWord("const"); }
826 | "continue" { $$ = CYNew CYWord("continue"); }
827 | "debugger" { $$ = CYNew CYWord("debugger"); }
828 | "default" { $$ = CYNew CYWord("default"); }
829 | "delete" { $$ = CYNew CYWord("delete"); }
830 | "do" { $$ = CYNew CYWord("do"); }
831 | "else" { $$ = CYNew CYWord("else"); }
832 | "enum" { $$ = CYNew CYWord("enum"); }
833 | "export" { $$ = CYNew CYWord("export"); }
834 | "extends" { $$ = CYNew CYWord("extends"); }
835 | "false" { $$ = CYNew CYWord("false"); }
836 | "finally" { $$ = CYNew CYWord("finally"); }
837 | "function" LexOf { $$ = CYNew CYWord("function"); }
838 | "if" { $$ = CYNew CYWord("if"); }
839 | "import" { $$ = CYNew CYWord("import"); }
840 | "!in" { $$ = CYNew CYWord("in"); }
841 | "!of" { $$ = CYNew CYWord("of"); }
842 | "new" { $$ = CYNew CYWord("new"); }
843 | "null" { $$ = CYNew CYWord("null"); }
844 | "return" { $$ = CYNew CYWord("return"); }
845 | "super" { $$ = CYNew CYWord("super"); }
846 | "switch" { $$ = CYNew CYWord("switch"); }
847 | "this" { $$ = CYNew CYWord("this"); }
848 | "throw" { $$ = CYNew CYWord("throw"); }
849 | "true" { $$ = CYNew CYWord("true"); }
850 | "try" { $$ = CYNew CYWord("try"); }
851 | "typeof" { $$ = CYNew CYWord("typeof"); }
852 | "var" { $$ = CYNew CYWord("var"); }
853 | "void" { $$ = CYNew CYWord("void"); }
854 | "while" { $$ = CYNew CYWord("while"); }
855 | "with" { $$ = CYNew CYWord("with"); }
856 | "yield" { $$ = CYNew CYIdentifier("yield"); }
861 : Word[pass] { $$ = $pass; }
866 /* 11.8.1 Null Literals {{{ */
868 : "null" { $$ = CYNew CYNull(); }
871 /* 11.8.2 Boolean Literals {{{ */
873 : "true" { $$ = CYNew CYTrue(); }
874 | "false" { $$ = CYNew CYFalse(); }
877 /* 11.8.5 Regular Expression Literals {{{ */
878 RegularExpressionSlash
879 : "/" { $$ = false; }
880 | "/=" { $$ = true; }
883 RegularExpressionLiteral
884 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
888 /* 11.9 Automatic Semicolon Insertion {{{ */
890 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
898 : LexNewLineOrNot "\n"
903 : LexNewLineOrNot "\n" StrictSemi
904 | NewLineNot LexOf Terminator
909 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
914 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
919 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
923 /* 12.1 Identifiers {{{ */
925 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
926 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
930 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
931 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
932 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
936 : BindingIdentifier[pass] { $$ = $pass; }
937 | LexOf { $$ = NULL; }
941 : Identifier[pass] { $$ = $pass; }
942 | "yield" { $$ = CYNew CYIdentifier("yield"); }
946 : Identifier_[pass] { $$ = $pass; }
947 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
948 | "as" { $$ = CYNew CYIdentifier("as"); }
949 | "await" { $$ = CYNew CYIdentifier("await"); }
950 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
951 | "byte" { $$ = CYNew CYIdentifier("byte"); }
952 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
953 | "double" { $$ = CYNew CYIdentifier("double"); }
954 | "each" { $$ = CYNew CYIdentifier("each"); }
955 | "eval" { $$ = CYNew CYIdentifier("eval"); }
956 | "final" { $$ = CYNew CYIdentifier("final"); }
957 | "float" { $$ = CYNew CYIdentifier("float"); }
958 | "from" { $$ = CYNew CYIdentifier("from"); }
959 | "get" { $$ = CYNew CYIdentifier("get"); }
960 | "goto" { $$ = CYNew CYIdentifier("goto"); }
961 | "implements" { $$ = CYNew CYIdentifier("implements"); }
962 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
963 | "interface" { $$ = CYNew CYIdentifier("interface"); }
964 | "let" { $$ = CYNew CYIdentifier("let"); }
965 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
966 | "native" { $$ = CYNew CYIdentifier("native"); }
967 | "package" { $$ = CYNew CYIdentifier("package"); }
968 | "private" { $$ = CYNew CYIdentifier("private"); }
969 | "protected" { $$ = CYNew CYIdentifier("protected"); }
970 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
971 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
972 | "public" { $$ = CYNew CYIdentifier("public"); }
973 | "set" { $$ = CYNew CYIdentifier("set"); }
974 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
975 | "target" { $$ = CYNew CYIdentifier("target"); }
976 | "throws" { $$ = CYNew CYIdentifier("throws"); }
977 | "transient" { $$ = CYNew CYIdentifier("transient"); }
978 | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
979 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
981 | "bool" { $$ = CYNew CYIdentifier("bool"); }
982 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
983 | "id" { $$ = CYNew CYIdentifier("id"); }
984 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
989 : IdentifierTypeNoOf[pass] { $$ = $pass; }
990 | "of" { $$ = CYNew CYIdentifier("of"); }
994 : IdentifierType[pass] { $$ = $pass; }
1000 | "char" { $$ = CYNew CYIdentifier("char"); }
1001 | "int" { $$ = CYNew CYIdentifier("int"); }
1002 | "long" { $$ = CYNew CYIdentifier("long"); }
1003 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1004 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1005 | "short" { $$ = CYNew CYIdentifier("short"); }
1006 | "static" { $$ = CYNew CYIdentifier("static"); }
1007 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1009 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1010 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1013 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1014 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1015 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1016 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1021 : IdentifierNoOf[pass] { $$ = $pass; }
1022 | "of" { $$ = CYNew CYIdentifier("of"); }
1023 | "!of" { $$ = CYNew CYIdentifier("of"); }
1026 /* 12.2 Primary Expression {{{ */
1028 : "this" { $$ = CYNew CYThis(); }
1029 | IdentifierReference[pass] { $$ = $pass; }
1030 | Literal[pass] { $$ = $pass; }
1031 | ArrayLiteral[pass] { $$ = $pass; }
1032 | ObjectLiteral[pass] { $$ = $pass; }
1033 | FunctionExpression[pass] { $$ = $pass; }
1034 | ClassExpression[pass] { $$ = $pass; }
1035 | GeneratorExpression[pass] { $$ = $pass; }
1036 | RegularExpressionLiteral[pass] { $$ = $pass; }
1037 | TemplateLiteral[pass] { $$ = $pass; }
1038 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1039 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1042 CoverParenthesizedExpressionAndArrowParameterList
1043 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1044 | "(" LexOf ")" { $$ = NULL; }
1045 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1046 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1049 /* 12.2.4 Literals {{{ */
1051 : NullLiteral[pass] { $$ = $pass; }
1052 | BooleanLiteral[pass] { $$ = $pass; }
1053 | NumericLiteral[pass] { $$ = $pass; }
1054 | StringLiteral[pass] { $$ = $pass; }
1057 /* 12.2.5 Array Initializer {{{ */
1059 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1063 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1064 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1068 : "," ElementListOpt[elements] { $$ = $elements; }
1073 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1074 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1078 : ElementList[pass] { $$ = $pass; }
1079 | LexOf { $$ = NULL; }
1082 /* 12.2.6 Object Initializer {{{ */
1084 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1087 PropertyDefinitionList_
1088 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1092 PropertyDefinitionList
1093 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1096 PropertyDefinitionListOpt
1097 : PropertyDefinitionList[properties] { $$ = $properties; }
1102 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1103 | CoverInitializedName[name] { CYNOT(@$); }
1104 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1105 | MethodDefinition[pass] { $$ = $pass; }
1109 : LiteralPropertyName[pass] { $$ = $pass; }
1110 | ComputedPropertyName[pass] { $$ = $pass; }
1114 : IdentifierName[pass] { $$ = $pass; }
1115 | StringLiteral[pass] { $$ = $pass; }
1116 | NumericLiteral[pass] { $$ = $pass; }
1119 ComputedPropertyName
1120 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1123 CoverInitializedName
1124 : IdentifierReference Initializer
1128 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1132 : Initializer[pass] { $$ = $pass; }
1136 /* 12.2.9 Template Literals {{{ */
1138 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1139 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1143 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1144 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1148 /* 12.3 Left-Hand-Side Expressions {{{ */
1150 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1151 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1152 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1153 | TemplateLiteral { CYNOT(@$); }
1157 : PrimaryExpression[pass] { $$ = $pass; }
1158 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1159 | SuperProperty[pass] { $$ = $pass; }
1160 | MetaProperty { CYNOT(@$); }
1161 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1165 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1166 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1174 : "new" "." "target"
1178 : MemberExpression[pass] { $$ = $pass; }
1179 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1183 : MemberExpression[pass] { $$ = $pass; }
1184 | CallExpression[pass] { $$ = $pass; }
1188 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1189 | SuperCall[pass] { $$ = $pass; }
1190 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1194 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1198 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1202 : "," ArgumentList[arguments] { $$ = $arguments; }
1207 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1208 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1212 : ArgumentList[pass] { $$ = $pass; }
1213 | LexOf { $$ = NULL; }
1217 : NewExpression[pass] { $$ = $pass; }
1218 | CallExpression[pass] { $$ = $pass; }
1221 LeftHandSideExpression
1222 : RubyBlockExpression[pass] { $$ = $pass; }
1223 | IndirectExpression[pass] { $$ = $pass; }
1226 /* 12.4 Postfix Expressions {{{ */
1228 : RubyBlockExpression[pass] { $$ = $pass; }
1229 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1230 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1233 /* 12.5 Unary Operators {{{ */
1235 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1236 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1237 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1238 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1239 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1240 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1241 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1242 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1243 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1247 : PostfixExpression[expression] { $$ = $expression; }
1248 | UnaryExpression_[pass] { $$ = $pass; }
1251 /* 12.6 Multiplicative Operators {{{ */
1252 MultiplicativeExpression
1253 : UnaryExpression[pass] { $$ = $pass; }
1254 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1255 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1256 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1259 /* 12.7 Additive Operators {{{ */
1261 : MultiplicativeExpression[pass] { $$ = $pass; }
1262 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1263 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1266 /* 12.8 Bitwise Shift Operators {{{ */
1268 : AdditiveExpression[pass] { $$ = $pass; }
1269 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1270 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1271 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1274 /* 12.9 Relational Operators {{{ */
1275 RelationalExpression
1276 : ShiftExpression[pass] { $$ = $pass; }
1277 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1278 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1279 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1280 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1281 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1282 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1285 /* 12.10 Equality Operators {{{ */
1287 : RelationalExpression[pass] { $$ = $pass; }
1288 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1289 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1290 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1291 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1294 /* 12.11 Binary Bitwise Operators {{{ */
1295 BitwiseANDExpression
1296 : EqualityExpression[pass] { $$ = $pass; }
1297 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1300 BitwiseXORExpression
1301 : BitwiseANDExpression[pass] { $$ = $pass; }
1302 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1306 : BitwiseXORExpression[pass] { $$ = $pass; }
1307 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1310 /* 12.12 Binary Logical Operators {{{ */
1311 LogicalANDExpression
1312 : BitwiseORExpression[pass] { $$ = $pass; }
1313 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1317 : LogicalANDExpression[pass] { $$ = $pass; }
1318 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1321 /* 12.13 Conditional Operator ( ? : ) {{{ */
1323 ConditionalExpressionClassic
1324 : LogicalORExpression[pass] { $$ = $pass; }
1325 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1329 ConditionalExpression
1330 : LogicalORExpression[pass] { $$ = $pass; }
1331 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1334 /* 12.14 Assignment Operators {{{ */
1335 LeftHandSideAssignment
1336 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1337 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1338 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1339 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1340 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1341 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1342 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1343 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1344 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1345 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1346 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1347 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1351 AssignmentExpressionClassic
1352 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1353 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1357 AssignmentExpression
1358 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1359 | LexOf YieldExpression[pass] { $$ = $pass; }
1360 | ArrowFunction[pass] { $$ = $pass; }
1361 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1364 /* 12.15 Comma Operator ( , ) {{{ */
1366 : AssignmentExpression[pass] { $$ = $pass; }
1367 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1371 : Expression[pass] { $$ = $pass; }
1372 | LexOf { $$ = NULL; }
1376 /* 13 Statements and Declarations {{{ */
1378 : BlockStatement[pass] { $$ = $pass; }
1379 | VariableStatement[pass] { $$ = $pass; }
1380 | EmptyStatement[pass] { $$ = $pass; }
1381 | IfStatement[pass] { $$ = $pass; }
1382 | BreakableStatement[pass] { $$ = $pass; }
1383 | ContinueStatement[pass] { $$ = $pass; }
1384 | BreakStatement[pass] { $$ = $pass; }
1385 | ReturnStatement[pass] { $$ = $pass; }
1386 | WithStatement[pass] { $$ = $pass; }
1387 | LabelledStatement[pass] { $$ = $pass; }
1388 | ThrowStatement[pass] { $$ = $pass; }
1389 | TryStatement[pass] { $$ = $pass; }
1390 | DebuggerStatement[pass] { $$ = $pass; }
1394 : LexOf Statement__[pass] { $$ = $pass; }
1395 | ExpressionStatement[pass] { $$ = $pass; }
1399 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1403 : HoistableDeclaration[pass] { $$ = $pass; }
1404 | ClassDeclaration[pass] { $$ = $pass; }
1408 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1409 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1412 HoistableDeclaration
1413 : FunctionDeclaration[pass] { $$ = $pass; }
1414 | GeneratorDeclaration[pass] { $$ = $pass; }
1418 : IterationStatement[pass] { $$ = $pass; }
1419 | SwitchStatement[pass] { $$ = $pass; }
1422 /* 13.2 Block {{{ */
1424 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1428 : "{" StatementListOpt[code] "}" { $$ = $code; }
1432 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1436 : StatementList[pass] { $$ = $pass; }
1437 | LexSetStatement LexLet LexOf { $$ = NULL; }
1441 : Statement[pass] { $$ = $pass; }
1442 | Declaration[pass] { $$ = $pass; }
1445 /* 13.3 Let and Const Declarations {{{ */
1447 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1451 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1455 : { CYMAP(_let__, _let_); }
1459 : { CYMAP(_of__, _of_); }
1463 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1467 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1468 | LexLet LexOf "const" { $$ = true; }
1472 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1477 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1481 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1482 | LexOf BindingPattern Initializer { CYNOT(@$); }
1485 /* 13.3.2 Variable Statement {{{ */
1487 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1491 : VariableStatement_[statement] Terminator { $$ = $statement; }
1494 VariableDeclarationList_
1495 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1499 VariableDeclarationList
1500 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1504 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1505 | LexOf BindingPattern Initializer { CYNOT(@$); }
1508 /* 13.3.3 Destructuring Binding Patterns {{{ */
1510 : ObjectBindingPattern
1511 | ArrayBindingPattern
1514 ObjectBindingPattern
1515 : "let {" BindingPropertyListOpt "}"
1519 : "let [" BindingElementListOpt "]"
1522 BindingPropertyList_
1523 : "," BindingPropertyListOpt
1528 : BindingProperty BindingPropertyList_
1531 BindingPropertyListOpt
1532 : BindingPropertyList
1537 : BindingElementOpt[element] "," BindingElementListOpt[next]
1538 | BindingRestElement[element]
1539 | BindingElement[element]
1542 BindingElementListOpt
1543 : BindingElementList[pass]
1549 | LexOf PropertyName ":" BindingElement
1553 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1554 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1558 : BindingElement[pass]
1563 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1567 : LexBind LexOf "..." BindingIdentifier
1570 /* 13.4 Empty Statement {{{ */
1572 : ";" { $$ = CYNew CYEmpty(); }
1575 /* 13.5 Expression Statement {{{ */
1576 ExpressionStatement_
1577 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1580 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1583 /* 13.6 The if Statement {{{ */
1585 : "else" Statement[false] { $$ = $false; }
1586 | %prec "if" { $$ = NULL; }
1590 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1593 /* 13.7 Iteration Statements {{{ */
1595 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1596 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1597 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1598 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1599 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1600 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1603 ForStatementInitializer
1604 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1605 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1606 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1607 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1610 ForInStatementInitializer
1611 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1612 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1613 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1614 | ForDeclaration[pass] { $$ = $pass; }
1618 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1622 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1623 | LexOf BindingPattern { CYNOT(@$); }
1626 /* 13.8 The continue Statement {{{ */
1628 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1629 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1632 /* 13.9 The break Statement {{{ */
1634 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1635 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1638 /* 13.10 The return Statement {{{ */
1640 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1641 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1644 /* 13.11 The with Statement {{{ */
1646 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1649 /* 13.12 The switch Statement {{{ */
1651 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1655 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1659 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1663 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1664 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1668 // XXX: the standard makes certain you can only have one of these
1670 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1673 /* 13.13 Labelled Statements {{{ */
1675 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1679 : Statement[pass] { $$ = $pass; }
1680 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1683 /* 13.14 The throw Statement {{{ */
1685 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1686 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1689 /* 13.15 The try Statement {{{ */
1691 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1692 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1693 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1697 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1701 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1705 : BindingIdentifier[pass] { $$ = $pass; }
1706 | LexOf BindingPattern { CYNOT(@$); }
1709 /* 13.16 The debugger Statement {{{ */
1711 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1715 /* 14.1 Function Definitions {{{ */
1717 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1721 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1724 StrictFormalParameters
1725 : FormalParameters[pass] { $$ = $pass; }
1729 : LexBind LexOf { $$ = NULL; }
1730 | FormalParameterList
1733 FormalParameterList_
1734 : "," FormalParameterList[parameters] { $$ = $parameters; }
1739 : FunctionRestParameter { CYNOT(@$); }
1740 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1743 FunctionRestParameter
1744 : BindingRestElement
1748 : BindingElement[pass] { $$ = $pass; }
1752 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1755 FunctionStatementList
1756 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1759 /* 14.2 Arrow Function Definitions {{{ */
1761 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1765 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1766 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1770 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1771 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1774 /* 14.3 Method Definitions {{{ */
1776 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1777 | GeneratorMethod[pass] { $$ = $pass; }
1778 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1779 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1782 PropertySetParameterList
1783 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1786 /* 14.4 Generator Function Definitions {{{ */
1788 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1791 GeneratorDeclaration
1792 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1796 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1800 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1804 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1805 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1806 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1807 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1810 /* 14.5 Class Definitions {{{ */
1812 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1816 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1820 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1824 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1828 : ClassHeritage[pass] { $$ = $pass; }
1829 | { $$ = CYNew CYClassTail(NULL); }
1842 : ClassElementListOpt ClassElement
1851 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1852 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1857 /* 15.1 Scripts {{{ */
1859 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1863 : StatementList[pass] { $$ = $pass; }
1867 : ScriptBody[pass] { $$ = $pass; }
1868 | LexSetStatement LexLet LexOf { $$ = NULL; }
1871 /* 15.2 Modules {{{ */
1873 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1877 : ModuleItemList[pass] { $$ = $pass; }
1881 : ModuleBody[pass] { $$ = $pass; }
1882 | LexSetStatement LexLet LexOf { $$ = NULL; }
1886 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1890 : ModuleItemList[pass] { $$ = $pass; }
1891 | LexSetStatement LexLet LexOf { $$ = NULL; }
1895 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1896 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1897 | StatementListItem[pass] { $$ = $pass; }
1900 /* 15.2.2 Imports {{{ */
1902 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1903 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1907 : ImportedDefaultBinding[default] { $$ = $default; }
1908 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1909 | LexOf NamedImports[pass] { $$ = $pass; }
1910 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1911 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1914 ImportedDefaultBinding
1915 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1919 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1923 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1927 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1931 : "," ImportsListOpt[pass] { $$ = $pass; }
1936 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1940 : ImportsList[pass] { $$ = $pass; }
1941 | LexOf { $$ = NULL; }
1945 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1946 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1950 : StringLiteral[pass] { $$ = $pass; }
1954 : BindingIdentifier[pass] { $$ = $pass; }
1957 /* 15.2.3 Exports {{{ */
1959 : "*" FromClause Terminator
1960 | ExportClause FromClause Terminator
1961 | ExportClause Terminator
1963 | "default" LexSetStatement LexOf HoistableDeclaration
1964 | "default" LexSetStatement LexOf ClassDeclaration
1965 | "default" LexSetStatement AssignmentExpression Terminator
1969 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1970 | "export" Declaration
1974 : ";{" ExportsListOpt "}"
1978 : "," ExportsListOpt
1983 : ExportSpecifier ExportsList_
1993 | IdentifierName "as" IdentifierName
1998 /* Cycript (C): Type Encoding {{{ */
2000 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
2001 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2005 : { $$ = CYNew CYTypedIdentifier(@$); }
2009 : TypeSignifier[pass] { $$ = $pass; }
2010 | TypeSignifierNone[pass] { $$ = $pass; }
2027 ParameterModifierOpt
2033 : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
2037 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2038 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2039 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2040 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2044 : SuffixedType[pass] { $$ = $pass; }
2045 | TypeSignifierOpt[pass] { $$ = $pass; }
2049 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2053 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2054 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2057 TypeQualifierLeftOpt
2058 : TypeQualifierLeft[pass] { $$ = $pass; }
2063 : SuffixedType[pass] { $$ = $pass; }
2064 | PrefixedType[pass] { $$ = $pass; }
2065 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2066 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2067 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2070 TypeQualifierRightOpt
2071 : TypeQualifierRight[pass] { $$ = $pass; }
2072 | TypeSignifierOpt[pass] { $$ = $pass; }
2076 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2077 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2078 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2079 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2080 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2084 : IntegerType[pass] { $$ = $pass; }
2085 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2089 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2094 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2095 | IntegerType[pass] { $$ = $pass; }
2096 | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
2097 | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
2098 | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
2099 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2102 TypedIdentifierMaybe
2103 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2104 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2105 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2109 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2113 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2116 TypedIdentifierField
2117 : TypedIdentifierYes[pass] { $$ = $pass; }
2118 | 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; }
2121 TypedIdentifierEncoding
2122 : TypedIdentifierNo[pass] { $$ = $pass; }
2123 | 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; }
2126 TypedIdentifierDefinition
2127 : TypedIdentifierYes[pass] { $$ = $pass; }
2128 | 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; }
2132 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2138 /* Cycript (Objective-C): @class Declaration {{{ */
2140 /* XXX: why the hell did I choose MemberExpression? */
2141 : ":" MemberExpression[extends] { $$ = $extends; }
2145 ImplementationFieldListOpt
2146 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2151 : "+" { $$ = false; }
2152 | "-" { $$ = true; }
2156 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2157 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2161 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2164 MessageParameterList
2165 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2168 MessageParameterListOpt
2169 : MessageParameterList[pass] { $$ = $pass; }
2170 | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
2174 : MessageParameterList[pass] { $$ = $pass; }
2175 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2178 ClassMessageDeclaration
2179 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2182 ClassMessageDeclarationListOpt
2183 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2187 // XXX: this should be AssignmentExpressionNoRight
2189 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2193 : "," ClassProtocols[protocols] { $$ = $protocols; }
2197 ClassProtocolListOpt
2198 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2202 ImplementationStatement
2203 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2211 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2215 : ImplementationStatement[pass] { $$ = $pass; }
2216 | CategoryStatement[pass] { $$ = $pass; }
2219 /* Cycript (Objective-C): Send Message {{{ */
2221 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2226 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2227 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2231 : SelectorCall[pass] { $$ = $pass; }
2232 | VariadicCall[pass] { $$ = $pass; }
2236 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2240 : SelectorCall[pass] { $$ = $pass; }
2241 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2245 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2246 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2250 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2254 : SelectorExpression_[pass] { $$ = $pass; }
2255 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2258 SelectorExpressionOpt
2259 : SelectorExpression_[pass] { $$ = $pass; }
2264 : MessageExpression[pass] { $$ = $pass; }
2265 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2270 /* Cycript: @import Directive {{{ */
2272 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2273 | Word[part] { $$ = CYNew CYModule($part); }
2277 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2282 /* Cycript (Objective-C): Boxed Expressions {{{ */
2284 : NullLiteral[pass] { $$ = $pass; }
2285 | BooleanLiteral[pass] { $$ = $pass; }
2286 | NumericLiteral[pass] { $$ = $pass; }
2287 | StringLiteral[pass] { $$ = $pass; }
2288 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2289 | "YES" { $$ = CYNew CYTrue(); }
2290 | "NO" { $$ = CYNew CYFalse(); }
2294 : "," KeyValuePairListOpt[next] { $$ = $next; }
2298 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2302 : KeyValuePairList[pass] { $$ = $pass; }
2303 | LexOf { $$ = NULL; }
2307 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2308 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2309 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2311 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2312 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2313 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2314 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2315 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2318 /* Cycript (Objective-C): Block Expressions {{{ */
2320 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2323 /* Cycript (Objective-C): Instance Literals {{{ */
2325 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2331 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2333 : IndirectExpression[pass] { $$ = $pass; }
2337 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2341 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2345 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2346 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2347 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2350 /* Cycript (C): Lambda Expressions {{{ */
2352 : "," TypedParameterList[parameters] { $$ = $parameters; }
2353 | { $$ = CYNew CYTypedFormal(false); }
2357 : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
2358 | "..." { $$ = CYNew CYTypedFormal(true); }
2361 TypedParameterListOpt
2362 : TypedParameterList[pass] { $$ = $pass; }
2363 | "void" { $$ = CYNew CYTypedFormal(false); }
2364 | { $$ = CYNew CYTypedFormal(false); }
2368 : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
2372 : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2375 /* Cycript (C): Structure Definitions {{{ */
2377 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2381 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2385 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2388 /* Cycript (C): Type Definitions {{{ */
2390 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2394 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2398 : TypeDefinition[pass] { $$ = $pass; }
2402 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2405 /* Cycript (C): extern "C" {{{ */
2407 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2411 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2412 | TypeDefinition[pass] { $$ = $pass; }
2415 ExternCStatementListOpt
2416 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2421 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2422 | ExternCStatement[pass] { $$ = $pass; }
2426 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2432 /* Lexer State {{{ */
2434 : { driver.PushCondition(CYDriver::RegExpCondition); }
2438 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2442 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2446 : { driver.PopCondition(); }
2450 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2454 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2457 /* Virtual Tokens {{{ */
2464 /* 8.1 Context Keywords {{{ */
2466 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2467 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2470 /* 8.3 XML Initializer Input Elements {{{ */
2472 : XMLComment { $$ = $1; }
2473 | XMLCDATA { $$ = $1; }
2474 | XMLPI { $$ = $1; }
2478 /* 11.1 Primary Expressions {{{ */
2480 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2481 | XMLInitilizer { $$ = $1; }
2482 | XMLListInitilizer { $$ = $1; }
2486 : AttributeIdentifier { $$ = $1; }
2487 | QualifiedIdentifier { $$ = $1; }
2488 | WildcardIdentifier { $$ = $1; }
2491 /* 11.1.1 Attribute Identifiers {{{ */
2493 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2497 : PropertySelector { $$ = $1; }
2498 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2502 : Identifier { $$ = CYNew CYSelector($1); }
2503 | WildcardIdentifier { $$ = $1; }
2506 /* 11.1.2 Qualified Identifiers {{{ */
2507 QualifiedIdentifier_
2508 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2509 | QualifiedIdentifier { $$ = $1; }
2513 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2516 /* 11.1.3 Wildcard Identifiers {{{ */
2518 : "*" { $$ = CYNew CYWildcard(); }
2521 /* 11.1.4 XML Initializer {{{ */
2523 : XMLMarkup { $$ = $1; }
2524 | XMLElement { $$ = $1; }
2528 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2529 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2533 : LexPushXMLTag XMLTagName XMLAttributes
2537 : "{" LexPushRegExp Expression LexPop "}"
2546 : XMLAttributes_ XMLAttribute
2551 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2552 | XMLAttributes_ XMLWhitespaceOpt
2561 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2565 : XMLExpression XMLElementContentOpt
2566 | XMLMarkup XMLElementContentOpt
2567 | XMLText XMLElementContentOpt
2568 | XMLElement XMLElementContentOpt
2571 XMLElementContentOpt
2576 /* 11.1.5 XMLList Initializer {{{ */
2578 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2582 /* 11.2 Left-Hand-Side Expressions {{{ */
2584 : Identifier { $$ = $1; }
2585 | PropertyIdentifier { $$ = $1; }
2589 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2590 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2591 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2594 /* 12.1 The default xml namespace Statement {{{ */
2595 /* XXX: DefaultXMLNamespaceStatement
2596 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2600 : DefaultXMLNamespaceStatement { $$ = $1; }
2605 /* JavaScript FTL: Array Comprehensions {{{ */
2607 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2611 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2614 /* JavaScript FTL: for each {{{ */
2616 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2620 /* JavaScript FTW: Array Comprehensions {{{ */
2622 : ArrayComprehension
2626 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2630 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2635 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2636 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2640 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2641 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2645 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2648 /* JavaScript FTW: Coalesce Operator {{{ */
2649 ConditionalExpression
2650 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2653 /* JavaScript FTW: Named Arguments {{{ */
2655 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2658 /* JavaScript FTW: Ruby Blocks {{{ */
2659 RubyProcParameterList_
2660 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2664 RubyProcParameterList
2665 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2666 | LexOf { $$ = NULL; }
2670 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2671 | "||" { $$ = NULL; }
2674 RubyProcParametersOpt
2675 : RubyProcParameters[pass] { $$ = $pass; }
2680 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2684 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2687 RubyBlockExpression_
2688 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2689 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2693 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2694 | RubyBlockExpression_[pass] { $$ = $pass; }
2700 bool CYDriver::Parse(CYMark mark) {
2702 CYLocal<CYPool> local(&pool_);
2703 cy::parser parser(*this);
2705 parser.set_debug_level(debug_);
2707 return parser.parse() != 0;
2710 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2714 CYDriver::Error error;
2715 error.warning_ = true;
2716 error.location_ = location;
2717 error.message_ = message;
2718 errors_.push_back(error);
2721 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2722 CYDriver::Error error;
2723 error.warning_ = false;
2724 error.location_ = location;
2725 error.message_ = message;
2726 driver.errors_.push_back(error);