1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define YYSTACKEXPANDABLE 1
30 #define CYNew new(driver.pool_)
33 #include "ObjectiveC/Syntax.hpp"
37 #include "E4X/Syntax.hpp"
40 #include "Highlight.hpp"
43 %union { bool bool_; }
45 %union { CYMember *access_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBinding *binding_; }
49 %union { CYBindings *bindings_; }
50 %union { CYBoolean *boolean_; }
51 %union { CYClause *clause_; }
52 %union { cy::Syntax::Catch *catch_; }
53 %union { CYClassTail *classTail_; }
54 %union { CYComprehension *comprehension_; }
55 %union { CYElement *element_; }
56 %union { CYExpression *expression_; }
57 %union { CYFalse *false_; }
58 %union { CYVariable *variable_; }
59 %union { CYFinally *finally_; }
60 %union { CYForInitializer *for_; }
61 %union { CYForInInitializer *forin_; }
62 %union { CYFunctionParameter *functionParameter_; }
63 %union { CYIdentifier *identifier_; }
64 %union { CYImportSpecifier *import_; }
65 %union { CYInfix *infix_; }
66 %union { CYLiteral *literal_; }
67 %union { CYMethod *method_; }
68 %union { CYModule *module_; }
69 %union { CYNull *null_; }
70 %union { CYNumber *number_; }
71 %union { CYParenthetical *parenthetical_; }
72 %union { CYProperty *property_; }
73 %union { CYPropertyName *propertyName_; }
74 %union { CYRubyProc *rubyProc_; }
75 %union { CYSpan *span_; }
76 %union { CYStatement *statement_; }
77 %union { CYString *string_; }
78 %union { CYTarget *target_; }
79 %union { CYThis *this_; }
80 %union { CYTrue *true_; }
81 %union { CYWord *word_; }
84 %union { CYTypeIntegral *integral_; }
85 %union { CYTypeStructField *structField_; }
86 %union { CYTypeModifier *modifier_; }
87 %union { CYTypeSpecifier *specifier_; }
88 %union { CYTypedIdentifier *typedIdentifier_; }
89 %union { CYTypedParameter *typedParameter_; }
93 %union { CYImplementationField *implementationField_; }
94 %union { CYMessage *message_; }
95 %union { CYMessageParameter *messageParameter_; }
96 %union { CYProtocol *protocol_; }
97 %union { CYSelectorPart *selector_; }
101 %union { CYAttribute *attribute_; }
102 %union { CYPropertyIdentifier *propertyIdentifier_; }
103 %union { CYSelector *selector_; }
109 cy::parser::semantic_type semantic_;
110 hi::Value highlight_;
113 int cylex(YYSTYPE *, CYLocation *, void *);
121 typedef cy::parser::token tk;
123 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
124 driver.newline_ = false;
127 int token(cylex(&data, location, driver.scanner_));
128 *semantic = data.semantic_;
132 case tk::OpenBracket:
134 driver.in_.push(false);
138 if (driver.in_.top())
143 case tk::CloseBracket:
150 if (driver.yield_.top())
151 token = tk::_yield__;
155 driver.newline_ = true;
163 #define yylex_(semantic, location, driver) ({ \
165 if (driver.hold_ == cy::parser::empty_symbol) \
166 type = yytranslate_(cylex_(semantic, location, driver)); \
168 type = driver.hold_; \
169 driver.hold_ = cy::parser::empty_symbol; \
173 #define CYLEX() do if (yyla.empty()) { \
174 YYCDEBUG << "Mapping a token: "; \
175 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
176 YY_SYMBOL_PRINT("Next token is", yyla); \
179 #define CYMAP(to, from) do { \
181 if (yyla.type == yytranslate_(token::from)) \
182 yyla.type = yytranslate_(token::to); \
185 #define CYERR(location, message) do { \
186 error(location, message); \
190 #define CYEOK() do { \
192 driver.errors_.pop_back(); \
195 #define CYNOT(location) \
196 CYERR(location, "unimplemented feature")
198 #define CYMPT(location) do { \
199 if (!yyla.empty() && yyla.type_get() != yyeof_) \
200 CYERR(location, "unexpected lookahead"); \
210 @$.begin.filename = @$.end.filename = &driver.filename_;
212 switch (driver.mark_) {
214 driver.hold_ = yytranslate_(token::MarkScript);
217 driver.hold_ = yytranslate_(token::MarkModule);
225 %define api.location.type { CYLocation }
232 %param { CYDriver &driver }
234 /* Token Declarations {{{ */
240 %token XMLAttributeValue
242 %token XMLTagCharacters
248 %token LeftRight "<>"
249 %token LeftSlashRight "</>"
251 %token SlashRight "/>"
252 %token LeftSlash "</"
254 %token ColonColon "::"
255 %token PeriodPeriod ".."
258 @begin E4X ObjectiveC
264 %token AmpersandAmpersand "&&"
265 %token AmpersandEqual "&="
267 %token CarrotEqual "^="
269 %token EqualEqual "=="
270 %token EqualEqualEqual "==="
271 %token EqualRight "=>"
272 %token Exclamation "!"
273 %token ExclamationEqual "!="
274 %token ExclamationEqualEqual "!=="
276 %token HyphenEqual "-="
277 %token HyphenHyphen "--"
278 %token HyphenRight "->"
280 %token LeftEqual "<="
282 %token LeftLeftEqual "<<="
284 %token PercentEqual "%="
286 %token PeriodPeriodPeriod "..."
288 %token PipeEqual "|="
291 %token PlusEqual "+="
294 %token RightEqual ">="
295 %token RightRight ">>"
296 %token RightRightEqual ">>="
297 %token RightRightRight ">>>"
298 %token RightRightRightEqual ">>>="
300 %token SlashEqual "/="
302 %token StarEqual "*="
315 %token CloseParen ")"
318 %token OpenBrace_ ";{"
319 %token OpenBrace_let "let {"
320 %token CloseBrace "}"
322 %token OpenBracket "["
323 %token OpenBracket_let "let ["
324 %token CloseBracket "]"
326 %token At_error_ "@error"
329 %token At_class_ "@class"
333 %token _typedef_ "typedef"
334 %token _unsigned_ "unsigned"
335 %token _signed_ "signed"
336 %token _struct_ "struct"
337 %token _extern_ "extern"
341 %token At_encode_ "@encode"
345 %token At_implementation_ "@implementation"
346 %token At_import_ "@import"
347 %token At_end_ "@end"
348 %token At_selector_ "@selector"
349 %token At_null_ "@null"
350 %token At_YES_ "@YES"
352 %token At_true_ "@true"
353 %token At_false_ "@false"
358 %token _false_ "false"
363 %token _break_ "break"
365 %token _catch_ "catch"
366 %token _class_ "class"
367 %token _class__ ";class"
368 %token _const_ "const"
369 %token _continue_ "continue"
370 %token _debugger_ "debugger"
371 %token _default_ "default"
372 %token _delete_ "delete"
376 %token _export_ "export"
377 %token _extends_ "extends"
378 %token _finally_ "finally"
380 %token _function_ "function"
381 %token _function__ ";function"
383 %token _import_ "import"
386 %token _Infinity_ "Infinity"
387 %token _instanceof_ "instanceof"
389 %token _return_ "return"
390 %token _super_ "super"
391 %token _switch_ "switch"
392 %token _target_ "target"
394 %token _throw_ "throw"
396 %token _typeof_ "typeof"
399 %token _while_ "while"
402 %token _abstract_ "abstract"
403 %token _await_ "await"
404 %token _boolean_ "boolean"
407 %token _constructor_ "constructor"
408 %token _double_ "double"
410 %token _final_ "final"
411 %token _float_ "float"
415 %token _implements_ "implements"
417 %token _interface_ "interface"
421 %token _native_ "native"
422 %token _package_ "package"
423 %token _private_ "private"
424 %token _protected_ "protected"
425 %token ___proto___ "__proto__"
426 %token _prototype_ "prototype"
427 %token _public_ "public"
428 %token ___restrict_ "__restrict"
429 %token _restrict_ "restrict"
431 %token _short_ "short"
432 %token _static_ "static"
433 %token _synchronized_ "synchronized"
434 %token _throws_ "throws"
435 %token _transient_ "transient"
436 %token _volatile_ "volatile"
437 %token _yield_ "yield"
438 %token _yield__ "!yield"
440 %token _undefined_ "undefined"
456 %token _namespace_ "namespace"
461 %token YieldStar "yield *"
463 %token <identifier_> Identifier_
464 %token <number_> NumericLiteral
465 %token <string_> StringLiteral
466 %token <literal_> RegularExpressionLiteral_
468 %token <string_> NoSubstitutionTemplate
469 %token <string_> TemplateHead
470 %token <string_> TemplateMiddle
471 %token <string_> TemplateTail
473 %type <target_> AccessExpression
474 %type <expression_> AdditiveExpression
475 %type <argument_> ArgumentList_
476 %type <argument_> ArgumentList
477 %type <argument_> ArgumentListOpt
478 %type <argument_> Arguments
479 %type <target_> ArrayComprehension
480 %type <literal_> ArrayLiteral
481 %type <expression_> ArrowFunction
482 %type <functionParameter_> ArrowParameters
483 %type <expression_> AssignmentExpression
484 %type <expression_> AssignmentExpressionOpt
485 %type <identifier_> BindingIdentifier
486 %type <identifier_> BindingIdentifierOpt
487 %type <bindings_> BindingList_
488 %type <bindings_> BindingList
489 %type <expression_> BitwiseANDExpression
490 %type <statement_> Block
491 %type <statement_> BlockStatement
492 %type <boolean_> BooleanLiteral
493 %type <binding_> BindingElement
494 %type <expression_> BitwiseORExpression
495 %type <expression_> BitwiseXORExpression
496 %type <statement_> BreakStatement
497 %type <statement_> BreakableStatement
498 %type <expression_> CallExpression_
499 %type <target_> CallExpression
500 %type <clause_> CaseBlock
501 %type <clause_> CaseClause
502 %type <clause_> CaseClausesOpt
504 %type <identifier_> CatchParameter
505 %type <statement_> ClassDeclaration
506 %type <target_> ClassExpression
507 %type <classTail_> ClassHeritage
508 %type <classTail_> ClassHeritageOpt
509 %type <classTail_> ClassTail
510 %type <target_> Comprehension
511 %type <comprehension_> ComprehensionFor
512 %type <comprehension_> ComprehensionIf
513 %type <comprehension_> ComprehensionTail
514 %type <propertyName_> ComputedPropertyName
515 %type <expression_> ConditionalExpression
516 %type <statement_> ContinueStatement
517 %type <statement_> ConciseBody
518 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
519 %type <statement_> DebuggerStatement
520 %type <statement_> Declaration_
521 %type <statement_> Declaration
522 %type <clause_> DefaultClause
523 %type <element_> ElementList
524 %type <element_> ElementListOpt
525 %type <statement_> ElseStatementOpt
526 %type <for_> EmptyStatement
527 %type <expression_> EqualityExpression
528 %type <expression_> Expression
529 %type <expression_> ExpressionOpt
530 %type <for_> ExpressionStatement_
531 %type <statement_> ExpressionStatement
532 %type <statement_> ExternC
533 %type <statement_> ExternCStatement
534 %type <statement_> ExternCStatementListOpt
535 %type <finally_> Finally
536 %type <binding_> ForBinding
537 %type <forin_> ForDeclaration
538 %type <forin_> ForInStatementInitializer
539 %type <for_> ForStatementInitializer
540 %type <binding_> FormalParameter
541 %type <functionParameter_> FormalParameterList_
542 %type <functionParameter_> FormalParameterList
543 %type <functionParameter_> FormalParameters
544 %type <string_> FromClause
545 %type <statement_> FunctionBody
546 %type <statement_> FunctionDeclaration
547 %type <target_> FunctionExpression
548 %type <statement_> FunctionStatementList
549 %type <statement_> GeneratorBody
550 %type <statement_> GeneratorDeclaration
551 %type <target_> GeneratorExpression
552 %type <method_> GeneratorMethod
553 %type <statement_> HoistableDeclaration
554 %type <identifier_> Identifier
555 %type <identifier_> IdentifierNoOf
556 %type <identifier_> IdentifierType
557 %type <identifier_> IdentifierTypeNoOf
558 %type <identifier_> IdentifierTypeOpt
559 %type <word_> IdentifierName
560 %type <variable_> IdentifierReference
561 %type <statement_> IfStatement
562 %type <import_> ImportClause
563 %type <statement_> ImportDeclaration
564 %type <import_> ImportSpecifier
565 %type <identifier_> ImportedBinding
566 %type <import_> ImportedDefaultBinding
567 %type <import_> ImportsList_
568 %type <import_> ImportsList
569 %type <import_> ImportsListOpt
570 %type <target_> IndirectExpression
571 %type <expression_> Initializer
572 %type <expression_> InitializerOpt
573 %type <statement_> IterationStatement
574 %type <identifier_> LabelIdentifier
575 %type <statement_> LabelledItem
576 %type <statement_> LabelledStatement
577 %type <assignment_> LeftHandSideAssignment
578 %type <target_> LeftHandSideExpression
579 %type <bool_> LetOrConst
580 %type <binding_> LexicalBinding
581 %type <for_> LexicalDeclaration_
582 %type <statement_> LexicalDeclaration
583 %type <literal_> Literal
584 %type <propertyName_> LiteralPropertyName
585 %type <expression_> LogicalANDExpression
586 %type <expression_> LogicalORExpression
587 %type <access_> MemberAccess
588 %type <target_> MemberExpression
589 %type <method_> MethodDefinition
590 %type <statement_> ModuleBody
591 %type <statement_> ModuleBodyOpt
592 %type <statement_> ModuleItem
593 %type <statement_> ModuleItemList
594 %type <statement_> ModuleItemListOpt
595 %type <module_> ModulePath
596 %type <string_> ModuleSpecifier
597 %type <expression_> MultiplicativeExpression
598 %type <import_> NameSpaceImport
599 %type <import_> NamedImports
600 %type <target_> NewExpression
601 %type <null_> NullLiteral
602 %type <literal_> ObjectLiteral
603 %type <expression_> PostfixExpression
604 %type <target_> PrimaryExpression
605 %type <propertyName_> PropertyName
606 %type <property_> PropertyDefinition
607 %type <property_> PropertyDefinitionList_
608 %type <property_> PropertyDefinitionList
609 %type <property_> PropertyDefinitionListOpt
610 %type <functionParameter_> PropertySetParameterList
611 %type <literal_> RegularExpressionLiteral
612 %type <bool_> RegularExpressionSlash
613 %type <expression_> RelationalExpression
614 %type <statement_> ReturnStatement
615 %type <target_> RubyBlockExpression_
616 %type <target_> RubyBlockExpression
617 %type <rubyProc_> RubyProcExpression
618 %type <functionParameter_> RubyProcParameterList_
619 %type <functionParameter_> RubyProcParameterList
620 %type <functionParameter_> RubyProcParameters
621 %type <functionParameter_> RubyProcParametersOpt
622 %type <statement_> Script
623 %type <statement_> ScriptBody
624 %type <statement_> ScriptBodyOpt
625 %type <expression_> ShiftExpression
626 %type <binding_> SingleNameBinding
627 %type <statement_> Statement__
628 %type <statement_> Statement_
629 %type <statement_> Statement
630 %type <statement_> StatementList
631 %type <statement_> StatementListOpt
632 %type <statement_> StatementListItem
633 %type <functionParameter_> StrictFormalParameters
634 %type <target_> SuperCall
635 %type <target_> SuperProperty
636 %type <statement_> SwitchStatement
637 %type <target_> TemplateLiteral
638 %type <span_> TemplateSpans
639 %type <statement_> ThrowStatement
640 %type <statement_> TryStatement
641 %type <statement_> TypeDefinition
642 %type <expression_> UnaryExpression_
643 %type <expression_> UnaryExpression
644 %type <binding_> VariableDeclaration
645 %type <bindings_> VariableDeclarationList_
646 %type <bindings_> VariableDeclarationList
647 %type <for_> VariableStatement_
648 %type <statement_> VariableStatement
649 %type <statement_> WithStatement
652 %type <word_> WordOpt
654 %type <expression_> YieldExpression
657 %type <integral_> IntegerType
658 %type <integral_> IntegerTypeOpt
659 %type <typedIdentifier_> PrefixedType
660 %type <specifier_> PrimitiveType
661 %type <structField_> StructFieldListOpt
662 %type <typedIdentifier_> SuffixedType
663 %type <typedIdentifier_> SuffixedTypeOpt
664 %type <typedIdentifier_> TypeSignifier
665 %type <typedIdentifier_> TypeSignifierNone
666 %type <typedIdentifier_> TypeSignifierOpt
667 %type <modifier_> ParameterTail
668 %type <modifier_> TypeQualifierLeft
669 %type <modifier_> TypeQualifierLeftOpt
670 %type <typedIdentifier_> TypeQualifierRight
671 %type <typedIdentifier_> TypeQualifierRightOpt
672 %type <typedIdentifier_> TypedIdentifierDefinition
673 %type <typedIdentifier_> TypedIdentifierEncoding
674 %type <typedIdentifier_> TypedIdentifierField
675 %type <typedIdentifier_> TypedIdentifierMaybe
676 %type <typedIdentifier_> TypedIdentifierNo
677 %type <typedIdentifier_> TypedIdentifierYes
678 %type <typedParameter_> TypedParameterList_
679 %type <typedParameter_> TypedParameterList
680 %type <typedParameter_> TypedParameterListOpt
684 %type <expression_> AssignmentExpressionClassic
685 %type <expression_> BoxableExpression
686 %type <statement_> CategoryStatement
687 %type <expression_> ClassSuperOpt
688 %type <expression_> ConditionalExpressionClassic
689 %type <message_> ClassMessageDeclaration
690 %type <message_> ClassMessageDeclarationListOpt
691 %type <protocol_> ClassProtocolListOpt
692 %type <protocol_> ClassProtocols
693 %type <protocol_> ClassProtocolsOpt
694 %type <implementationField_> ImplementationFieldListOpt
695 %type <statement_> ImplementationStatement
696 %type <target_> MessageExpression
697 %type <messageParameter_> MessageParameter
698 %type <messageParameter_> MessageParameters
699 %type <messageParameter_> MessageParameterList
700 %type <messageParameter_> MessageParameterListOpt
701 %type <bool_> MessageScope
702 %type <argument_> SelectorCall_
703 %type <argument_> SelectorCall
704 %type <selector_> SelectorExpression_
705 %type <selector_> SelectorExpression
706 %type <selector_> SelectorExpressionOpt
707 %type <argument_> SelectorList
708 %type <word_> SelectorWordOpt
709 %type <typedIdentifier_> TypeOpt
710 %type <argument_> VariadicCall
714 %type <propertyIdentifier_> PropertyIdentifier_
715 %type <selector_> PropertySelector_
716 %type <selector_> PropertySelector
717 %type <identifier_> QualifiedIdentifier_
718 %type <identifier_> QualifiedIdentifier
719 %type <identifier_> WildcardIdentifier
720 %type <identifier_> XMLComment
721 %type <identifier_> XMLCDATA
722 %type <identifier_> XMLElement
723 %type <identifier_> XMLElementContent
724 %type <identifier_> XMLMarkup
725 %type <identifier_> XMLPI
727 %type <attribute_> AttributeIdentifier
728 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
729 %type <expression_> PropertyIdentifier
730 %type <expression_> XMLListInitilizer
731 %type <expression_> XMLInitilizer
734 /* Token Priorities {{{ */
750 /* Lexer State {{{ */
751 LexPushInOn: { driver.in_.push(true); };
752 LexPushInOff: { driver.in_.push(false); };
753 LexPopIn: { driver.in_.pop(); };
755 LexPushReturnOn: { driver.return_.push(true); };
756 LexPopReturn: { driver.return_.pop(); };
757 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
759 LexPushSuperOn: { driver.super_.push(true); };
760 LexPushSuperOff: { driver.super_.push(false); };
761 LexPopSuper: { driver.super_.pop(); };
762 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
764 LexPushYieldOn: { driver.yield_.push(true); };
765 LexPushYieldOff: { driver.yield_.push(false); };
766 LexPopYield: { driver.yield_.pop(); };
769 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
773 : { 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::__); }
777 : { CYMAP(YieldStar, Star); }
781 : { CYMAP(OpenBrace_, OpenBrace); }
785 : { CYMAP(_class__, _class_); }
789 : { CYMAP(_function__, _function_); }
793 : LexNoBrace LexNoClass LexNoFunction
796 /* Virtual Tokens {{{ */
802 /* 11.6 Names and Keywords {{{ */
804 : Word[pass] { $$ = $pass; }
805 | "for" { $$ = CYNew CYWord("for"); }
806 | "in" { $$ = CYNew CYWord("in"); }
807 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
811 : IdentifierNoOf[pass] { $$ = $pass; }
812 | "break" { $$ = CYNew CYWord("break"); }
813 | "case" { $$ = CYNew CYWord("case"); }
814 | "catch" { $$ = CYNew CYWord("catch"); }
815 | "class" LexOf { $$ = CYNew CYWord("class"); }
816 | ";class" { $$ = CYNew CYWord("class"); }
817 | "const" { $$ = CYNew CYWord("const"); }
818 | "continue" { $$ = CYNew CYWord("continue"); }
819 | "debugger" { $$ = CYNew CYWord("debugger"); }
820 | "default" { $$ = CYNew CYWord("default"); }
821 | "delete" { $$ = CYNew CYWord("delete"); }
822 | "do" { $$ = CYNew CYWord("do"); }
823 | "else" { $$ = CYNew CYWord("else"); }
824 | "enum" { $$ = CYNew CYWord("enum"); }
825 | "export" { $$ = CYNew CYWord("export"); }
826 | "extends" { $$ = CYNew CYWord("extends"); }
827 | "false" { $$ = CYNew CYWord("false"); }
828 | "finally" { $$ = CYNew CYWord("finally"); }
829 | "function" LexOf { $$ = CYNew CYWord("function"); }
830 | "if" { $$ = CYNew CYWord("if"); }
831 | "import" { $$ = CYNew CYWord("import"); }
832 | "!in" { $$ = CYNew CYWord("in"); }
833 | "!of" { $$ = CYNew CYWord("of"); }
834 | "new" { $$ = CYNew CYWord("new"); }
835 | "null" { $$ = CYNew CYWord("null"); }
836 | "return" { $$ = CYNew CYWord("return"); }
837 | "super" { $$ = CYNew CYWord("super"); }
838 | "switch" { $$ = CYNew CYWord("switch"); }
839 | "this" { $$ = CYNew CYWord("this"); }
840 | "throw" { $$ = CYNew CYWord("throw"); }
841 | "true" { $$ = CYNew CYWord("true"); }
842 | "try" { $$ = CYNew CYWord("try"); }
843 | "typeof" { $$ = CYNew CYWord("typeof"); }
844 | "var" { $$ = CYNew CYWord("var"); }
845 | "void" { $$ = CYNew CYWord("void"); }
846 | "while" { $$ = CYNew CYWord("while"); }
847 | "with" { $$ = CYNew CYWord("with"); }
848 | "yield" { $$ = CYNew CYIdentifier("yield"); }
853 : Word[pass] { $$ = $pass; }
858 /* 11.8.1 Null Literals {{{ */
860 : "null" { $$ = CYNew CYNull(); }
863 /* 11.8.2 Boolean Literals {{{ */
865 : "true" { $$ = CYNew CYTrue(); }
866 | "false" { $$ = CYNew CYFalse(); }
869 /* 11.8.5 Regular Expression Literals {{{ */
870 RegularExpressionSlash
871 : "/" { $$ = false; }
872 | "/=" { $$ = true; }
875 RegularExpressionLiteral
876 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
880 /* 11.9 Automatic Semicolon Insertion {{{ */
882 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
890 : LexNewLineOrNot "\n"
895 : LexNewLineOrNot "\n" StrictSemi
896 | NewLineNot LexOf Terminator
901 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
906 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
911 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
915 /* 12.1 Identifiers {{{ */
917 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
918 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
922 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
923 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
924 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
928 : BindingIdentifier[pass] { $$ = $pass; }
929 | LexOf { $$ = NULL; }
933 : Identifier[pass] { $$ = $pass; }
934 | "yield" { $$ = CYNew CYIdentifier("yield"); }
938 : Identifier_[pass] { $$ = $pass; }
939 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
940 | "as" { $$ = CYNew CYIdentifier("as"); }
941 | "await" { $$ = CYNew CYIdentifier("await"); }
942 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
943 | "byte" { $$ = CYNew CYIdentifier("byte"); }
944 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
945 | "double" { $$ = CYNew CYIdentifier("double"); }
946 | "each" { $$ = CYNew CYIdentifier("each"); }
947 | "eval" { $$ = CYNew CYIdentifier("eval"); }
948 | "final" { $$ = CYNew CYIdentifier("final"); }
949 | "float" { $$ = CYNew CYIdentifier("float"); }
950 | "from" { $$ = CYNew CYIdentifier("from"); }
951 | "get" { $$ = CYNew CYIdentifier("get"); }
952 | "goto" { $$ = CYNew CYIdentifier("goto"); }
953 | "implements" { $$ = CYNew CYIdentifier("implements"); }
954 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
955 | "interface" { $$ = CYNew CYIdentifier("interface"); }
956 | "let" { $$ = CYNew CYIdentifier("let"); }
957 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
958 | "native" { $$ = CYNew CYIdentifier("native"); }
959 | "package" { $$ = CYNew CYIdentifier("package"); }
960 | "private" { $$ = CYNew CYIdentifier("private"); }
961 | "protected" { $$ = CYNew CYIdentifier("protected"); }
962 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
963 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
964 | "public" { $$ = CYNew CYIdentifier("public"); }
965 | "set" { $$ = CYNew CYIdentifier("set"); }
966 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
967 | "target" { $$ = CYNew CYIdentifier("target"); }
968 | "throws" { $$ = CYNew CYIdentifier("throws"); }
969 | "transient" { $$ = CYNew CYIdentifier("transient"); }
970 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
972 | "bool" { $$ = CYNew CYIdentifier("bool"); }
973 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
974 | "id" { $$ = CYNew CYIdentifier("id"); }
975 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
980 : IdentifierTypeNoOf[pass] { $$ = $pass; }
981 | "of" { $$ = CYNew CYIdentifier("of"); }
985 : IdentifierType[pass] { $$ = $pass; }
991 | "char" { $$ = CYNew CYIdentifier("char"); }
992 | "int" { $$ = CYNew CYIdentifier("int"); }
993 | "long" { $$ = CYNew CYIdentifier("long"); }
994 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
995 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
996 | "short" { $$ = CYNew CYIdentifier("short"); }
997 | "static" { $$ = CYNew CYIdentifier("static"); }
998 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1000 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1001 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1004 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1005 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1006 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1007 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1012 : IdentifierNoOf[pass] { $$ = $pass; }
1013 | "of" { $$ = CYNew CYIdentifier("of"); }
1014 | "!of" { $$ = CYNew CYIdentifier("of"); }
1017 /* 12.2 Primary Expression {{{ */
1019 : "this" { $$ = CYNew CYThis(); }
1020 | IdentifierReference[pass] { $$ = $pass; }
1021 | Literal[pass] { $$ = $pass; }
1022 | ArrayLiteral[pass] { $$ = $pass; }
1023 | ObjectLiteral[pass] { $$ = $pass; }
1024 | FunctionExpression[pass] { $$ = $pass; }
1025 | ClassExpression[pass] { $$ = $pass; }
1026 | GeneratorExpression[pass] { $$ = $pass; }
1027 | RegularExpressionLiteral[pass] { $$ = $pass; }
1028 | TemplateLiteral[pass] { $$ = $pass; }
1029 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1030 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1033 CoverParenthesizedExpressionAndArrowParameterList
1034 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1035 | "(" LexOf ")" { $$ = NULL; }
1036 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1037 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1040 /* 12.2.4 Literals {{{ */
1042 : NullLiteral[pass] { $$ = $pass; }
1043 | BooleanLiteral[pass] { $$ = $pass; }
1044 | NumericLiteral[pass] { $$ = $pass; }
1045 | StringLiteral[pass] { $$ = $pass; }
1048 /* 12.2.5 Array Initializer {{{ */
1050 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1054 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1055 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1056 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1060 : ElementList[pass] { $$ = $pass; }
1061 | LexOf { $$ = NULL; }
1064 /* 12.2.6 Object Initializer {{{ */
1066 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1069 PropertyDefinitionList_
1070 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1074 PropertyDefinitionList
1075 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1078 PropertyDefinitionListOpt
1079 : PropertyDefinitionList[properties] { $$ = $properties; }
1084 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1085 | CoverInitializedName[name] { CYNOT(@$); }
1086 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1087 | MethodDefinition[pass] { $$ = $pass; }
1091 : LiteralPropertyName[pass] { $$ = $pass; }
1092 | ComputedPropertyName[pass] { $$ = $pass; }
1096 : IdentifierName[pass] { $$ = $pass; }
1097 | StringLiteral[pass] { $$ = $pass; }
1098 | NumericLiteral[pass] { $$ = $pass; }
1101 ComputedPropertyName
1102 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1105 CoverInitializedName
1106 : IdentifierReference Initializer
1110 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1114 : Initializer[pass] { $$ = $pass; }
1118 /* 12.2.9 Template Literals {{{ */
1120 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1121 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1125 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1126 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1130 /* 12.3 Left-Hand-Side Expressions {{{ */
1132 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1133 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1134 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1135 | TemplateLiteral { CYNOT(@$); }
1139 : PrimaryExpression[pass] { $$ = $pass; }
1140 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1141 | SuperProperty[pass] { $$ = $pass; }
1142 | MetaProperty { CYNOT(@$); }
1143 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1147 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1148 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1156 : "new" "." "target"
1160 : MemberExpression[pass] { $$ = $pass; }
1161 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1165 : MemberExpression[pass] { $$ = $pass; }
1166 | CallExpression[pass] { $$ = $pass; }
1170 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1171 | SuperCall[pass] { $$ = $pass; }
1172 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1176 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1180 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1184 : "," ArgumentList[arguments] { $$ = $arguments; }
1189 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1190 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1194 : ArgumentList[pass] { $$ = $pass; }
1195 | LexOf { $$ = NULL; }
1199 : NewExpression[pass] { $$ = $pass; }
1200 | CallExpression[pass] { $$ = $pass; }
1203 LeftHandSideExpression
1204 : RubyBlockExpression[pass] { $$ = $pass; }
1205 | IndirectExpression[pass] { $$ = $pass; }
1208 /* 12.4 Postfix Expressions {{{ */
1210 : RubyBlockExpression[pass] { $$ = $pass; }
1211 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1212 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1215 /* 12.5 Unary Operators {{{ */
1217 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1218 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1219 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1220 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1221 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1222 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1223 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1224 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1225 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1229 : PostfixExpression[expression] { $$ = $expression; }
1230 | UnaryExpression_[pass] { $$ = $pass; }
1233 /* 12.6 Multiplicative Operators {{{ */
1234 MultiplicativeExpression
1235 : UnaryExpression[pass] { $$ = $pass; }
1236 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1237 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1238 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1241 /* 12.7 Additive Operators {{{ */
1243 : MultiplicativeExpression[pass] { $$ = $pass; }
1244 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1245 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1248 /* 12.8 Bitwise Shift Operators {{{ */
1250 : AdditiveExpression[pass] { $$ = $pass; }
1251 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1252 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1253 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1256 /* 12.9 Relational Operators {{{ */
1257 RelationalExpression
1258 : ShiftExpression[pass] { $$ = $pass; }
1259 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1260 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1261 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1262 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1263 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1264 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1267 /* 12.10 Equality Operators {{{ */
1269 : RelationalExpression[pass] { $$ = $pass; }
1270 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1271 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1272 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1273 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1276 /* 12.11 Binary Bitwise Operators {{{ */
1277 BitwiseANDExpression
1278 : EqualityExpression[pass] { $$ = $pass; }
1279 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1282 BitwiseXORExpression
1283 : BitwiseANDExpression[pass] { $$ = $pass; }
1284 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1288 : BitwiseXORExpression[pass] { $$ = $pass; }
1289 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1292 /* 12.12 Binary Logical Operators {{{ */
1293 LogicalANDExpression
1294 : BitwiseORExpression[pass] { $$ = $pass; }
1295 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1299 : LogicalANDExpression[pass] { $$ = $pass; }
1300 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1303 /* 12.13 Conditional Operator ( ? : ) {{{ */
1305 ConditionalExpressionClassic
1306 : LogicalORExpression[pass] { $$ = $pass; }
1307 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1311 ConditionalExpression
1312 : LogicalORExpression[pass] { $$ = $pass; }
1313 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1316 /* 12.14 Assignment Operators {{{ */
1317 LeftHandSideAssignment
1318 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1319 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1320 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1321 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1322 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1323 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1324 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1325 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1326 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1327 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1328 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1329 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1333 AssignmentExpressionClassic
1334 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1335 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1339 AssignmentExpression
1340 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1341 | LexOf YieldExpression[pass] { $$ = $pass; }
1342 | ArrowFunction[pass] { $$ = $pass; }
1343 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1346 AssignmentExpressionOpt
1347 : AssignmentExpression[pass] { $$ = $pass; }
1348 | LexOf { $$ = NULL; }
1351 /* 12.15 Comma Operator ( , ) {{{ */
1353 : AssignmentExpression[pass] { $$ = $pass; }
1354 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1358 : Expression[pass] { $$ = $pass; }
1359 | LexOf { $$ = NULL; }
1363 /* 13 Statements and Declarations {{{ */
1365 : BlockStatement[pass] { $$ = $pass; }
1366 | VariableStatement[pass] { $$ = $pass; }
1367 | EmptyStatement[pass] { $$ = $pass; }
1368 | IfStatement[pass] { $$ = $pass; }
1369 | BreakableStatement[pass] { $$ = $pass; }
1370 | ContinueStatement[pass] { $$ = $pass; }
1371 | BreakStatement[pass] { $$ = $pass; }
1372 | ReturnStatement[pass] { $$ = $pass; }
1373 | WithStatement[pass] { $$ = $pass; }
1374 | LabelledStatement[pass] { $$ = $pass; }
1375 | ThrowStatement[pass] { $$ = $pass; }
1376 | TryStatement[pass] { $$ = $pass; }
1377 | DebuggerStatement[pass] { $$ = $pass; }
1381 : LexOf Statement__[pass] { $$ = $pass; }
1382 | ExpressionStatement[pass] { $$ = $pass; }
1386 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1390 : HoistableDeclaration[pass] { $$ = $pass; }
1391 | ClassDeclaration[pass] { $$ = $pass; }
1395 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1396 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1399 HoistableDeclaration
1400 : FunctionDeclaration[pass] { $$ = $pass; }
1401 | GeneratorDeclaration[pass] { $$ = $pass; }
1405 : IterationStatement[pass] { $$ = $pass; }
1406 | SwitchStatement[pass] { $$ = $pass; }
1409 /* 13.2 Block {{{ */
1411 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1415 : "{" StatementListOpt[code] "}" { $$ = $code; }
1419 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1423 : StatementList[pass] { $$ = $pass; }
1424 | LexSetStatement LexLet LexOf { $$ = NULL; }
1428 : Statement[pass] { $$ = $pass; }
1429 | Declaration[pass] { $$ = $pass; }
1432 /* 13.3 Let and Const Declarations {{{ */
1434 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1438 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1442 : { CYMAP(_let__, _let_); }
1446 : { CYMAP(_of__, _of_); }
1450 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1454 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1455 | LexLet LexOf "const" { $$ = true; }
1459 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1464 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1468 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1469 | LexOf BindingPattern Initializer { CYNOT(@$); }
1472 /* 13.3.2 Variable Statement {{{ */
1474 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1478 : VariableStatement_[statement] Terminator { $$ = $statement; }
1481 VariableDeclarationList_
1482 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1486 VariableDeclarationList
1487 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1491 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1492 | LexOf BindingPattern Initializer { CYNOT(@$); }
1495 /* 13.3.3 Destructuring Binding Patterns {{{ */
1497 : ObjectBindingPattern
1498 | ArrayBindingPattern
1501 ObjectBindingPattern
1502 : "let {" BindingPropertyListOpt "}"
1506 : "let [" BindingElementListOpt "]"
1509 BindingPropertyList_
1510 : "," BindingPropertyListOpt
1515 : BindingProperty BindingPropertyList_
1518 BindingPropertyListOpt
1519 : BindingPropertyList
1524 : BindingElementOpt[element] "," BindingElementListOpt[next]
1525 | BindingRestElement[element]
1526 | BindingElement[element]
1529 BindingElementListOpt
1530 : BindingElementList[pass]
1536 | LexOf PropertyName ":" BindingElement
1540 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1541 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1545 : BindingElement[pass]
1550 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1554 : LexBind LexOf "..." BindingIdentifier
1557 /* 13.4 Empty Statement {{{ */
1559 : ";" { $$ = CYNew CYEmpty(); }
1562 /* 13.5 Expression Statement {{{ */
1563 ExpressionStatement_
1564 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1567 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1570 /* 13.6 The if Statement {{{ */
1572 : "else" Statement[false] { $$ = $false; }
1573 | %prec "if" { $$ = NULL; }
1577 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1580 /* 13.7 Iteration Statements {{{ */
1582 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1583 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1584 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1585 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1586 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1587 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1590 ForStatementInitializer
1591 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1592 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1593 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1594 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1597 ForInStatementInitializer
1598 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1599 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1600 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1601 | ForDeclaration[pass] { $$ = $pass; }
1605 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1609 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1610 | LexOf BindingPattern { CYNOT(@$); }
1613 /* 13.8 The continue Statement {{{ */
1615 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1616 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1619 /* 13.9 The break Statement {{{ */
1621 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1622 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1625 /* 13.10 The return Statement {{{ */
1627 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1628 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1631 /* 13.11 The with Statement {{{ */
1633 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1636 /* 13.12 The switch Statement {{{ */
1638 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1642 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1646 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1650 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1651 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1655 // XXX: the standard makes certain you can only have one of these
1657 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1660 /* 13.13 Labelled Statements {{{ */
1662 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1666 : Statement[pass] { $$ = $pass; }
1667 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1670 /* 13.14 The throw Statement {{{ */
1672 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1673 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1676 /* 13.15 The try Statement {{{ */
1678 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1679 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1680 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1684 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1688 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1692 : BindingIdentifier[pass] { $$ = $pass; }
1693 | LexOf BindingPattern { CYNOT(@$); }
1696 /* 13.16 The debugger Statement {{{ */
1698 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1702 /* 14.1 Function Definitions {{{ */
1704 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1708 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1711 StrictFormalParameters
1712 : FormalParameters[pass] { $$ = $pass; }
1716 : LexBind LexOf { $$ = NULL; }
1717 | FormalParameterList
1720 FormalParameterList_
1721 : "," FormalParameterList[parameters] { $$ = $parameters; }
1726 : FunctionRestParameter { CYNOT(@$); }
1727 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1730 FunctionRestParameter
1731 : BindingRestElement
1735 : BindingElement[pass] { $$ = $pass; }
1739 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1742 FunctionStatementList
1743 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1746 /* 14.2 Arrow Function Definitions {{{ */
1748 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1752 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1753 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1757 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1758 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1761 /* 14.3 Method Definitions {{{ */
1763 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1764 | GeneratorMethod[pass] { $$ = $pass; }
1765 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1766 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1769 PropertySetParameterList
1770 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1773 /* 14.4 Generator Function Definitions {{{ */
1775 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1778 GeneratorDeclaration
1779 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1783 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1787 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1791 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1792 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1793 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1794 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1797 /* 14.5 Class Definitions {{{ */
1799 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1803 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1807 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1811 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1815 : ClassHeritage[pass] { $$ = $pass; }
1816 | { $$ = CYNew CYClassTail(NULL); }
1829 : ClassElementListOpt ClassElement
1838 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1839 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1844 /* 15.1 Scripts {{{ */
1846 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1850 : StatementList[pass] { $$ = $pass; }
1854 : ScriptBody[pass] { $$ = $pass; }
1855 | LexSetStatement LexLet LexOf { $$ = NULL; }
1858 /* 15.2 Modules {{{ */
1860 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1864 : ModuleItemList[pass] { $$ = $pass; }
1868 : ModuleBody[pass] { $$ = $pass; }
1869 | LexSetStatement LexLet LexOf { $$ = NULL; }
1873 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1877 : ModuleItemList[pass] { $$ = $pass; }
1878 | LexSetStatement LexLet LexOf { $$ = NULL; }
1882 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1883 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1884 | StatementListItem[pass] { $$ = $pass; }
1887 /* 15.2.2 Imports {{{ */
1889 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1890 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1894 : ImportedDefaultBinding[default] { $$ = $default; }
1895 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1896 | LexOf NamedImports[pass] { $$ = $pass; }
1897 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1898 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1901 ImportedDefaultBinding
1902 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1906 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1910 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1914 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1918 : "," ImportsListOpt[pass] { $$ = $pass; }
1923 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1927 : ImportsList[pass] { $$ = $pass; }
1928 | LexOf { $$ = NULL; }
1932 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1933 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1937 : StringLiteral[pass] { $$ = $pass; }
1941 : BindingIdentifier[pass] { $$ = $pass; }
1944 /* 15.2.3 Exports {{{ */
1946 : "*" FromClause Terminator
1947 | ExportClause FromClause Terminator
1948 | ExportClause Terminator
1950 | "default" LexSetStatement LexOf HoistableDeclaration
1951 | "default" LexSetStatement LexOf ClassDeclaration
1952 | "default" LexSetStatement AssignmentExpression Terminator
1956 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1957 | "export" Declaration
1961 : ";{" ExportsListOpt "}"
1965 : "," ExportsListOpt
1970 : ExportSpecifier ExportsList_
1980 | IdentifierName "as" IdentifierName
1985 /* Cycript (C): Type Encoding {{{ */
1987 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1988 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1992 : { $$ = CYNew CYTypedIdentifier(@$); }
1996 : TypeSignifier[pass] { $$ = $pass; }
1997 | TypeSignifierNone[pass] { $$ = $pass; }
2014 ParameterModifierOpt
2020 : TypedParameterListOpt[parameters] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($parameters); }
2024 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2025 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2026 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2027 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2031 : SuffixedType[pass] { $$ = $pass; }
2032 | TypeSignifierOpt[pass] { $$ = $pass; }
2036 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2040 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2041 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2044 TypeQualifierLeftOpt
2045 : TypeQualifierLeft[pass] { $$ = $pass; }
2050 : SuffixedType[pass] { $$ = $pass; }
2051 | PrefixedType[pass] { $$ = $pass; }
2052 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2053 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2054 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2057 TypeQualifierRightOpt
2058 : TypeQualifierRight[pass] { $$ = $pass; }
2059 | TypeSignifierOpt[pass] { $$ = $pass; }
2063 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2064 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2065 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2066 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2067 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2071 : IntegerType[pass] { $$ = $pass; }
2072 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2076 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2081 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2082 | IntegerType[pass] { $$ = $pass; }
2083 | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
2084 | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
2085 | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
2086 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2089 TypedIdentifierMaybe
2090 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2091 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2092 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2096 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2100 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2103 TypedIdentifierField
2104 : TypedIdentifierYes[pass] { $$ = $pass; }
2105 | 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; }
2108 TypedIdentifierEncoding
2109 : TypedIdentifierNo[pass] { $$ = $pass; }
2110 | 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; }
2113 TypedIdentifierDefinition
2114 : TypedIdentifierYes[pass] { $$ = $pass; }
2115 | 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; }
2119 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2125 /* Cycript (Objective-C): @class Declaration {{{ */
2127 /* XXX: why the hell did I choose MemberExpression? */
2128 : ":" MemberExpression[extends] { $$ = $extends; }
2132 ImplementationFieldListOpt
2133 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2138 : "+" { $$ = false; }
2139 | "-" { $$ = true; }
2143 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2144 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2148 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2151 MessageParameterList
2152 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2155 MessageParameterListOpt
2156 : MessageParameterList[pass] { $$ = $pass; }
2161 : MessageParameterList[pass] { $$ = $pass; }
2162 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2165 ClassMessageDeclaration
2166 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2169 ClassMessageDeclarationListOpt
2170 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2174 // XXX: this should be AssignmentExpressionNoRight
2176 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2180 : "," ClassProtocols[protocols] { $$ = $protocols; }
2184 ClassProtocolListOpt
2185 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2189 ImplementationStatement
2190 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2198 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2202 : ImplementationStatement[pass] { $$ = $pass; }
2203 | CategoryStatement[pass] { $$ = $pass; }
2206 /* Cycript (Objective-C): Send Message {{{ */
2208 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2213 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2214 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2218 : SelectorCall[pass] { $$ = $pass; }
2219 | VariadicCall[pass] { $$ = $pass; }
2223 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2227 : SelectorCall[pass] { $$ = $pass; }
2228 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2232 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2233 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2237 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2241 : SelectorExpression_[pass] { $$ = $pass; }
2242 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2245 SelectorExpressionOpt
2246 : SelectorExpression_[pass] { $$ = $pass; }
2251 : MessageExpression[pass] { $$ = $pass; }
2252 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2257 /* Cycript: @import Directive {{{ */
2259 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2260 | Word[part] { $$ = CYNew CYModule($part); }
2264 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2269 /* Cycript (Objective-C): Boxed Expressions {{{ */
2271 : NullLiteral[pass] { $$ = $pass; }
2272 | BooleanLiteral[pass] { $$ = $pass; }
2273 | NumericLiteral[pass] { $$ = $pass; }
2274 | StringLiteral[pass] { $$ = $pass; }
2275 | ArrayLiteral[pass] { $$ = $pass; }
2276 | ObjectLiteral[pass] { $$ = $pass; }
2277 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2278 | "YES" { $$ = CYNew CYTrue(); }
2279 | "NO" { $$ = CYNew CYFalse(); }
2283 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2284 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2285 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2286 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2287 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2288 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2291 /* Cycript (Objective-C): Block Expressions {{{ */
2293 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2296 /* Cycript (Objective-C): Instance Literals {{{ */
2298 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2304 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2306 : IndirectExpression[pass] { $$ = $pass; }
2310 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2314 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2318 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2319 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2320 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2323 /* Cycript (C): Lambda Expressions {{{ */
2325 : "," TypedParameterList[parameters] { $$ = $parameters; }
2330 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2333 TypedParameterListOpt
2334 : TypedParameterList[pass] { $$ = $pass; }
2335 | "void" { $$ = NULL; }
2340 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2343 /* Cycript (C): Structure Definitions {{{ */
2345 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2349 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2353 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2356 /* Cycript (C): Type Definitions {{{ */
2358 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2362 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2366 : TypeDefinition[pass] { $$ = $pass; }
2370 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2373 /* Cycript (C): extern "C" {{{ */
2375 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2379 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2380 | TypeDefinition[pass] { $$ = $pass; }
2383 ExternCStatementListOpt
2384 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2389 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2390 | ExternCStatement[pass] { $$ = $pass; }
2394 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2400 /* Lexer State {{{ */
2402 : { driver.PushCondition(CYDriver::RegExpCondition); }
2406 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2410 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2414 : { driver.PopCondition(); }
2418 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2422 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2425 /* Virtual Tokens {{{ */
2432 /* 8.1 Context Keywords {{{ */
2434 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2435 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2438 /* 8.3 XML Initializer Input Elements {{{ */
2440 : XMLComment { $$ = $1; }
2441 | XMLCDATA { $$ = $1; }
2442 | XMLPI { $$ = $1; }
2446 /* 11.1 Primary Expressions {{{ */
2448 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2449 | XMLInitilizer { $$ = $1; }
2450 | XMLListInitilizer { $$ = $1; }
2454 : AttributeIdentifier { $$ = $1; }
2455 | QualifiedIdentifier { $$ = $1; }
2456 | WildcardIdentifier { $$ = $1; }
2459 /* 11.1.1 Attribute Identifiers {{{ */
2461 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2465 : PropertySelector { $$ = $1; }
2466 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2470 : Identifier { $$ = CYNew CYSelector($1); }
2471 | WildcardIdentifier { $$ = $1; }
2474 /* 11.1.2 Qualified Identifiers {{{ */
2475 QualifiedIdentifier_
2476 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2477 | QualifiedIdentifier { $$ = $1; }
2481 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2484 /* 11.1.3 Wildcard Identifiers {{{ */
2486 : "*" { $$ = CYNew CYWildcard(); }
2489 /* 11.1.4 XML Initializer {{{ */
2491 : XMLMarkup { $$ = $1; }
2492 | XMLElement { $$ = $1; }
2496 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2497 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2501 : LexPushXMLTag XMLTagName XMLAttributes
2505 : "{" LexPushRegExp Expression LexPop "}"
2514 : XMLAttributes_ XMLAttribute
2519 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2520 | XMLAttributes_ XMLWhitespaceOpt
2529 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2533 : XMLExpression XMLElementContentOpt
2534 | XMLMarkup XMLElementContentOpt
2535 | XMLText XMLElementContentOpt
2536 | XMLElement XMLElementContentOpt
2539 XMLElementContentOpt
2544 /* 11.1.5 XMLList Initializer {{{ */
2546 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2550 /* 11.2 Left-Hand-Side Expressions {{{ */
2552 : Identifier { $$ = $1; }
2553 | PropertyIdentifier { $$ = $1; }
2557 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2558 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2559 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2562 /* 12.1 The default xml namespace Statement {{{ */
2563 /* XXX: DefaultXMLNamespaceStatement
2564 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2568 : DefaultXMLNamespaceStatement { $$ = $1; }
2573 /* JavaScript FTL: Array Comprehensions {{{ */
2575 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2579 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2582 /* JavaScript FTL: for each {{{ */
2584 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2588 /* JavaScript FTW: Array Comprehensions {{{ */
2590 : ArrayComprehension
2594 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2598 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2603 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2604 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2608 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2609 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2613 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2616 /* JavaScript FTW: Coalesce Operator {{{ */
2617 ConditionalExpression
2618 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2621 /* JavaScript FTW: Named Arguments {{{ */
2623 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2626 /* JavaScript FTW: Ruby Blocks {{{ */
2627 RubyProcParameterList_
2628 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2632 RubyProcParameterList
2633 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2634 | LexOf { $$ = NULL; }
2638 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2639 | "||" { $$ = NULL; }
2642 RubyProcParametersOpt
2643 : RubyProcParameters[pass] { $$ = $pass; }
2648 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2652 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2655 RubyBlockExpression_
2656 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2657 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2661 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2662 | RubyBlockExpression_[pass] { $$ = $pass; }
2668 bool CYDriver::Parse(CYMark mark) {
2670 CYLocal<CYPool> local(&pool_);
2671 cy::parser parser(*this);
2673 parser.set_debug_level(debug_);
2675 return parser.parse() != 0;
2678 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2682 CYDriver::Error error;
2683 error.warning_ = true;
2684 error.location_ = location;
2685 error.message_ = message;
2686 errors_.push_back(error);
2689 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2690 CYDriver::Error error;
2691 error.warning_ = false;
2692 error.location_ = location;
2693 error.message_ = message;
2694 driver.errors_.push_back(error);