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 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 "*="
307 %token ColonColon "::"
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
655 %type <word_> WordNoUnary
657 %type <word_> WordOpt
659 %type <expression_> YieldExpression
662 %type <integral_> IntegerType
663 %type <integral_> IntegerTypeOpt
664 %type <typedIdentifier_> PrefixedType
665 %type <specifier_> PrimitiveType
666 %type <structField_> StructFieldListOpt
667 %type <typedIdentifier_> SuffixedType
668 %type <typedIdentifier_> SuffixedTypeOpt
669 %type <typedIdentifier_> TypeSignifier
670 %type <typedIdentifier_> TypeSignifierNone
671 %type <typedIdentifier_> TypeSignifierOpt
672 %type <modifier_> ParameterTail
673 %type <modifier_> TypeQualifierLeft
674 %type <modifier_> TypeQualifierLeftOpt
675 %type <typedIdentifier_> TypeQualifierRight
676 %type <typedIdentifier_> TypeQualifierRightOpt
677 %type <typedIdentifier_> TypedIdentifierDefinition
678 %type <typedIdentifier_> TypedIdentifierEncoding
679 %type <typedIdentifier_> TypedIdentifierField
680 %type <typedIdentifier_> TypedIdentifierMaybe
681 %type <typedIdentifier_> TypedIdentifierNo
682 %type <typedIdentifier_> TypedIdentifierYes
683 %type <typedFormal_> TypedParameterList_
684 %type <typedFormal_> TypedParameterList
685 %type <typedFormal_> TypedParameterListOpt
686 %type <typedParameter_> TypedParameters
690 %type <expression_> AssignmentExpressionClassic
691 %type <expression_> BoxableExpression
692 %type <statement_> CategoryStatement
693 %type <expression_> ClassSuperOpt
694 %type <expression_> ConditionalExpressionClassic
695 %type <message_> ClassMessageDeclaration
696 %type <message_> ClassMessageDeclarationListOpt
697 %type <protocol_> ClassProtocolListOpt
698 %type <protocol_> ClassProtocols
699 %type <protocol_> ClassProtocolsOpt
700 %type <implementationField_> ImplementationFieldListOpt
701 %type <statement_> ImplementationStatement
702 %type <keyValue_> KeyValuePairList_
703 %type <keyValue_> KeyValuePairList
704 %type <keyValue_> KeyValuePairListOpt
705 %type <target_> MessageExpression
706 %type <messageParameter_> MessageParameter
707 %type <messageParameter_> MessageParameters
708 %type <messageParameter_> MessageParameterList
709 %type <messageParameter_> MessageParameterListOpt
710 %type <bool_> MessageScope
711 %type <argument_> SelectorCall_
712 %type <argument_> SelectorCall
713 %type <selector_> SelectorExpression_
714 %type <selector_> SelectorExpression
715 %type <selector_> SelectorExpressionOpt
716 %type <argument_> SelectorList
717 %type <word_> SelectorWordOpt
718 %type <typedIdentifier_> TypeOpt
719 %type <argument_> VariadicCall
723 %type <propertyIdentifier_> PropertyIdentifier_
724 %type <selector_> PropertySelector_
725 %type <selector_> PropertySelector
726 %type <identifier_> QualifiedIdentifier_
727 %type <identifier_> QualifiedIdentifier
728 %type <identifier_> WildcardIdentifier
729 %type <identifier_> XMLComment
730 %type <identifier_> XMLCDATA
731 %type <identifier_> XMLElement
732 %type <identifier_> XMLElementContent
733 %type <identifier_> XMLMarkup
734 %type <identifier_> XMLPI
736 %type <attribute_> AttributeIdentifier
737 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
738 %type <expression_> PropertyIdentifier
739 %type <expression_> XMLListInitilizer
740 %type <expression_> XMLInitilizer
743 /* Token Priorities {{{ */
762 /* Lexer State {{{ */
763 LexPushInOn: { driver.in_.push(true); };
764 LexPushInOff: { driver.in_.push(false); };
765 LexPopIn: { driver.in_.pop(); };
767 LexPushReturnOn: { driver.return_.push(true); };
768 LexPopReturn: { driver.return_.pop(); };
769 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
771 LexPushSuperOn: { driver.super_.push(true); };
772 LexPushSuperOff: { driver.super_.push(false); };
773 LexPopSuper: { driver.super_.pop(); };
774 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
776 LexPushYieldOn: { driver.yield_.push(true); };
777 LexPushYieldOff: { driver.yield_.push(false); };
778 LexPopYield: { driver.yield_.pop(); };
781 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
785 : { 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::__); }
789 : { CYMAP(YieldStar, Star); }
793 : { CYMAP(OpenBrace_, OpenBrace); }
797 : { CYMAP(_class__, _class_); }
801 : { CYMAP(_function__, _function_); }
805 : LexNoBrace LexNoClass LexNoFunction
808 /* Virtual Tokens {{{ */
814 /* 11.6 Names and Keywords {{{ */
816 : Word[pass] { $$ = $pass; }
817 | "for" { $$ = CYNew CYWord("for"); }
818 | "in" { $$ = CYNew CYWord("in"); }
819 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
823 : IdentifierNoOf[pass] { $$ = $pass; }
824 | "break" { $$ = CYNew CYWord("break"); }
825 | "case" { $$ = CYNew CYWord("case"); }
826 | "catch" { $$ = CYNew CYWord("catch"); }
827 | "class" LexOf { $$ = CYNew CYWord("class"); }
828 | ";class" { $$ = CYNew CYWord("class"); }
829 | "const" { $$ = CYNew CYWord("const"); }
830 | "continue" { $$ = CYNew CYWord("continue"); }
831 | "debugger" { $$ = CYNew CYWord("debugger"); }
832 | "default" { $$ = CYNew CYWord("default"); }
833 | "do" { $$ = CYNew CYWord("do"); }
834 | "else" { $$ = CYNew CYWord("else"); }
835 | "enum" { $$ = CYNew CYWord("enum"); }
836 | "export" { $$ = CYNew CYWord("export"); }
837 | "extends" { $$ = CYNew CYWord("extends"); }
838 | "false" { $$ = CYNew CYWord("false"); }
839 | "finally" { $$ = CYNew CYWord("finally"); }
840 | "function" LexOf { $$ = CYNew CYWord("function"); }
841 | "if" { $$ = CYNew CYWord("if"); }
842 | "import" { $$ = CYNew CYWord("import"); }
843 | "!in" { $$ = CYNew CYWord("in"); }
844 | "!of" { $$ = CYNew CYWord("of"); }
845 | "null" { $$ = CYNew CYWord("null"); }
846 | "return" { $$ = CYNew CYWord("return"); }
847 | "super" { $$ = CYNew CYWord("super"); }
848 | "switch" { $$ = CYNew CYWord("switch"); }
849 | "this" { $$ = CYNew CYWord("this"); }
850 | "throw" { $$ = CYNew CYWord("throw"); }
851 | "true" { $$ = CYNew CYWord("true"); }
852 | "try" { $$ = CYNew CYWord("try"); }
853 | "var" { $$ = CYNew CYWord("var"); }
854 | "while" { $$ = CYNew CYWord("while"); }
855 | "with" { $$ = CYNew CYWord("with"); }
859 : WordNoUnary[pass] { $$ = $pass; }
860 | "delete" { $$ = CYNew CYWord("delete"); }
861 | "typeof" { $$ = CYNew CYWord("typeof"); }
862 | "void" { $$ = CYNew CYWord("void"); }
863 | "yield" { $$ = CYNew CYIdentifier("yield"); }
868 : Word[pass] { $$ = $pass; }
873 /* 11.8.1 Null Literals {{{ */
875 : "null" { $$ = CYNew CYNull(); }
878 /* 11.8.2 Boolean Literals {{{ */
880 : "true" { $$ = CYNew CYTrue(); }
881 | "false" { $$ = CYNew CYFalse(); }
884 /* 11.8.5 Regular Expression Literals {{{ */
885 RegularExpressionSlash
886 : "/" { $$ = false; }
887 | "/=" { $$ = true; }
890 RegularExpressionLiteral
891 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
895 /* 11.9 Automatic Semicolon Insertion {{{ */
897 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
905 : LexNewLineOrNot "\n"
910 : LexNewLineOrNot "\n" StrictSemi
911 | NewLineNot LexOf Terminator
916 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
921 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
926 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
930 /* 12.1 Identifiers {{{ */
932 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
933 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
937 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
938 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
939 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
943 : BindingIdentifier[pass] { $$ = $pass; }
944 | LexOf { $$ = NULL; }
948 : Identifier[pass] { $$ = $pass; }
949 | "yield" { $$ = CYNew CYIdentifier("yield"); }
953 : Identifier_[pass] { $$ = $pass; }
954 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
955 | "as" { $$ = CYNew CYIdentifier("as"); }
956 | "await" { $$ = CYNew CYIdentifier("await"); }
957 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
958 | "byte" { $$ = CYNew CYIdentifier("byte"); }
959 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
960 | "double" { $$ = CYNew CYIdentifier("double"); }
961 | "each" { $$ = CYNew CYIdentifier("each"); }
962 | "eval" { $$ = CYNew CYIdentifier("eval"); }
963 | "final" { $$ = CYNew CYIdentifier("final"); }
964 | "float" { $$ = CYNew CYIdentifier("float"); }
965 | "from" { $$ = CYNew CYIdentifier("from"); }
966 | "get" { $$ = CYNew CYIdentifier("get"); }
967 | "goto" { $$ = CYNew CYIdentifier("goto"); }
968 | "implements" { $$ = CYNew CYIdentifier("implements"); }
969 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
970 | "interface" { $$ = CYNew CYIdentifier("interface"); }
971 | "let" { $$ = CYNew CYIdentifier("let"); }
972 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
973 | "native" { $$ = CYNew CYIdentifier("native"); }
974 | "package" { $$ = CYNew CYIdentifier("package"); }
975 | "private" { $$ = CYNew CYIdentifier("private"); }
976 | "protected" { $$ = CYNew CYIdentifier("protected"); }
977 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
978 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
979 | "public" { $$ = CYNew CYIdentifier("public"); }
980 | "set" { $$ = CYNew CYIdentifier("set"); }
981 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
982 | "target" { $$ = CYNew CYIdentifier("target"); }
983 | "throws" { $$ = CYNew CYIdentifier("throws"); }
984 | "transient" { $$ = CYNew CYIdentifier("transient"); }
985 | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
986 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
988 | "bool" { $$ = CYNew CYIdentifier("bool"); }
989 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
990 | "id" { $$ = CYNew CYIdentifier("id"); }
991 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
996 : IdentifierTypeNoOf[pass] { $$ = $pass; }
997 | "of" { $$ = CYNew CYIdentifier("of"); }
1001 : IdentifierType[pass] { $$ = $pass; }
1006 : IdentifierTypeNoOf
1007 | "char" { $$ = CYNew CYIdentifier("char"); }
1008 | "int" { $$ = CYNew CYIdentifier("int"); }
1009 | "long" { $$ = CYNew CYIdentifier("long"); }
1010 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1011 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1012 | "short" { $$ = CYNew CYIdentifier("short"); }
1013 | "static" { $$ = CYNew CYIdentifier("static"); }
1014 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1016 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1017 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1020 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1021 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1022 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1023 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1028 : IdentifierNoOf[pass] { $$ = $pass; }
1029 | "of" { $$ = CYNew CYIdentifier("of"); }
1030 | "!of" { $$ = CYNew CYIdentifier("of"); }
1033 /* 12.2 Primary Expression {{{ */
1035 : "this" { $$ = CYNew CYThis(); }
1036 | IdentifierReference[pass] { $$ = $pass; }
1037 | Literal[pass] { $$ = $pass; }
1038 | ArrayLiteral[pass] { $$ = $pass; }
1039 | ObjectLiteral[pass] { $$ = $pass; }
1040 | FunctionExpression[pass] { $$ = $pass; }
1041 | ClassExpression[pass] { $$ = $pass; }
1042 | GeneratorExpression[pass] { $$ = $pass; }
1043 | RegularExpressionLiteral[pass] { $$ = $pass; }
1044 | TemplateLiteral[pass] { $$ = $pass; }
1045 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1046 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1049 CoverParenthesizedExpressionAndArrowParameterList
1050 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1051 | "(" LexOf ")" { $$ = NULL; }
1052 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1053 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1056 /* 12.2.4 Literals {{{ */
1058 : NullLiteral[pass] { $$ = $pass; }
1059 | BooleanLiteral[pass] { $$ = $pass; }
1060 | NumericLiteral[pass] { $$ = $pass; }
1061 | StringLiteral[pass] { $$ = $pass; }
1064 /* 12.2.5 Array Initializer {{{ */
1066 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1070 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1071 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1075 : "," ElementListOpt[elements] { $$ = $elements; }
1080 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1081 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1085 : ElementList[pass] { $$ = $pass; }
1086 | LexOf { $$ = NULL; }
1089 /* 12.2.6 Object Initializer {{{ */
1091 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1094 PropertyDefinitionList_
1095 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1099 PropertyDefinitionList
1100 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1103 PropertyDefinitionListOpt
1104 : PropertyDefinitionList[properties] { $$ = $properties; }
1109 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1110 | CoverInitializedName[name] { CYNOT(@$); }
1111 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1112 | MethodDefinition[pass] { $$ = $pass; }
1116 : LiteralPropertyName[pass] { $$ = $pass; }
1117 | ComputedPropertyName[pass] { $$ = $pass; }
1121 : IdentifierName[pass] { $$ = $pass; }
1122 | StringLiteral[pass] { $$ = $pass; }
1123 | NumericLiteral[pass] { $$ = $pass; }
1126 ComputedPropertyName
1127 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1130 CoverInitializedName
1131 : IdentifierReference Initializer
1135 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1139 : Initializer[pass] { $$ = $pass; }
1143 /* 12.2.9 Template Literals {{{ */
1145 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1146 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1150 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1151 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1155 /* 12.3 Left-Hand-Side Expressions {{{ */
1157 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1158 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1159 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1160 | TemplateLiteral { CYNOT(@$); }
1164 : PrimaryExpression[pass] { $$ = $pass; }
1165 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1166 | SuperProperty[pass] { $$ = $pass; }
1167 | MetaProperty { CYNOT(@$); }
1168 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1172 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1173 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1181 : "new" "." "target"
1185 : MemberExpression[pass] { $$ = $pass; }
1186 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1190 : MemberExpression[pass] { $$ = $pass; }
1191 | CallExpression[pass] { $$ = $pass; }
1195 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1196 | SuperCall[pass] { $$ = $pass; }
1197 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1201 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1205 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1209 : "," ArgumentList[arguments] { $$ = $arguments; }
1214 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1215 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1219 : ArgumentList[pass] { $$ = $pass; }
1220 | LexOf { $$ = NULL; }
1224 : NewExpression[pass] { $$ = $pass; }
1225 | CallExpression[pass] { $$ = $pass; }
1228 LeftHandSideExpression
1229 : RubyBlockExpression[pass] { $$ = $pass; }
1230 | IndirectExpression[pass] { $$ = $pass; }
1233 /* 12.4 Postfix Expressions {{{ */
1235 : RubyBlockExpression[pass] { $$ = $pass; }
1236 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1237 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1240 /* 12.5 Unary Operators {{{ */
1242 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1243 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1244 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1245 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1246 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1247 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1248 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1249 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1250 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1254 : PostfixExpression[expression] { $$ = $expression; }
1255 | UnaryExpression_[pass] { $$ = $pass; }
1258 /* 12.6 Multiplicative Operators {{{ */
1259 MultiplicativeExpression
1260 : UnaryExpression[pass] { $$ = $pass; }
1261 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1262 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1263 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1266 /* 12.7 Additive Operators {{{ */
1268 : MultiplicativeExpression[pass] { $$ = $pass; }
1269 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1270 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1273 /* 12.8 Bitwise Shift Operators {{{ */
1275 : AdditiveExpression[pass] { $$ = $pass; }
1276 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1277 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1278 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1281 /* 12.9 Relational Operators {{{ */
1282 RelationalExpression
1283 : ShiftExpression[pass] { $$ = $pass; }
1284 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1285 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1286 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1287 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1288 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1289 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1292 /* 12.10 Equality Operators {{{ */
1294 : RelationalExpression[pass] { $$ = $pass; }
1295 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1296 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1297 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1298 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1301 /* 12.11 Binary Bitwise Operators {{{ */
1302 BitwiseANDExpression
1303 : EqualityExpression[pass] { $$ = $pass; }
1304 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1307 BitwiseXORExpression
1308 : BitwiseANDExpression[pass] { $$ = $pass; }
1309 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1313 : BitwiseXORExpression[pass] { $$ = $pass; }
1314 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1317 /* 12.12 Binary Logical Operators {{{ */
1318 LogicalANDExpression
1319 : BitwiseORExpression[pass] { $$ = $pass; }
1320 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1324 : LogicalANDExpression[pass] { $$ = $pass; }
1325 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1328 /* 12.13 Conditional Operator ( ? : ) {{{ */
1330 ConditionalExpressionClassic
1331 : LogicalORExpression[pass] { $$ = $pass; }
1332 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1336 ConditionalExpression
1337 : LogicalORExpression[pass] { $$ = $pass; }
1338 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1341 /* 12.14 Assignment Operators {{{ */
1342 LeftHandSideAssignment
1343 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1344 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1345 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1346 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1347 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1348 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1349 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1350 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1351 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1352 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1353 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1354 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1358 AssignmentExpressionClassic
1359 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1360 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1364 AssignmentExpression
1365 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1366 | LexOf YieldExpression[pass] { $$ = $pass; }
1367 | ArrowFunction[pass] { $$ = $pass; }
1368 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1371 /* 12.15 Comma Operator ( , ) {{{ */
1373 : AssignmentExpression[pass] { $$ = $pass; }
1374 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1378 : Expression[pass] { $$ = $pass; }
1379 | LexOf { $$ = NULL; }
1383 /* 13 Statements and Declarations {{{ */
1385 : BlockStatement[pass] { $$ = $pass; }
1386 | VariableStatement[pass] { $$ = $pass; }
1387 | EmptyStatement[pass] { $$ = $pass; }
1388 | IfStatement[pass] { $$ = $pass; }
1389 | BreakableStatement[pass] { $$ = $pass; }
1390 | ContinueStatement[pass] { $$ = $pass; }
1391 | BreakStatement[pass] { $$ = $pass; }
1392 | ReturnStatement[pass] { $$ = $pass; }
1393 | WithStatement[pass] { $$ = $pass; }
1394 | LabelledStatement[pass] { $$ = $pass; }
1395 | ThrowStatement[pass] { $$ = $pass; }
1396 | TryStatement[pass] { $$ = $pass; }
1397 | DebuggerStatement[pass] { $$ = $pass; }
1401 : LexOf Statement__[pass] { $$ = $pass; }
1402 | ExpressionStatement[pass] { $$ = $pass; }
1406 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1410 : HoistableDeclaration[pass] { $$ = $pass; }
1411 | ClassDeclaration[pass] { $$ = $pass; }
1415 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1416 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1419 HoistableDeclaration
1420 : FunctionDeclaration[pass] { $$ = $pass; }
1421 | GeneratorDeclaration[pass] { $$ = $pass; }
1425 : IterationStatement[pass] { $$ = $pass; }
1426 | SwitchStatement[pass] { $$ = $pass; }
1429 /* 13.2 Block {{{ */
1431 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1435 : "{" StatementListOpt[code] "}" { $$ = $code; }
1439 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1443 : StatementList[pass] { $$ = $pass; }
1444 | LexSetStatement LexLet LexOf { $$ = NULL; }
1448 : Statement[pass] { $$ = $pass; }
1449 | Declaration[pass] { $$ = $pass; }
1452 /* 13.3 Let and Const Declarations {{{ */
1454 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1458 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1462 : { CYMAP(_let__, _let_); }
1466 : { CYMAP(_of__, _of_); }
1470 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1474 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1475 | LexLet LexOf "const" { $$ = true; }
1479 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1484 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1488 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1489 | LexOf BindingPattern Initializer { CYNOT(@$); }
1492 /* 13.3.2 Variable Statement {{{ */
1494 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1498 : VariableStatement_[statement] Terminator { $$ = $statement; }
1501 VariableDeclarationList_
1502 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1506 VariableDeclarationList
1507 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1511 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1512 | LexOf BindingPattern Initializer { CYNOT(@$); }
1515 /* 13.3.3 Destructuring Binding Patterns {{{ */
1517 : ObjectBindingPattern
1518 | ArrayBindingPattern
1521 ObjectBindingPattern
1522 : "let {" BindingPropertyListOpt "}"
1526 : "let [" BindingElementListOpt "]"
1529 BindingPropertyList_
1530 : "," BindingPropertyListOpt
1535 : BindingProperty BindingPropertyList_
1538 BindingPropertyListOpt
1539 : BindingPropertyList
1544 : BindingElementOpt[element] "," BindingElementListOpt[next]
1545 | BindingRestElement[element]
1546 | BindingElement[element]
1549 BindingElementListOpt
1550 : BindingElementList[pass]
1556 | LexOf PropertyName ":" BindingElement
1560 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1561 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1565 : BindingElement[pass]
1570 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1574 : LexBind LexOf "..." BindingIdentifier
1577 /* 13.4 Empty Statement {{{ */
1579 : ";" { $$ = CYNew CYEmpty(); }
1582 /* 13.5 Expression Statement {{{ */
1583 ExpressionStatement_
1584 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1587 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1590 /* 13.6 The if Statement {{{ */
1592 : "else" Statement[false] { $$ = $false; }
1593 | %prec "if" { $$ = NULL; }
1597 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1600 /* 13.7 Iteration Statements {{{ */
1602 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1603 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1604 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1605 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1606 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1607 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1610 ForStatementInitializer
1611 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1612 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1613 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1614 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1617 ForInStatementInitializer
1618 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1619 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1620 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1621 | ForDeclaration[pass] { $$ = $pass; }
1625 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1629 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1630 | LexOf BindingPattern { CYNOT(@$); }
1633 /* 13.8 The continue Statement {{{ */
1635 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1636 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1639 /* 13.9 The break Statement {{{ */
1641 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1642 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1645 /* 13.10 The return Statement {{{ */
1647 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1648 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1651 /* 13.11 The with Statement {{{ */
1653 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1656 /* 13.12 The switch Statement {{{ */
1658 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1662 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1666 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1670 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1671 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1675 // XXX: the standard makes certain you can only have one of these
1677 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1680 /* 13.13 Labelled Statements {{{ */
1682 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1686 : Statement[pass] { $$ = $pass; }
1687 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1690 /* 13.14 The throw Statement {{{ */
1692 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1693 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1696 /* 13.15 The try Statement {{{ */
1698 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1699 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1700 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1704 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1708 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1712 : BindingIdentifier[pass] { $$ = $pass; }
1713 | LexOf BindingPattern { CYNOT(@$); }
1716 /* 13.16 The debugger Statement {{{ */
1718 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1722 /* 14.1 Function Definitions {{{ */
1724 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1728 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1731 StrictFormalParameters
1732 : FormalParameters[pass] { $$ = $pass; }
1736 : LexBind LexOf { $$ = NULL; }
1737 | FormalParameterList
1740 FormalParameterList_
1741 : "," FormalParameterList[parameters] { $$ = $parameters; }
1746 : FunctionRestParameter { CYNOT(@$); }
1747 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1750 FunctionRestParameter
1751 : BindingRestElement
1755 : BindingElement[pass] { $$ = $pass; }
1759 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1762 FunctionStatementList
1763 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1766 /* 14.2 Arrow Function Definitions {{{ */
1768 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1772 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1773 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1777 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1778 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1781 /* 14.3 Method Definitions {{{ */
1783 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1784 | GeneratorMethod[pass] { $$ = $pass; }
1785 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1786 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1789 PropertySetParameterList
1790 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1793 /* 14.4 Generator Function Definitions {{{ */
1795 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1798 GeneratorDeclaration
1799 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1803 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1807 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1811 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1812 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield"
1813 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1814 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1817 /* 14.5 Class Definitions {{{ */
1819 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1823 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1827 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1831 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1835 : ClassHeritage[pass] { $$ = $pass; }
1836 | { $$ = CYNew CYClassTail(NULL); }
1849 : ClassElementListOpt ClassElement
1858 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1859 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1864 /* 15.1 Scripts {{{ */
1866 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1870 : StatementList[pass] { $$ = $pass; }
1874 : ScriptBody[pass] { $$ = $pass; }
1875 | LexSetStatement LexLet LexOf { $$ = NULL; }
1878 /* 15.2 Modules {{{ */
1880 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1884 : ModuleItemList[pass] { $$ = $pass; }
1888 : ModuleBody[pass] { $$ = $pass; }
1889 | LexSetStatement LexLet LexOf { $$ = NULL; }
1893 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1897 : ModuleItemList[pass] { $$ = $pass; }
1898 | LexSetStatement LexLet LexOf { $$ = NULL; }
1902 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1903 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1904 | StatementListItem[pass] { $$ = $pass; }
1907 /* 15.2.2 Imports {{{ */
1909 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1910 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1914 : ImportedDefaultBinding[default] { $$ = $default; }
1915 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1916 | LexOf NamedImports[pass] { $$ = $pass; }
1917 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1918 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1921 ImportedDefaultBinding
1922 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1926 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1930 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1934 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1938 : "," ImportsListOpt[pass] { $$ = $pass; }
1943 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1947 : ImportsList[pass] { $$ = $pass; }
1948 | LexOf { $$ = NULL; }
1952 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1953 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1957 : StringLiteral[pass] { $$ = $pass; }
1961 : BindingIdentifier[pass] { $$ = $pass; }
1964 /* 15.2.3 Exports {{{ */
1966 : "*" FromClause Terminator
1967 | ExportClause FromClause Terminator
1968 | ExportClause Terminator
1970 | "default" LexSetStatement LexOf HoistableDeclaration
1971 | "default" LexSetStatement LexOf ClassDeclaration
1972 | "default" LexSetStatement AssignmentExpression Terminator
1976 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1977 | "export" Declaration
1981 : ";{" ExportsListOpt "}"
1985 : "," ExportsListOpt
1990 : ExportSpecifier ExportsList_
2000 | IdentifierName "as" IdentifierName
2005 /* Cycript (C): Type Encoding {{{ */
2007 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
2008 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2012 : { $$ = CYNew CYTypedIdentifier(@$); }
2016 : TypeSignifier[pass] { $$ = $pass; }
2017 | TypeSignifierNone[pass] { $$ = $pass; }
2034 ParameterModifierOpt
2040 : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
2044 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2045 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2046 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2047 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2051 : SuffixedType[pass] { $$ = $pass; }
2052 | TypeSignifierOpt[pass] { $$ = $pass; }
2056 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2060 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2061 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2064 TypeQualifierLeftOpt
2065 : TypeQualifierLeft[pass] { $$ = $pass; }
2070 : SuffixedType[pass] { $$ = $pass; }
2071 | PrefixedType[pass] { $$ = $pass; }
2072 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2073 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2074 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2077 TypeQualifierRightOpt
2078 : TypeQualifierRight[pass] { $$ = $pass; }
2079 | TypeSignifierOpt[pass] { $$ = $pass; }
2083 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2084 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2085 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2086 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2087 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2091 : IntegerType[pass] { $$ = $pass; }
2092 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2096 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2101 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2102 | IntegerType[pass] { $$ = $pass; }
2103 | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
2104 | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
2105 | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
2106 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2109 TypedIdentifierMaybe
2110 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2111 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2112 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2116 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2120 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2123 TypedIdentifierField
2124 : TypedIdentifierYes[pass] { $$ = $pass; }
2125 | 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; }
2128 TypedIdentifierEncoding
2129 : TypedIdentifierNo[pass] { $$ = $pass; }
2130 | 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; }
2133 TypedIdentifierDefinition
2134 : TypedIdentifierYes[pass] { $$ = $pass; }
2135 | 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; }
2139 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2145 /* Cycript (Objective-C): @class Declaration {{{ */
2147 /* XXX: why the hell did I choose MemberExpression? */
2148 : ":" MemberExpression[extends] { $$ = $extends; }
2152 ImplementationFieldListOpt
2153 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2158 : "+" { $$ = false; }
2159 | "-" { $$ = true; }
2163 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2164 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2168 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2171 MessageParameterList
2172 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2175 MessageParameterListOpt
2176 : MessageParameterList[pass] { $$ = $pass; }
2177 | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
2181 : MessageParameterList[pass] { $$ = $pass; }
2182 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2185 ClassMessageDeclaration
2186 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2189 ClassMessageDeclarationListOpt
2190 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2194 // XXX: this should be AssignmentExpressionNoRight
2196 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2200 : "," ClassProtocols[protocols] { $$ = $protocols; }
2204 ClassProtocolListOpt
2205 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2209 ImplementationStatement
2210 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2218 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2222 : ImplementationStatement[pass] { $$ = $pass; }
2223 | CategoryStatement[pass] { $$ = $pass; }
2226 /* Cycript (Objective-C): Send Message {{{ */
2228 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2233 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2234 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2238 : SelectorCall[pass] { $$ = $pass; }
2239 | VariadicCall[pass] { $$ = $pass; }
2243 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2247 : SelectorCall[pass] { $$ = $pass; }
2248 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2252 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2253 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2257 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2261 : SelectorExpression_[pass] { $$ = $pass; }
2262 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2265 SelectorExpressionOpt
2266 : SelectorExpression_[pass] { $$ = $pass; }
2271 : MessageExpression[pass] { $$ = $pass; }
2272 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2277 /* Cycript: @import Directive {{{ */
2279 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2280 | Word[part] { $$ = CYNew CYModule($part); }
2284 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2289 /* Cycript (Objective-C): Boxed Expressions {{{ */
2291 : NullLiteral[pass] { $$ = $pass; }
2292 | BooleanLiteral[pass] { $$ = $pass; }
2293 | NumericLiteral[pass] { $$ = $pass; }
2294 | StringLiteral[pass] { $$ = $pass; }
2295 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2296 | "YES" { $$ = CYNew CYTrue(); }
2297 | "NO" { $$ = CYNew CYFalse(); }
2301 : "," KeyValuePairListOpt[next] { $$ = $next; }
2305 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2309 : KeyValuePairList[pass] { $$ = $pass; }
2310 | LexOf { $$ = NULL; }
2314 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2315 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2316 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2318 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2319 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2320 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2321 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2322 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2325 /* Cycript (Objective-C): Block Expressions {{{ */
2327 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2330 /* Cycript (Objective-C): Instance Literals {{{ */
2332 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2338 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2340 : IndirectExpression[pass] { $$ = $pass; }
2344 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2348 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2352 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2353 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2354 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2357 /* Cycript (C): Lambda Expressions {{{ */
2359 : "," TypedParameterList[parameters] { $$ = $parameters; }
2360 | { $$ = CYNew CYTypedFormal(false); }
2364 : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
2365 | "..." { $$ = CYNew CYTypedFormal(true); }
2368 TypedParameterListOpt
2369 : TypedParameterList[pass] { $$ = $pass; }
2370 | "void" { $$ = CYNew CYTypedFormal(false); }
2371 | { $$ = CYNew CYTypedFormal(false); }
2375 : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
2379 : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2382 /* Cycript (C): Structure Definitions {{{ */
2384 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2388 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2392 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2395 /* Cycript (C): Type Definitions {{{ */
2397 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2401 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2405 : TypeDefinition[pass] { $$ = $pass; }
2409 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2412 /* Cycript (C): extern "C" {{{ */
2414 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2418 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2419 | TypeDefinition[pass] { $$ = $pass; }
2422 ExternCStatementListOpt
2423 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2428 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2429 | ExternCStatement[pass] { $$ = $pass; }
2433 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2439 /* Lexer State {{{ */
2441 : { driver.PushCondition(CYDriver::RegExpCondition); }
2445 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2449 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2453 : { driver.PopCondition(); }
2457 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2461 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2464 /* Virtual Tokens {{{ */
2471 /* 8.1 Context Keywords {{{ */
2473 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2474 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2477 /* 8.3 XML Initializer Input Elements {{{ */
2479 : XMLComment { $$ = $1; }
2480 | XMLCDATA { $$ = $1; }
2481 | XMLPI { $$ = $1; }
2485 /* 11.1 Primary Expressions {{{ */
2487 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2488 | XMLInitilizer { $$ = $1; }
2489 | XMLListInitilizer { $$ = $1; }
2493 : AttributeIdentifier { $$ = $1; }
2494 | QualifiedIdentifier { $$ = $1; }
2495 | WildcardIdentifier { $$ = $1; }
2498 /* 11.1.1 Attribute Identifiers {{{ */
2500 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2504 : PropertySelector { $$ = $1; }
2505 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2509 : Identifier { $$ = CYNew CYSelector($1); }
2510 | WildcardIdentifier { $$ = $1; }
2513 /* 11.1.2 Qualified Identifiers {{{ */
2514 QualifiedIdentifier_
2515 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2516 | QualifiedIdentifier { $$ = $1; }
2520 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2523 /* 11.1.3 Wildcard Identifiers {{{ */
2525 : "*" { $$ = CYNew CYWildcard(); }
2528 /* 11.1.4 XML Initializer {{{ */
2530 : XMLMarkup { $$ = $1; }
2531 | XMLElement { $$ = $1; }
2535 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2536 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2540 : LexPushXMLTag XMLTagName XMLAttributes
2544 : "{" LexPushRegExp Expression LexPop "}"
2553 : XMLAttributes_ XMLAttribute
2558 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2559 | XMLAttributes_ XMLWhitespaceOpt
2568 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2572 : XMLExpression XMLElementContentOpt
2573 | XMLMarkup XMLElementContentOpt
2574 | XMLText XMLElementContentOpt
2575 | XMLElement XMLElementContentOpt
2578 XMLElementContentOpt
2583 /* 11.1.5 XMLList Initializer {{{ */
2585 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2589 /* 11.2 Left-Hand-Side Expressions {{{ */
2591 : Identifier { $$ = $1; }
2592 | PropertyIdentifier { $$ = $1; }
2596 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2597 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2598 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2601 /* 12.1 The default xml namespace Statement {{{ */
2602 /* XXX: DefaultXMLNamespaceStatement
2603 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2607 : DefaultXMLNamespaceStatement { $$ = $1; }
2612 /* JavaScript FTL: Array Comprehensions {{{ */
2614 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2618 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2621 /* JavaScript FTL: for each {{{ */
2623 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2627 /* JavaScript FTW: Array Comprehensions {{{ */
2629 : ArrayComprehension
2633 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2637 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2642 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2643 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2647 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2648 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2652 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2655 /* JavaScript FTW: Named Arguments {{{ */
2657 : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2661 /* JavaScript FTW: Ruby Blocks {{{ */
2662 RubyProcParameterList_
2663 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2667 RubyProcParameterList
2668 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2669 | LexOf { $$ = NULL; }
2673 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2674 | "||" { $$ = NULL; }
2677 RubyProcParametersOpt
2678 : RubyProcParameters[pass] { $$ = $pass; }
2683 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2687 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2690 RubyBlockExpression_
2691 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2692 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2696 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2697 | RubyBlockExpression_[pass] { $$ = $pass; }
2700 /* JavaScript FTW: Ruby Scopes {{{ */
2702 : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); }
2703 | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); }
2704 | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; }
2707 /* JavaScript FTW: Ruby Symbols {{{ */
2709 : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); }
2715 bool CYDriver::Parse(CYMark mark) {
2717 CYLocal<CYPool> local(&pool_);
2718 cy::parser parser(*this);
2720 parser.set_debug_level(debug_);
2722 return parser.parse() != 0;
2725 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2729 CYDriver::Error error;
2730 error.warning_ = true;
2731 error.location_ = location;
2732 error.message_ = message;
2733 errors_.push_back(error);
2736 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2737 CYDriver::Error error;
2738 error.warning_ = false;
2739 error.location_ = location;
2740 error.message_ = message;
2741 driver.errors_.push_back(error);