1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define YYSTACKEXPANDABLE 1
31 #define CYNew new(driver.pool_)
34 #include "ObjectiveC/Syntax.hpp"
38 #include "E4X/Syntax.hpp"
41 #include "Highlight.hpp"
44 %union { bool bool_; }
46 %union { CYMember *access_; }
47 %union { CYArgument *argument_; }
48 %union { CYAssignment *assignment_; }
49 %union { CYBinding *binding_; }
50 %union { CYBindings *bindings_; }
51 %union { CYBoolean *boolean_; }
52 %union { CYBraced *braced_; }
53 %union { CYClause *clause_; }
54 %union { cy::Syntax::Catch *catch_; }
55 %union { CYClassTail *classTail_; }
56 %union { CYComprehension *comprehension_; }
57 %union { CYElement *element_; }
58 %union { CYExpression *expression_; }
59 %union { CYFalse *false_; }
60 %union { CYVariable *variable_; }
61 %union { CYFinally *finally_; }
62 %union { CYForInitializer *for_; }
63 %union { CYForInInitializer *forin_; }
64 %union { CYFunctionParameter *functionParameter_; }
65 %union { CYIdentifier *identifier_; }
66 %union { CYImportSpecifier *import_; }
67 %union { CYInfix *infix_; }
68 %union { CYLiteral *literal_; }
69 %union { CYMethod *method_; }
70 %union { CYModule *module_; }
71 %union { CYNull *null_; }
72 %union { CYNumber *number_; }
73 %union { CYParenthetical *parenthetical_; }
74 %union { CYProperty *property_; }
75 %union { CYPropertyName *propertyName_; }
76 %union { CYSpan *span_; }
77 %union { CYStatement *statement_; }
78 %union { CYString *string_; }
79 %union { CYTarget *target_; }
80 %union { CYThis *this_; }
81 %union { CYTrue *true_; }
82 %union { CYWord *word_; }
85 %union { CYTypeIntegral *integral_; }
86 %union { CYTypeStructField *structField_; }
87 %union { CYTypeModifier *modifier_; }
88 %union { CYTypeSpecifier *specifier_; }
89 %union { CYTypedFormal *typedFormal_; }
90 %union { CYTypedIdentifier *typedIdentifier_; }
91 %union { CYTypedParameter *typedParameter_; }
95 %union { CYObjCKeyValue *keyValue_; }
96 %union { CYImplementationField *implementationField_; }
97 %union { CYMessage *message_; }
98 %union { CYMessageParameter *messageParameter_; }
99 %union { CYProtocol *protocol_; }
100 %union { CYSelectorPart *selector_; }
104 %union { CYAttribute *attribute_; }
105 %union { CYPropertyIdentifier *propertyIdentifier_; }
106 %union { CYSelector *selector_; }
112 cy::parser::semantic_type semantic_;
113 hi::Value highlight_;
116 int cylex(YYSTYPE *, CYLocation *, void *);
124 typedef cy::parser::token tk;
126 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
127 driver.newline_ = false;
130 int token(cylex(&data, location, driver.scanner_));
131 *semantic = data.semantic_;
135 case tk::OpenBracket:
137 driver.in_.push(false);
141 if (driver.in_.top())
146 case tk::CloseBracket:
153 if (driver.yield_.top())
154 token = tk::_yield__;
158 driver.newline_ = true;
166 #define yylex_(semantic, location, driver) ({ \
168 if (driver.hold_ == cy::parser::empty_symbol) \
169 type = yytranslate_(cylex_(semantic, location, driver)); \
171 type = driver.hold_; \
172 driver.hold_ = cy::parser::empty_symbol; \
176 #define CYLEX() do if (yyla.empty()) { \
177 YYCDEBUG << "Mapping a token: "; \
178 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
179 YY_SYMBOL_PRINT("Next token is", yyla); \
182 #define CYMAP(to, from) do { \
184 if (yyla.type == yytranslate_(token::from)) \
185 yyla.type = yytranslate_(token::to); \
188 #define CYHLD(location, token) do { \
189 if (driver.hold_ != empty_symbol) \
190 CYERR(location, "unexpected hold"); \
191 driver.hold_ = yyla.type; \
192 yyla.type = yytranslate_(token); \
195 #define CYERR(location, message) do { \
196 error(location, message); \
200 #define CYEOK() do { \
202 driver.errors_.pop_back(); \
205 #define CYNOT(location) \
206 CYERR(location, "unimplemented feature")
208 #define CYMPT(location) do { \
209 if (!yyla.empty() && yyla.type_get() != yyeof_) \
210 CYERR(location, "unexpected lookahead"); \
220 @$.begin.filename = @$.end.filename = &driver.filename_;
222 switch (driver.mark_) {
224 driver.hold_ = yytranslate_(token::MarkScript);
227 driver.hold_ = yytranslate_(token::MarkModule);
235 %define api.location.type { CYLocation }
242 %param { CYDriver &driver }
244 /* Token Declarations {{{ */
250 %token XMLAttributeValue
252 %token XMLTagCharacters
258 %token LeftRight "<>"
259 %token LeftSlashRight "</>"
261 %token SlashRight "/>"
262 %token LeftSlash "</"
264 %token PeriodPeriod ".."
267 @begin E4X ObjectiveC
273 %token AmpersandAmpersand "&&"
274 %token AmpersandEqual "&="
276 %token CarrotEqual "^="
278 %token EqualEqual "=="
279 %token EqualEqualEqual "==="
280 %token EqualRight "=>"
281 %token Exclamation "!"
282 %token ExclamationEqual "!="
283 %token ExclamationEqualEqual "!=="
285 %token HyphenEqual "-="
286 %token HyphenHyphen "--"
287 %token HyphenRight "->"
289 %token LeftEqual "<="
291 %token LeftLeftEqual "<<="
293 %token PercentEqual "%="
295 %token PeriodPeriodPeriod "..."
297 %token PipeEqual "|="
300 %token PlusEqual "+="
303 %token RightEqual ">="
304 %token RightRight ">>"
305 %token RightRightEqual ">>="
306 %token RightRightRight ">>>"
307 %token RightRightRightEqual ">>>="
309 %token SlashEqual "/="
311 %token StarEqual "*="
315 %token ColonColon "::"
325 %token CloseParen ")"
328 %token OpenBrace_ ";{"
329 %token OpenBrace_let "let {"
330 %token CloseBrace "}"
332 %token OpenBracket "["
333 %token OpenBracket_let "let ["
334 %token CloseBracket "]"
336 %token At_error_ "@error"
339 %token At_class_ "@class"
343 %token _typedef_ "typedef"
344 %token _unsigned_ "unsigned"
345 %token _signed_ "signed"
346 %token _struct_ "struct"
347 %token _extern_ "extern"
351 %token At_encode_ "@encode"
355 %token At_implementation_ "@implementation"
356 %token At_import_ "@import"
357 %token At_end_ "@end"
358 %token At_selector_ "@selector"
359 %token At_null_ "@null"
360 %token At_YES_ "@YES"
362 %token At_true_ "@true"
363 %token At_false_ "@false"
368 %token _false_ "false"
373 %token _break_ "break"
375 %token _catch_ "catch"
376 %token _class_ "class"
377 %token _class__ ";class"
378 %token _const_ "const"
379 %token _continue_ "continue"
380 %token _debugger_ "debugger"
381 %token _default_ "default"
382 %token _delete_ "delete"
386 %token _export_ "export"
387 %token _extends_ "extends"
388 %token _finally_ "finally"
390 %token _function_ "function"
391 %token _function__ ";function"
393 %token _import_ "import"
396 %token _Infinity_ "Infinity"
397 %token _instanceof_ "instanceof"
399 %token _return_ "return"
400 %token _super_ "super"
401 %token _switch_ "switch"
402 %token _target_ "target"
404 %token _throw_ "throw"
406 %token _typeof_ "typeof"
409 %token _while_ "while"
412 %token _abstract_ "abstract"
413 %token _await_ "await"
414 %token _boolean_ "boolean"
417 %token _constructor_ "constructor"
418 %token _double_ "double"
420 %token _final_ "final"
421 %token _float_ "float"
425 %token _implements_ "implements"
427 %token _interface_ "interface"
431 %token _native_ "native"
432 %token _package_ "package"
433 %token _private_ "private"
434 %token _protected_ "protected"
435 %token ___proto___ "__proto__"
436 %token _prototype_ "prototype"
437 %token _public_ "public"
438 %token ___restrict_ "__restrict"
439 %token _restrict_ "restrict"
441 %token _short_ "short"
442 %token _static_ "static"
443 %token _synchronized_ "synchronized"
444 %token _throws_ "throws"
445 %token _transient_ "transient"
446 %token _typeid_ "typeid"
447 %token _volatile_ "volatile"
448 %token _yield_ "yield"
449 %token _yield__ "!yield"
451 %token _undefined_ "undefined"
467 %token _namespace_ "namespace"
472 %token YieldStar "yield *"
474 %token <identifier_> Identifier_
475 %token <number_> NumericLiteral
476 %token <string_> StringLiteral
477 %token <literal_> RegularExpressionLiteral_
479 %token <string_> NoSubstitutionTemplate
480 %token <string_> TemplateHead
481 %token <string_> TemplateMiddle
482 %token <string_> TemplateTail
484 %type <target_> AccessExpression
485 %type <expression_> AdditiveExpression
486 %type <argument_> ArgumentList_
487 %type <argument_> ArgumentList
488 %type <argument_> ArgumentListOpt
489 %type <argument_> Arguments
490 %type <target_> ArrayComprehension
491 %type <element_> ArrayElement
492 %type <literal_> ArrayLiteral
493 %type <expression_> ArrowFunction
494 %type <functionParameter_> ArrowParameters
495 %type <expression_> AssignmentExpression
496 %type <identifier_> BindingIdentifier
497 %type <identifier_> BindingIdentifierOpt
498 %type <bindings_> BindingList_
499 %type <bindings_> BindingList
500 %type <expression_> BitwiseANDExpression
501 %type <statement_> Block
502 %type <statement_> BlockStatement
503 %type <boolean_> BooleanLiteral
504 %type <binding_> BindingElement
505 %type <expression_> BitwiseORExpression
506 %type <expression_> BitwiseXORExpression
507 %type <target_> BracedExpression_
508 %type <target_> BracedExpression
509 %type <statement_> BreakStatement
510 %type <statement_> BreakableStatement
511 %type <expression_> CallExpression_
512 %type <target_> CallExpression
513 %type <clause_> CaseBlock
514 %type <clause_> CaseClause
515 %type <clause_> CaseClausesOpt
517 %type <identifier_> CatchParameter
518 %type <statement_> ClassDeclaration
519 %type <target_> ClassExpression
520 %type <classTail_> ClassHeritage
521 %type <classTail_> ClassHeritageOpt
522 %type <classTail_> ClassTail
523 %type <target_> Comprehension
524 %type <comprehension_> ComprehensionFor
525 %type <comprehension_> ComprehensionIf
526 %type <comprehension_> ComprehensionTail
527 %type <propertyName_> ComputedPropertyName
528 %type <expression_> ConditionalExpression
529 %type <statement_> ContinueStatement
530 %type <statement_> ConciseBody
531 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
532 %type <statement_> DebuggerStatement
533 %type <statement_> Declaration_
534 %type <statement_> Declaration
535 %type <clause_> DefaultClause
536 %type <element_> ElementList_
537 %type <element_> ElementList
538 %type <element_> ElementListOpt
539 %type <statement_> ElseStatementOpt
540 %type <for_> EmptyStatement
541 %type <expression_> EqualityExpression
542 %type <expression_> Expression
543 %type <expression_> ExpressionOpt
544 %type <for_> ExpressionStatement_
545 %type <statement_> ExpressionStatement
546 %type <statement_> ExternC
547 %type <statement_> ExternCStatement
548 %type <statement_> ExternCStatementListOpt
549 %type <finally_> Finally
550 %type <binding_> ForBinding
551 %type <forin_> ForDeclaration
552 %type <forin_> ForInStatementInitializer
553 %type <for_> ForStatementInitializer
554 %type <binding_> FormalParameter
555 %type <functionParameter_> FormalParameterList_
556 %type <functionParameter_> FormalParameterList
557 %type <functionParameter_> FormalParameters
558 %type <string_> FromClause
559 %type <statement_> FunctionBody
560 %type <statement_> FunctionDeclaration
561 %type <target_> FunctionExpression
562 %type <statement_> FunctionStatementList
563 %type <statement_> GeneratorBody
564 %type <statement_> GeneratorDeclaration
565 %type <target_> GeneratorExpression
566 %type <method_> GeneratorMethod
567 %type <statement_> HoistableDeclaration
568 %type <identifier_> Identifier
569 %type <identifier_> IdentifierNoOf
570 %type <identifier_> IdentifierType
571 %type <identifier_> IdentifierTypeNoOf
572 %type <identifier_> IdentifierTypeOpt
573 %type <word_> IdentifierName
574 %type <variable_> IdentifierReference
575 %type <statement_> IfStatement
576 %type <import_> ImportClause
577 %type <statement_> ImportDeclaration
578 %type <import_> ImportSpecifier
579 %type <identifier_> ImportedBinding
580 %type <import_> ImportedDefaultBinding
581 %type <import_> ImportsList_
582 %type <import_> ImportsList
583 %type <import_> ImportsListOpt
584 %type <target_> IndirectExpression
585 %type <expression_> Initializer
586 %type <expression_> InitializerOpt
587 %type <statement_> IterationStatement
588 %type <identifier_> LabelIdentifier
589 %type <statement_> LabelledItem
590 %type <statement_> LabelledStatement
591 %type <assignment_> LeftHandSideAssignment
592 %type <target_> LeftHandSideExpression
593 %type <bool_> LetOrConst
594 %type <binding_> LexicalBinding
595 %type <for_> LexicalDeclaration_
596 %type <statement_> LexicalDeclaration
597 %type <literal_> Literal
598 %type <propertyName_> LiteralPropertyName
599 %type <expression_> LogicalANDExpression
600 %type <expression_> LogicalORExpression
601 %type <access_> MemberAccess
602 %type <target_> MemberExpression
603 %type <method_> MethodDefinition
604 %type <statement_> ModuleBody
605 %type <statement_> ModuleBodyOpt
606 %type <statement_> ModuleItem
607 %type <statement_> ModuleItemList
608 %type <statement_> ModuleItemListOpt
609 %type <module_> ModulePath
610 %type <string_> ModuleSpecifier
611 %type <expression_> MultiplicativeExpression
612 %type <import_> NameSpaceImport
613 %type <import_> NamedImports
614 %type <target_> NewExpression
615 %type <null_> NullLiteral
616 %type <literal_> ObjectLiteral
617 %type <expression_> PostfixExpression
618 %type <target_> PrimaryExpression
619 %type <propertyName_> PropertyName
620 %type <property_> PropertyDefinition
621 %type <property_> PropertyDefinitionList_
622 %type <property_> PropertyDefinitionList
623 %type <property_> PropertyDefinitionListOpt
624 %type <functionParameter_> PropertySetParameterList
625 %type <literal_> RegularExpressionLiteral
626 %type <bool_> RegularExpressionSlash
627 %type <expression_> RelationalExpression
628 %type <statement_> ReturnStatement
629 %type <braced_> BracedParameter
630 %type <functionParameter_> RubyProcParameterList_
631 %type <functionParameter_> RubyProcParameterList
632 %type <functionParameter_> RubyProcParameters
633 %type <functionParameter_> RubyProcParametersOpt
634 %type <statement_> Script
635 %type <statement_> ScriptBody
636 %type <statement_> ScriptBodyOpt
637 %type <expression_> ShiftExpression
638 %type <binding_> SingleNameBinding
639 %type <statement_> Statement__
640 %type <statement_> Statement_
641 %type <statement_> Statement
642 %type <statement_> StatementList
643 %type <statement_> StatementListOpt
644 %type <statement_> StatementListItem
645 %type <functionParameter_> StrictFormalParameters
646 %type <target_> SuperCall
647 %type <target_> SuperProperty
648 %type <statement_> SwitchStatement
649 %type <target_> TemplateLiteral
650 %type <span_> TemplateSpans
651 %type <statement_> ThrowStatement
652 %type <statement_> TryStatement
653 %type <statement_> TypeDefinition
654 %type <expression_> UnaryExpression_
655 %type <expression_> UnaryExpression
656 %type <binding_> VariableDeclaration
657 %type <bindings_> VariableDeclarationList_
658 %type <bindings_> VariableDeclarationList
659 %type <for_> VariableStatement_
660 %type <statement_> VariableStatement
661 %type <statement_> WithStatement
663 %type <word_> WordNoUnary
665 %type <word_> WordOpt
667 %type <expression_> YieldExpression
670 %type <integral_> IntegerType
671 %type <integral_> IntegerTypeOpt
672 %type <typedIdentifier_> PrefixedType
673 %type <specifier_> PrimitiveType
674 %type <structField_> StructFieldListOpt
675 %type <typedIdentifier_> SuffixedType
676 %type <typedIdentifier_> SuffixedTypeOpt
677 %type <typedIdentifier_> TypeSignifier
678 %type <typedIdentifier_> TypeSignifierNone
679 %type <typedIdentifier_> TypeSignifierOpt
680 %type <modifier_> ParameterTail
681 %type <modifier_> TypeQualifierLeft
682 %type <modifier_> TypeQualifierLeftOpt
683 %type <typedIdentifier_> TypeQualifierRight
684 %type <typedIdentifier_> TypeQualifierRightOpt
685 %type <typedIdentifier_> TypedIdentifierDefinition
686 %type <typedIdentifier_> TypedIdentifierEncoding
687 %type <typedIdentifier_> TypedIdentifierField
688 %type <typedIdentifier_> TypedIdentifierMaybe
689 %type <typedIdentifier_> TypedIdentifierNo
690 %type <typedIdentifier_> TypedIdentifierYes
691 %type <typedFormal_> TypedParameterList_
692 %type <typedFormal_> TypedParameterList
693 %type <typedFormal_> TypedParameterListOpt
694 %type <typedParameter_> TypedParameters
698 %type <expression_> AssignmentExpressionClassic
699 %type <expression_> BoxableExpression
700 %type <statement_> CategoryStatement
701 %type <expression_> ClassSuperOpt
702 %type <expression_> ConditionalExpressionClassic
703 %type <message_> ClassMessageDeclaration
704 %type <message_> ClassMessageDeclarationListOpt
705 %type <protocol_> ClassProtocolListOpt
706 %type <protocol_> ClassProtocols
707 %type <protocol_> ClassProtocolsOpt
708 %type <implementationField_> ImplementationFieldListOpt
709 %type <statement_> ImplementationStatement
710 %type <keyValue_> KeyValuePairList_
711 %type <keyValue_> KeyValuePairList
712 %type <keyValue_> KeyValuePairListOpt
713 %type <target_> MessageExpression
714 %type <messageParameter_> MessageParameter
715 %type <messageParameter_> MessageParameters
716 %type <messageParameter_> MessageParameterList
717 %type <messageParameter_> MessageParameterListOpt
718 %type <bool_> MessageScope
719 %type <argument_> SelectorCall_
720 %type <argument_> SelectorCall
721 %type <selector_> SelectorExpression_
722 %type <selector_> SelectorExpression
723 %type <selector_> SelectorExpressionOpt
724 %type <argument_> SelectorList
725 %type <word_> SelectorWordOpt
726 %type <typedIdentifier_> TypeOpt
727 %type <argument_> VariadicCall
731 %type <propertyIdentifier_> PropertyIdentifier_
732 %type <selector_> PropertySelector_
733 %type <selector_> PropertySelector
734 %type <identifier_> QualifiedIdentifier_
735 %type <identifier_> QualifiedIdentifier
736 %type <identifier_> WildcardIdentifier
737 %type <identifier_> XMLComment
738 %type <identifier_> XMLCDATA
739 %type <identifier_> XMLElement
740 %type <identifier_> XMLElementContent
741 %type <identifier_> XMLMarkup
742 %type <identifier_> XMLPI
744 %type <attribute_> AttributeIdentifier
745 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
746 %type <expression_> PropertyIdentifier
747 %type <expression_> XMLListInitilizer
748 %type <expression_> XMLInitilizer
751 /* Token Priorities {{{ */
770 /* Lexer State {{{ */
771 LexPushInOn: { driver.in_.push(true); };
772 LexPushInOff: { driver.in_.push(false); };
773 LexPopIn: { driver.in_.pop(); };
775 LexPushReturnOn: { driver.return_.push(true); };
776 LexPopReturn: { driver.return_.pop(); };
777 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
779 LexPushSuperOn: { driver.super_.push(true); };
780 LexPushSuperOff: { driver.super_.push(false); };
781 LexPopSuper: { driver.super_.pop(); };
782 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
784 LexPushYieldOn: { driver.yield_.push(true); };
785 LexPushYieldOff: { driver.yield_.push(false); };
786 LexPopYield: { driver.yield_.pop(); };
789 : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } }
793 : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); }
797 : { CYMAP(YieldStar, Star); }
801 : { CYMAP(OpenBrace_, OpenBrace); }
805 : { CYMAP(_class__, _class_); }
809 : { CYMAP(_function__, _function_); }
813 : LexNoBrace LexNoClass LexNoFunction
816 /* Virtual Tokens {{{ */
822 /* 11.6 Names and Keywords {{{ */
824 : Word[pass] { $$ = $pass; }
825 | "for" { $$ = CYNew CYWord("for"); }
826 | "in" { $$ = CYNew CYWord("in"); }
827 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
831 : IdentifierNoOf[pass] { $$ = $pass; }
832 | "break" { $$ = CYNew CYWord("break"); }
833 | "case" { $$ = CYNew CYWord("case"); }
834 | "catch" { $$ = CYNew CYWord("catch"); }
835 | "class" LexOf { $$ = CYNew CYWord("class"); }
836 | ";class" { $$ = CYNew CYWord("class"); }
837 | "const" { $$ = CYNew CYWord("const"); }
838 | "continue" { $$ = CYNew CYWord("continue"); }
839 | "debugger" { $$ = CYNew CYWord("debugger"); }
840 | "default" { $$ = CYNew CYWord("default"); }
841 | "do" { $$ = CYNew CYWord("do"); }
842 | "else" { $$ = CYNew CYWord("else"); }
843 | "enum" { $$ = CYNew CYWord("enum"); }
844 | "export" { $$ = CYNew CYWord("export"); }
845 | "extends" { $$ = CYNew CYWord("extends"); }
846 | "false" { $$ = CYNew CYWord("false"); }
847 | "finally" { $$ = CYNew CYWord("finally"); }
848 | "function" LexOf { $$ = CYNew CYWord("function"); }
849 | "if" { $$ = CYNew CYWord("if"); }
850 | "import" { $$ = CYNew CYWord("import"); }
851 | "!in" { $$ = CYNew CYWord("in"); }
852 | "!of" { $$ = CYNew CYWord("of"); }
853 | "null" { $$ = CYNew CYWord("null"); }
854 | "return" { $$ = CYNew CYWord("return"); }
855 | "super" { $$ = CYNew CYWord("super"); }
856 | "switch" { $$ = CYNew CYWord("switch"); }
857 | "this" { $$ = CYNew CYWord("this"); }
858 | "throw" { $$ = CYNew CYWord("throw"); }
859 | "true" { $$ = CYNew CYWord("true"); }
860 | "try" { $$ = CYNew CYWord("try"); }
861 | "var" { $$ = CYNew CYWord("var"); }
862 | "while" { $$ = CYNew CYWord("while"); }
863 | "with" { $$ = CYNew CYWord("with"); }
867 : WordNoUnary[pass] { $$ = $pass; }
868 | "delete" { $$ = CYNew CYWord("delete"); }
869 | "typeof" { $$ = CYNew CYWord("typeof"); }
870 | "void" { $$ = CYNew CYWord("void"); }
871 | "yield" { $$ = CYNew CYIdentifier("yield"); }
876 : Word[pass] { $$ = $pass; }
881 /* 11.8.1 Null Literals {{{ */
883 : "null" { $$ = CYNew CYNull(); }
886 /* 11.8.2 Boolean Literals {{{ */
888 : "true" { $$ = CYNew CYTrue(); }
889 | "false" { $$ = CYNew CYFalse(); }
892 /* 11.8.5 Regular Expression Literals {{{ */
893 RegularExpressionSlash
894 : "/" { $$ = false; }
895 | "/=" { $$ = true; }
898 RegularExpressionLiteral
899 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
903 /* 11.9 Automatic Semicolon Insertion {{{ */
905 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
913 : LexNewLineOrNot "\n"
918 : LexNewLineOrNot "\n" StrictSemi
919 | NewLineNot LexOf Terminator
924 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
929 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
934 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
938 /* 12.1 Identifiers {{{ */
940 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
941 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
945 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
946 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
947 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
951 : BindingIdentifier[pass] { $$ = $pass; }
952 | LexOf { $$ = NULL; }
956 : Identifier[pass] { $$ = $pass; }
957 | "yield" { $$ = CYNew CYIdentifier("yield"); }
961 : Identifier_[pass] { $$ = $pass; }
962 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
963 | "as" { $$ = CYNew CYIdentifier("as"); }
964 | "await" { $$ = CYNew CYIdentifier("await"); }
965 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
966 | "byte" { $$ = CYNew CYIdentifier("byte"); }
967 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
968 | "double" { $$ = CYNew CYIdentifier("double"); }
969 | "each" { $$ = CYNew CYIdentifier("each"); }
970 | "eval" { $$ = CYNew CYIdentifier("eval"); }
971 | "final" { $$ = CYNew CYIdentifier("final"); }
972 | "float" { $$ = CYNew CYIdentifier("float"); }
973 | "from" { $$ = CYNew CYIdentifier("from"); }
974 | "get" { $$ = CYNew CYIdentifier("get"); }
975 | "goto" { $$ = CYNew CYIdentifier("goto"); }
976 | "implements" { $$ = CYNew CYIdentifier("implements"); }
977 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
978 | "interface" { $$ = CYNew CYIdentifier("interface"); }
979 | "let" { $$ = CYNew CYIdentifier("let"); }
980 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
981 | "native" { $$ = CYNew CYIdentifier("native"); }
982 | "package" { $$ = CYNew CYIdentifier("package"); }
983 | "private" { $$ = CYNew CYIdentifier("private"); }
984 | "protected" { $$ = CYNew CYIdentifier("protected"); }
985 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
986 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
987 | "public" { $$ = CYNew CYIdentifier("public"); }
988 | "set" { $$ = CYNew CYIdentifier("set"); }
989 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
990 | "target" { $$ = CYNew CYIdentifier("target"); }
991 | "throws" { $$ = CYNew CYIdentifier("throws"); }
992 | "transient" { $$ = CYNew CYIdentifier("transient"); }
993 | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
994 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
996 | "bool" { $$ = CYNew CYIdentifier("bool"); }
997 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
998 | "id" { $$ = CYNew CYIdentifier("id"); }
999 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
1004 : IdentifierTypeNoOf[pass] { $$ = $pass; }
1005 | "of" { $$ = CYNew CYIdentifier("of"); }
1009 : IdentifierType[pass] { $$ = $pass; }
1014 : IdentifierTypeNoOf
1015 | "char" { $$ = CYNew CYIdentifier("char"); }
1016 | "int" { $$ = CYNew CYIdentifier("int"); }
1017 | "long" { $$ = CYNew CYIdentifier("long"); }
1018 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1019 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1020 | "short" { $$ = CYNew CYIdentifier("short"); }
1021 | "static" { $$ = CYNew CYIdentifier("static"); }
1022 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1024 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1025 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1028 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1029 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1030 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1031 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1036 : IdentifierNoOf[pass] { $$ = $pass; }
1037 | "of" { $$ = CYNew CYIdentifier("of"); }
1038 | "!of" { $$ = CYNew CYIdentifier("of"); }
1041 /* 12.2 Primary Expression {{{ */
1043 : "this" { $$ = CYNew CYThis(); }
1044 | IdentifierReference[pass] { $$ = $pass; }
1045 | Literal[pass] { $$ = $pass; }
1046 | ArrayLiteral[pass] { $$ = $pass; }
1047 | ObjectLiteral[pass] { $$ = $pass; }
1048 | FunctionExpression[pass] { $$ = $pass; }
1049 | ClassExpression[pass] { $$ = $pass; }
1050 | GeneratorExpression[pass] { $$ = $pass; }
1051 | RegularExpressionLiteral[pass] { $$ = $pass; }
1052 | TemplateLiteral[pass] { $$ = $pass; }
1053 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1054 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1057 CoverParenthesizedExpressionAndArrowParameterList
1058 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1059 | "(" LexOf ")" { $$ = NULL; }
1060 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1061 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1064 /* 12.2.4 Literals {{{ */
1066 : NullLiteral[pass] { $$ = $pass; }
1067 | BooleanLiteral[pass] { $$ = $pass; }
1068 | NumericLiteral[pass] { $$ = $pass; }
1069 | StringLiteral[pass] { $$ = $pass; }
1072 /* 12.2.5 Array Initializer {{{ */
1074 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1078 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1079 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1083 : "," ElementListOpt[elements] { $$ = $elements; }
1088 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1089 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1093 : ElementList[pass] { $$ = $pass; }
1094 | LexOf { $$ = NULL; }
1097 /* 12.2.6 Object Initializer {{{ */
1099 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1102 PropertyDefinitionList_
1103 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1107 PropertyDefinitionList
1108 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1111 PropertyDefinitionListOpt
1112 : PropertyDefinitionList[properties] { $$ = $properties; }
1117 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1118 | CoverInitializedName[name] { CYNOT(@$); }
1119 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1120 | MethodDefinition[pass] { $$ = $pass; }
1124 : LiteralPropertyName[pass] { $$ = $pass; }
1125 | ComputedPropertyName[pass] { $$ = $pass; }
1129 : IdentifierName[pass] { $$ = $pass; }
1130 | StringLiteral[pass] { $$ = $pass; }
1131 | NumericLiteral[pass] { $$ = $pass; }
1134 ComputedPropertyName
1135 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1138 CoverInitializedName
1139 : IdentifierReference Initializer
1143 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1147 : Initializer[pass] { $$ = $pass; }
1151 /* 12.2.9 Template Literals {{{ */
1153 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1154 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1158 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1159 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1163 /* 12.3 Left-Hand-Side Expressions {{{ */
1165 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1166 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1167 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1168 | TemplateLiteral { CYNOT(@$); }
1172 : PrimaryExpression[pass] { $$ = $pass; }
1173 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1174 | SuperProperty[pass] { $$ = $pass; }
1175 | MetaProperty { CYNOT(@$); }
1176 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1180 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1181 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1189 : "new" "." "target"
1193 : MemberExpression[pass] { $$ = $pass; }
1194 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1198 : MemberExpression[pass] { $$ = $pass; }
1199 | CallExpression[pass] { $$ = $pass; }
1203 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1204 | SuperCall[pass] { $$ = $pass; }
1205 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1209 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1213 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1217 : "," ArgumentList[arguments] { $$ = $arguments; }
1222 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1223 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1227 : ArgumentList[pass] { $$ = $pass; }
1228 | LexOf { $$ = NULL; }
1232 : NewExpression[pass] { $$ = $pass; }
1233 | CallExpression[pass] { $$ = $pass; }
1236 LeftHandSideExpression
1237 : BracedExpression[pass] { $$ = $pass; }
1238 | IndirectExpression[pass] { $$ = $pass; }
1241 /* 12.4 Postfix Expressions {{{ */
1243 : BracedExpression[pass] { $$ = $pass; }
1244 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1245 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1248 /* 12.5 Unary Operators {{{ */
1250 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1251 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1252 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1253 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1254 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1255 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1256 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1257 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1258 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1262 : PostfixExpression[expression] { $$ = $expression; }
1263 | UnaryExpression_[pass] { $$ = $pass; }
1266 /* 12.6 Multiplicative Operators {{{ */
1267 MultiplicativeExpression
1268 : UnaryExpression[pass] { $$ = $pass; }
1269 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1270 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1271 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1274 /* 12.7 Additive Operators {{{ */
1276 : MultiplicativeExpression[pass] { $$ = $pass; }
1277 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1278 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1281 /* 12.8 Bitwise Shift Operators {{{ */
1283 : AdditiveExpression[pass] { $$ = $pass; }
1284 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1285 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1286 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1289 /* 12.9 Relational Operators {{{ */
1290 RelationalExpression
1291 : ShiftExpression[pass] { $$ = $pass; }
1292 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1293 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1294 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1295 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1296 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1297 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1300 /* 12.10 Equality Operators {{{ */
1302 : RelationalExpression[pass] { $$ = $pass; }
1303 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1304 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1305 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1306 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1309 /* 12.11 Binary Bitwise Operators {{{ */
1310 BitwiseANDExpression
1311 : EqualityExpression[pass] { $$ = $pass; }
1312 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1315 BitwiseXORExpression
1316 : BitwiseANDExpression[pass] { $$ = $pass; }
1317 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1321 : BitwiseXORExpression[pass] { $$ = $pass; }
1322 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1325 /* 12.12 Binary Logical Operators {{{ */
1326 LogicalANDExpression
1327 : BitwiseORExpression[pass] { $$ = $pass; }
1328 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1332 : LogicalANDExpression[pass] { $$ = $pass; }
1333 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1336 /* 12.13 Conditional Operator ( ? : ) {{{ */
1338 ConditionalExpressionClassic
1339 : LogicalORExpression[pass] { $$ = $pass; }
1340 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1344 ConditionalExpression
1345 : LogicalORExpression[pass] { $$ = $pass; }
1346 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1349 /* 12.14 Assignment Operators {{{ */
1350 LeftHandSideAssignment
1351 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1352 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1353 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1354 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1355 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1356 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1357 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1358 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1359 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1360 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1361 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1362 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1366 AssignmentExpressionClassic
1367 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1368 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1372 AssignmentExpression
1373 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1374 | LexOf YieldExpression[pass] { $$ = $pass; }
1375 | ArrowFunction[pass] { $$ = $pass; }
1376 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1379 /* 12.15 Comma Operator ( , ) {{{ */
1381 : AssignmentExpression[pass] { $$ = $pass; }
1382 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1386 : Expression[pass] { $$ = $pass; }
1387 | LexOf { $$ = NULL; }
1391 /* 13 Statements and Declarations {{{ */
1393 : BlockStatement[pass] { $$ = $pass; }
1394 | VariableStatement[pass] { $$ = $pass; }
1395 | EmptyStatement[pass] { $$ = $pass; }
1396 | IfStatement[pass] { $$ = $pass; }
1397 | BreakableStatement[pass] { $$ = $pass; }
1398 | ContinueStatement[pass] { $$ = $pass; }
1399 | BreakStatement[pass] { $$ = $pass; }
1400 | ReturnStatement[pass] { $$ = $pass; }
1401 | WithStatement[pass] { $$ = $pass; }
1402 | LabelledStatement[pass] { $$ = $pass; }
1403 | ThrowStatement[pass] { $$ = $pass; }
1404 | TryStatement[pass] { $$ = $pass; }
1405 | DebuggerStatement[pass] { $$ = $pass; }
1409 : LexOf Statement__[pass] { $$ = $pass; }
1410 | ExpressionStatement[pass] { $$ = $pass; }
1414 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1418 : HoistableDeclaration[pass] { $$ = $pass; }
1419 | ClassDeclaration[pass] { $$ = $pass; }
1423 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1424 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1427 HoistableDeclaration
1428 : FunctionDeclaration[pass] { $$ = $pass; }
1429 | GeneratorDeclaration[pass] { $$ = $pass; }
1433 : IterationStatement[pass] { $$ = $pass; }
1434 | SwitchStatement[pass] { $$ = $pass; }
1437 /* 13.2 Block {{{ */
1439 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1443 : "{" StatementListOpt[code] "}" { $$ = $code; }
1447 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1451 : StatementList[pass] { $$ = $pass; }
1452 | LexSetStatement LexLet LexOf { $$ = NULL; }
1456 : Statement[pass] { $$ = $pass; }
1457 | Declaration[pass] { $$ = $pass; }
1460 /* 13.3 Let and Const Declarations {{{ */
1462 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1466 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1470 : { CYMAP(_let__, _let_); }
1474 : { CYMAP(_of__, _of_); }
1478 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1482 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1483 | LexLet LexOf "const" { $$ = true; }
1487 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1492 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1496 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1497 | LexOf BindingPattern Initializer { CYNOT(@$); }
1500 /* 13.3.2 Variable Statement {{{ */
1502 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1506 : VariableStatement_[statement] Terminator { $$ = $statement; }
1509 VariableDeclarationList_
1510 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1514 VariableDeclarationList
1515 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1519 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1520 | LexOf BindingPattern Initializer { CYNOT(@$); }
1523 /* 13.3.3 Destructuring Binding Patterns {{{ */
1525 : ObjectBindingPattern
1526 | ArrayBindingPattern
1529 ObjectBindingPattern
1530 : "let {" BindingPropertyListOpt "}"
1534 : "let [" BindingElementListOpt "]"
1537 BindingPropertyList_
1538 : "," BindingPropertyListOpt
1543 : BindingProperty BindingPropertyList_
1546 BindingPropertyListOpt
1547 : BindingPropertyList
1552 : BindingElementOpt[element] "," BindingElementListOpt[next]
1553 | BindingRestElement[element]
1554 | BindingElement[element]
1557 BindingElementListOpt
1558 : BindingElementList[pass]
1564 | LexOf PropertyName ":" BindingElement
1568 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1569 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1573 : BindingElement[pass]
1578 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1582 : LexBind LexOf "..." BindingIdentifier
1585 /* 13.4 Empty Statement {{{ */
1587 : ";" { $$ = CYNew CYEmpty(); }
1590 /* 13.5 Expression Statement {{{ */
1591 ExpressionStatement_
1592 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1595 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1598 /* 13.6 The if Statement {{{ */
1600 : "else" Statement[false] { $$ = $false; }
1601 | %prec "if" { $$ = NULL; }
1605 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1608 /* 13.7 Iteration Statements {{{ */
1610 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1611 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1612 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1613 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1614 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1615 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1618 ForStatementInitializer
1619 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1620 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1621 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1622 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1625 ForInStatementInitializer
1626 : LexLet LexOf BracedExpression[pass] { $$ = $pass; }
1627 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1628 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1629 | ForDeclaration[pass] { $$ = $pass; }
1633 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1637 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1638 | LexOf BindingPattern { CYNOT(@$); }
1641 /* 13.8 The continue Statement {{{ */
1643 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1644 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1647 /* 13.9 The break Statement {{{ */
1649 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1650 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1653 /* 13.10 The return Statement {{{ */
1655 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1656 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1659 /* 13.11 The with Statement {{{ */
1661 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1664 /* 13.12 The switch Statement {{{ */
1666 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1670 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1674 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1678 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1679 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1683 // XXX: the standard makes certain you can only have one of these
1685 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1688 /* 13.13 Labelled Statements {{{ */
1690 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1694 : Statement[pass] { $$ = $pass; }
1695 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1698 /* 13.14 The throw Statement {{{ */
1700 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1701 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1704 /* 13.15 The try Statement {{{ */
1706 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1707 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1708 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1712 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1716 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1720 : BindingIdentifier[pass] { $$ = $pass; }
1721 | LexOf BindingPattern { CYNOT(@$); }
1724 /* 13.16 The debugger Statement {{{ */
1726 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1730 /* 14.1 Function Definitions {{{ */
1732 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1736 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1739 StrictFormalParameters
1740 : FormalParameters[pass] { $$ = $pass; }
1744 : LexBind LexOf { $$ = NULL; }
1745 | FormalParameterList
1748 FormalParameterList_
1749 : "," FormalParameterList[parameters] { $$ = $parameters; }
1754 : FunctionRestParameter { CYNOT(@$); }
1755 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1758 FunctionRestParameter
1759 : BindingRestElement
1763 : BindingElement[pass] { $$ = $pass; }
1767 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1770 FunctionStatementList
1771 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1774 /* 14.2 Arrow Function Definitions {{{ */
1776 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1780 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1781 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1785 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1786 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1789 /* 14.3 Method Definitions {{{ */
1791 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1792 | GeneratorMethod[pass] { $$ = $pass; }
1793 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1794 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1797 PropertySetParameterList
1798 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1801 /* 14.4 Generator Function Definitions {{{ */
1803 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1806 GeneratorDeclaration
1807 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1811 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1815 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1819 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1820 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield"
1821 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1822 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1825 /* 14.5 Class Definitions {{{ */
1827 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1831 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1835 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1839 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1843 : ClassHeritage[pass] { $$ = $pass; }
1844 | { $$ = CYNew CYClassTail(NULL); }
1857 : ClassElementListOpt ClassElement
1866 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1867 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1872 /* 15.1 Scripts {{{ */
1874 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1878 : StatementList[pass] { $$ = $pass; }
1882 : ScriptBody[pass] { $$ = $pass; }
1883 | LexSetStatement LexLet LexOf { $$ = NULL; }
1886 /* 15.2 Modules {{{ */
1888 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1892 : ModuleItemList[pass] { $$ = $pass; }
1896 : ModuleBody[pass] { $$ = $pass; }
1897 | LexSetStatement LexLet LexOf { $$ = NULL; }
1901 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1905 : ModuleItemList[pass] { $$ = $pass; }
1906 | LexSetStatement LexLet LexOf { $$ = NULL; }
1910 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1911 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1912 | StatementListItem[pass] { $$ = $pass; }
1915 /* 15.2.2 Imports {{{ */
1917 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1918 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1922 : ImportedDefaultBinding[default] { $$ = $default; }
1923 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1924 | LexOf NamedImports[pass] { $$ = $pass; }
1925 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1926 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1929 ImportedDefaultBinding
1930 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1934 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1938 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1942 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1946 : "," ImportsListOpt[pass] { $$ = $pass; }
1951 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1955 : ImportsList[pass] { $$ = $pass; }
1956 | LexOf { $$ = NULL; }
1960 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1961 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1965 : StringLiteral[pass] { $$ = $pass; }
1969 : BindingIdentifier[pass] { $$ = $pass; }
1972 /* 15.2.3 Exports {{{ */
1974 : "*" FromClause Terminator
1975 | ExportClause FromClause Terminator
1976 | ExportClause Terminator
1978 | "default" LexSetStatement LexOf HoistableDeclaration
1979 | "default" LexSetStatement LexOf ClassDeclaration
1980 | "default" LexSetStatement AssignmentExpression Terminator
1984 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1985 | "export" Declaration
1989 : ";{" ExportsListOpt "}"
1993 : "," ExportsListOpt
1998 : ExportSpecifier ExportsList_
2008 | IdentifierName "as" IdentifierName
2013 /* Cycript (C): Type Encoding {{{ */
2015 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
2016 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2020 : { $$ = CYNew CYTypedIdentifier(@$); }
2024 : TypeSignifier[pass] { $$ = $pass; }
2025 | TypeSignifierNone[pass] { $$ = $pass; }
2042 ParameterModifierOpt
2048 : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
2052 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2053 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2054 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2055 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2059 : SuffixedType[pass] { $$ = $pass; }
2060 | TypeSignifierOpt[pass] { $$ = $pass; }
2064 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2068 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2069 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2072 TypeQualifierLeftOpt
2073 : TypeQualifierLeft[pass] { $$ = $pass; }
2078 : SuffixedType[pass] { $$ = $pass; }
2079 | PrefixedType[pass] { $$ = $pass; }
2080 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2081 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2082 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2085 TypeQualifierRightOpt
2086 : TypeQualifierRight[pass] { $$ = $pass; }
2087 | TypeSignifierOpt[pass] { $$ = $pass; }
2091 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2092 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2093 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2094 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2095 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2099 : IntegerType[pass] { $$ = $pass; }
2100 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2104 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2109 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2110 | IntegerType[pass] { $$ = $pass; }
2111 | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
2112 | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
2113 | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
2114 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2117 TypedIdentifierMaybe
2118 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2119 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2120 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2124 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2128 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2131 TypedIdentifierField
2132 : TypedIdentifierYes[pass] { $$ = $pass; }
2133 | 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; }
2136 TypedIdentifierEncoding
2137 : TypedIdentifierNo[pass] { $$ = $pass; }
2138 | 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; }
2141 TypedIdentifierDefinition
2142 : TypedIdentifierYes[pass] { $$ = $pass; }
2143 | 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; }
2147 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2153 /* Cycript (Objective-C): @class Declaration {{{ */
2155 /* XXX: why the hell did I choose MemberExpression? */
2156 : ":" MemberExpression[extends] { $$ = $extends; }
2160 ImplementationFieldListOpt
2161 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2166 : "+" { $$ = false; }
2167 | "-" { $$ = true; }
2171 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2172 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2176 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2179 MessageParameterList
2180 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2183 MessageParameterListOpt
2184 : MessageParameterList[pass] { $$ = $pass; }
2185 | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
2189 : MessageParameterList[pass] { $$ = $pass; }
2190 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2193 ClassMessageDeclaration
2194 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2197 ClassMessageDeclarationListOpt
2198 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2202 // XXX: this should be AssignmentExpressionNoRight
2204 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2208 : "," ClassProtocols[protocols] { $$ = $protocols; }
2212 ClassProtocolListOpt
2213 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2217 ImplementationStatement
2218 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2226 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2230 : ImplementationStatement[pass] { $$ = $pass; }
2231 | CategoryStatement[pass] { $$ = $pass; }
2234 /* Cycript (Objective-C): Send Message {{{ */
2236 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2241 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2242 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2246 : SelectorCall[pass] { $$ = $pass; }
2247 | VariadicCall[pass] { $$ = $pass; }
2251 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2255 : SelectorCall[pass] { $$ = $pass; }
2256 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2260 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2261 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2265 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2269 : SelectorExpression_[pass] { $$ = $pass; }
2270 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2273 SelectorExpressionOpt
2274 : SelectorExpression_[pass] { $$ = $pass; }
2279 : MessageExpression[pass] { $$ = $pass; }
2280 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2285 /* Cycript: @import Directive {{{ */
2287 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2288 | Word[part] { $$ = CYNew CYModule($part); }
2292 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2297 /* Cycript (Objective-C): Boxed Expressions {{{ */
2299 : NullLiteral[pass] { $$ = $pass; }
2300 | BooleanLiteral[pass] { $$ = $pass; }
2301 | NumericLiteral[pass] { $$ = $pass; }
2302 | StringLiteral[pass] { $$ = $pass; }
2303 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2304 | "YES" { $$ = CYNew CYTrue(); }
2305 | "NO" { $$ = CYNew CYFalse(); }
2309 : "," KeyValuePairListOpt[next] { $$ = $next; }
2313 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2317 : KeyValuePairList[pass] { $$ = $pass; }
2318 | LexOf { $$ = NULL; }
2322 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2323 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2324 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2326 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2327 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2328 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2329 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2330 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2333 /* Cycript (Objective-C): Block Expressions {{{ */
2335 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2338 /* Cycript (Objective-C): Instance Literals {{{ */
2340 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2346 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2348 : IndirectExpression[pass] { $$ = $pass; }
2352 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2356 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2360 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2361 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2362 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2365 /* Cycript (C): Lambda Expressions {{{ */
2367 : "," TypedParameterList[parameters] { $$ = $parameters; }
2368 | { $$ = CYNew CYTypedFormal(false); }
2372 : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
2373 | "..." { $$ = CYNew CYTypedFormal(true); }
2376 TypedParameterListOpt
2377 : TypedParameterList[pass] { $$ = $pass; }
2378 | "void" { $$ = CYNew CYTypedFormal(false); }
2379 | { $$ = CYNew CYTypedFormal(false); }
2383 : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
2387 : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2390 /* Cycript (C): Structure Definitions {{{ */
2392 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2396 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2400 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2403 /* Cycript (C): Type Definitions {{{ */
2405 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2409 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2413 : TypeDefinition[pass] { $$ = $pass; }
2417 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2420 /* Cycript (C): extern "C" {{{ */
2422 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2426 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2427 | TypeDefinition[pass] { $$ = $pass; }
2430 ExternCStatementListOpt
2431 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2436 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2437 | ExternCStatement[pass] { $$ = $pass; }
2441 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2447 /* Lexer State {{{ */
2449 : { driver.PushCondition(CYDriver::RegExpCondition); }
2453 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2457 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2461 : { driver.PopCondition(); }
2465 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2469 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2472 /* Virtual Tokens {{{ */
2479 /* 8.1 Context Keywords {{{ */
2481 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2482 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2485 /* 8.3 XML Initializer Input Elements {{{ */
2487 : XMLComment { $$ = $1; }
2488 | XMLCDATA { $$ = $1; }
2489 | XMLPI { $$ = $1; }
2493 /* 11.1 Primary Expressions {{{ */
2495 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2496 | XMLInitilizer { $$ = $1; }
2497 | XMLListInitilizer { $$ = $1; }
2501 : AttributeIdentifier { $$ = $1; }
2502 | QualifiedIdentifier { $$ = $1; }
2503 | WildcardIdentifier { $$ = $1; }
2506 /* 11.1.1 Attribute Identifiers {{{ */
2508 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2512 : PropertySelector { $$ = $1; }
2513 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2517 : Identifier { $$ = CYNew CYSelector($1); }
2518 | WildcardIdentifier { $$ = $1; }
2521 /* 11.1.2 Qualified Identifiers {{{ */
2522 QualifiedIdentifier_
2523 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2524 | QualifiedIdentifier { $$ = $1; }
2528 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2531 /* 11.1.3 Wildcard Identifiers {{{ */
2533 : "*" { $$ = CYNew CYWildcard(); }
2536 /* 11.1.4 XML Initializer {{{ */
2538 : XMLMarkup { $$ = $1; }
2539 | XMLElement { $$ = $1; }
2543 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2544 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2548 : LexPushXMLTag XMLTagName XMLAttributes
2552 : "{" LexPushRegExp Expression LexPop "}"
2561 : XMLAttributes_ XMLAttribute
2566 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2567 | XMLAttributes_ XMLWhitespaceOpt
2576 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2580 : XMLExpression XMLElementContentOpt
2581 | XMLMarkup XMLElementContentOpt
2582 | XMLText XMLElementContentOpt
2583 | XMLElement XMLElementContentOpt
2586 XMLElementContentOpt
2591 /* 11.1.5 XMLList Initializer {{{ */
2593 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2597 /* 11.2 Left-Hand-Side Expressions {{{ */
2599 : Identifier { $$ = $1; }
2600 | PropertyIdentifier { $$ = $1; }
2604 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2605 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2606 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2609 /* 12.1 The default xml namespace Statement {{{ */
2610 /* XXX: DefaultXMLNamespaceStatement
2611 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2615 : DefaultXMLNamespaceStatement { $$ = $1; }
2620 /* JavaScript FTL: Array Comprehensions {{{ */
2622 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2626 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2629 /* JavaScript FTL: for each {{{ */
2631 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2635 /* JavaScript FTW: Array Comprehensions {{{ */
2637 : ArrayComprehension
2641 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2645 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2650 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2651 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2655 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2656 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2660 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2663 /* JavaScript FTW: Named Arguments {{{ */
2665 : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2668 /* JavaScript FTW: Subscript Access {{{ */
2670 : "." "[" AssignmentExpression[property] "]" { $$ = CYNew CYSubscriptMember(NULL, $property); }
2674 /* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */
2676 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); }
2680 /* JavaScript FTW: Ruby Blocks {{{ */
2681 RubyProcParameterList_
2682 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2686 RubyProcParameterList
2687 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2688 | LexOf { $$ = NULL; }
2692 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2693 | "||" { $$ = NULL; }
2696 RubyProcParametersOpt
2697 : RubyProcParameters[pass] { $$ = $pass; }
2702 : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); }
2706 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2710 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2711 | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; }
2715 : BracedExpression_[pass] "\n" { $$ = $pass; }
2716 | BracedExpression_[pass] { $$ = $pass; }
2719 /* JavaScript FTW: Ruby Scopes {{{ */
2721 : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); }
2722 | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); }
2723 | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; }
2726 /* JavaScript FTW: Ruby Symbols {{{ */
2728 : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); }
2734 bool CYDriver::Parse(CYMark mark) {
2736 CYLocal<CYPool> local(&pool_);
2737 cy::parser parser(*this);
2739 parser.set_debug_level(debug_);
2741 return parser.parse() != 0;
2744 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2748 CYDriver::Error error;
2749 error.warning_ = true;
2750 error.location_ = location;
2751 error.message_ = message;
2752 errors_.push_back(error);
2755 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2756 CYDriver::Error error;
2757 error.warning_ = false;
2758 error.location_ = location;
2759 error.message_ = message;
2760 driver.errors_.push_back(error);