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 { CYInfix *infix_; }
65 %union { CYLiteral *literal_; }
66 %union { CYMethod *method_; }
67 %union { CYModule *module_; }
68 %union { CYNull *null_; }
69 %union { CYNumber *number_; }
70 %union { CYParenthetical *parenthetical_; }
71 %union { CYProperty *property_; }
72 %union { CYPropertyName *propertyName_; }
73 %union { CYRubyProc *rubyProc_; }
74 %union { CYSpan *span_; }
75 %union { CYStatement *statement_; }
76 %union { CYString *string_; }
77 %union { CYTarget *target_; }
78 %union { CYThis *this_; }
79 %union { CYTrue *true_; }
80 %union { CYWord *word_; }
83 %union { CYTypeModifier *modifier_; }
84 %union { CYTypeSpecifier *specifier_; }
85 %union { CYTypedIdentifier *typedIdentifier_; }
86 %union { CYTypedParameter *typedParameter_; }
90 %union { CYMessage *message_; }
91 %union { CYMessageParameter *messageParameter_; }
92 %union { CYImplementationField *implementationField_; }
93 %union { CYProtocol *protocol_; }
94 %union { CYSelectorPart *selector_; }
98 %union { CYAttribute *attribute_; }
99 %union { CYPropertyIdentifier *propertyIdentifier_; }
100 %union { CYSelector *selector_; }
106 cy::parser::semantic_type semantic_;
107 hi::Value highlight_;
110 int cylex(YYSTYPE *, CYLocation *, void *);
116 typedef cy::parser::token tk;
119 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
120 if (driver.mark_ == CYMarkIgnore);
121 else if (driver.mark_ == CYMarkScript) {
122 driver.mark_ = CYMarkIgnore;
123 return cy::parser::token::MarkScript;
124 } else if (driver.mark_ == CYMarkModule) {
125 driver.mark_ = CYMarkIgnore;
126 return cy::parser::token::MarkModule;
130 if (driver.newline_ == CYDriver::NewLineHere)
131 driver.newline_ = CYDriver::NewLineLast;
132 else if (driver.newline_ == CYDriver::NewLineLast)
133 driver.newline_ = CYDriver::NewLineNone;
136 int token(cylex(&data, location, driver.scanner_));
137 *semantic = data.semantic_;
141 case tk::OpenBracket:
143 driver.in_.push(false);
147 if (driver.in_.top())
152 case tk::CloseBracket:
159 if (driver.yield_.top())
160 token = tk::_yield__;
164 driver.newline_ = CYDriver::NewLineHere;
170 driver.next_ = false;
174 #define CYLEX() do if (yyla.empty()) { \
175 YYCDEBUG << "Mapping a token: "; \
176 yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
177 YY_SYMBOL_PRINT("Next token is", yyla); \
180 #define CYMAP(to, from) do { \
182 if (yyla.type == yytranslate_(token::from)) \
183 yyla.type = yytranslate_(token::to); \
186 #define CYLIN(from) do { \
188 if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \
189 yyla.type = yytranslate_(token::from ## _); \
192 #define CYERR(location, message) do { \
193 error(location, message); \
197 #define CYEOK() do { \
199 driver.errors_.pop_back(); \
202 #define CYNOT(location) \
203 CYERR(location, "unimplemented feature")
205 #define CYMPT(location) do { \
206 if (!yyla.empty() && yyla.type_get() != yyeof_) \
207 CYERR(location, "unexpected lookahead"); \
217 @$.begin.filename = @$.end.filename = &driver.filename_;
223 %define api.location.type { CYLocation }
230 %param { CYDriver &driver }
232 /* Token Declarations {{{ */
238 %token XMLAttributeValue
240 %token XMLTagCharacters
246 %token LeftRight "<>"
247 %token LeftSlashRight "</>"
249 %token SlashRight "/>"
250 %token LeftSlash "</"
252 %token ColonColon "::"
253 %token PeriodPeriod ".."
256 @begin E4X ObjectiveC
262 %token AmpersandAmpersand "&&"
263 %token AmpersandEqual "&="
265 %token CarrotEqual "^="
267 %token EqualEqual "=="
268 %token EqualEqualEqual "==="
269 %token EqualRight "=>"
270 %token EqualRight_ "\n=>"
271 %token Exclamation "!"
272 %token ExclamationEqual "!="
273 %token ExclamationEqualEqual "!=="
275 %token HyphenEqual "-="
276 %token HyphenHyphen "--"
277 %token HyphenHyphen_ "\n--"
278 %token HyphenRight "->"
280 %token LeftEqual "<="
282 %token LeftLeftEqual "<<="
284 %token PercentEqual "%="
286 %token PeriodPeriodPeriod "..."
288 %token PipeEqual "|="
291 %token PlusEqual "+="
293 %token PlusPlus_ "\n++"
295 %token RightEqual ">="
296 %token RightRight ">>"
297 %token RightRightEqual ">>="
298 %token RightRightRight ">>>"
299 %token RightRightRightEqual ">>>="
301 %token SlashEqual "/="
303 %token StarEqual "*="
315 %token CloseParen ")"
318 %token OpenBrace_ "\n{"
319 %token OpenBrace__ ";{"
320 %token OpenBrace_let "let {"
321 %token CloseBrace "}"
323 %token OpenBracket "["
324 %token OpenBracket_let "let ["
325 %token CloseBracket "]"
327 %token At_error_ "@error"
330 %token At_class_ "@class"
334 %token _typedef_ "typedef"
335 %token _unsigned_ "unsigned"
336 %token _signed_ "signed"
337 %token _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"
362 %token _break_ "break"
364 %token _catch_ "catch"
365 %token _class_ "class"
366 %token _class__ ";class"
367 %token _const_ "const"
368 %token _continue_ "continue"
369 %token _debugger_ "debugger"
370 %token _default_ "default"
371 %token _delete_ "delete"
375 %token _export_ "export"
376 %token _extends_ "extends"
377 %token _finally_ "finally"
379 %token _function_ "function"
380 %token _function__ ";function"
382 %token _import_ "import"
385 %token _Infinity_ "Infinity"
386 %token _instanceof_ "instanceof"
388 %token _return_ "return"
389 %token _super_ "super"
390 %token _switch_ "switch"
391 %token _target_ "target"
393 %token _throw_ "throw"
395 %token _typeof_ "typeof"
398 %token _while_ "while"
401 %token _abstract_ "abstract"
402 %token _await_ "await"
403 %token _boolean_ "boolean"
406 %token _constructor_ "constructor"
407 %token _double_ "double"
409 %token _final_ "final"
410 %token _float_ "float"
414 %token _implements_ "implements"
416 %token _interface_ "interface"
420 %token _native_ "native"
421 %token _package_ "package"
422 %token _private_ "private"
423 %token _protected_ "protected"
424 %token _prototype_ "prototype"
425 %token _public_ "public"
427 %token _short_ "short"
428 %token _static_ "static"
429 %token _synchronized_ "synchronized"
430 %token _throws_ "throws"
431 %token _transient_ "transient"
432 %token _volatile_ "volatile"
433 %token _yield_ "yield"
434 %token _yield__ "!yield"
436 %token _undefined_ "undefined"
453 %token _namespace_ "namespace"
460 %token <identifier_> Identifier_
461 %token <number_> NumericLiteral
462 %token <string_> StringLiteral
463 %token <literal_> RegularExpressionLiteral_
465 %token <string_> NoSubstitutionTemplate
466 %token <string_> TemplateHead
467 %token <string_> TemplateMiddle
468 %token <string_> TemplateTail
470 %type <target_> AccessExpression
471 %type <expression_> AdditiveExpression
472 %type <argument_> ArgumentList_
473 %type <argument_> ArgumentList
474 %type <argument_> ArgumentListOpt
475 %type <argument_> Arguments
476 %type <target_> ArrayComprehension
477 %type <literal_> ArrayLiteral
478 %type <expression_> ArrowFunction
479 %type <functionParameter_> ArrowParameters
480 %type <expression_> AssignmentExpression
481 %type <expression_> AssignmentExpressionOpt
482 %type <identifier_> BindingIdentifier
483 %type <identifier_> BindingIdentifierOpt
484 %type <bindings_> BindingList_
485 %type <bindings_> BindingList
486 %type <expression_> BitwiseANDExpression
487 %type <statement_> Block
488 %type <statement_> BlockStatement
489 %type <boolean_> BooleanLiteral
490 %type <binding_> BindingElement
491 %type <expression_> BitwiseORExpression
492 %type <expression_> BitwiseXORExpression
493 %type <statement_> BreakStatement
494 %type <statement_> BreakableStatement
495 %type <expression_> CallExpression_
496 %type <target_> CallExpression
497 %type <clause_> CaseBlock
498 %type <clause_> CaseClause
499 %type <clause_> CaseClausesOpt
501 %type <identifier_> CatchParameter
502 %type <statement_> ClassDeclaration
503 %type <target_> ClassExpression
504 %type <classTail_> ClassHeritage
505 %type <classTail_> ClassHeritageOpt
506 %type <classTail_> ClassTail
507 %type <target_> Comprehension
508 %type <comprehension_> ComprehensionFor
509 %type <comprehension_> ComprehensionIf
510 %type <comprehension_> ComprehensionTail
511 %type <propertyName_> ComputedPropertyName
512 %type <expression_> ConditionalExpression
513 %type <statement_> ContinueStatement
514 %type <statement_> ConciseBody
515 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
516 %type <statement_> DebuggerStatement
517 %type <statement_> Declaration_
518 %type <statement_> Declaration
519 %type <clause_> DefaultClause
520 %type <element_> ElementList
521 %type <element_> ElementListOpt
522 %type <statement_> ElseStatementOpt
523 %type <for_> EmptyStatement
524 %type <expression_> EqualityExpression
525 %type <expression_> Expression
526 %type <expression_> ExpressionOpt
527 %type <for_> ExpressionStatement_
528 %type <statement_> ExpressionStatement
529 %type <finally_> Finally
530 %type <binding_> ForBinding
531 %type <forin_> ForDeclaration
532 %type <forin_> ForInStatementInitializer
533 %type <for_> ForStatementInitializer
534 %type <binding_> FormalParameter
535 %type <functionParameter_> FormalParameterList_
536 %type <functionParameter_> FormalParameterList
537 %type <functionParameter_> FormalParameters
538 %type <statement_> FunctionBody
539 %type <statement_> FunctionDeclaration
540 %type <target_> FunctionExpression
541 %type <statement_> FunctionStatementList
542 %type <statement_> GeneratorBody
543 %type <statement_> GeneratorDeclaration
544 %type <target_> GeneratorExpression
545 %type <method_> GeneratorMethod
546 %type <statement_> HoistableDeclaration
547 %type <identifier_> Identifier
548 %type <identifier_> IdentifierNoOf
549 %type <identifier_> IdentifierType
550 %type <identifier_> IdentifierTypeNoOf
551 %type <word_> IdentifierName
552 %type <variable_> IdentifierReference
553 %type <statement_> IfStatement
554 %type <target_> IndirectExpression
555 %type <expression_> Initializer
556 %type <expression_> InitializerOpt
557 %type <statement_> IterationStatement
558 %type <identifier_> LabelIdentifier
559 %type <statement_> LabelledItem
560 %type <statement_> LabelledStatement
561 %type <assignment_> LeftHandSideAssignment
562 %type <target_> LeftHandSideExpression
563 %type <bool_> LetOrConst
564 %type <binding_> LexicalBinding
565 %type <for_> LexicalDeclaration_
566 %type <statement_> LexicalDeclaration
567 %type <literal_> Literal
568 %type <propertyName_> LiteralPropertyName
569 %type <expression_> LogicalANDExpression
570 %type <expression_> LogicalORExpression
571 %type <access_> MemberAccess
572 %type <target_> MemberExpression
573 %type <method_> MethodDefinition
574 %type <module_> ModulePath
575 %type <expression_> MultiplicativeExpression
576 %type <target_> NewExpression
577 %type <null_> NullLiteral
578 %type <literal_> ObjectLiteral
579 %type <expression_> PostfixExpression
580 %type <target_> PrimaryExpression
581 %type <propertyName_> PropertyName
582 %type <property_> PropertyDefinition
583 %type <property_> PropertyDefinitionList_
584 %type <property_> PropertyDefinitionList
585 %type <property_> PropertyDefinitionListOpt
586 %type <functionParameter_> PropertySetParameterList
587 %type <literal_> RegularExpressionLiteral
588 %type <bool_> RegularExpressionSlash
589 %type <expression_> RelationalExpression
590 %type <statement_> ReturnStatement
591 %type <rubyProc_> RubyProcExpression
592 %type <functionParameter_> RubyProcParameterList_
593 %type <functionParameter_> RubyProcParameterList
594 %type <functionParameter_> RubyProcParameters
595 %type <functionParameter_> RubyProcParametersOpt
596 %type <statement_> Script
597 %type <statement_> ScriptBody
598 %type <statement_> ScriptBodyOpt
599 %type <expression_> ShiftExpression
600 %type <binding_> SingleNameBinding
601 %type <statement_> Statement__
602 %type <statement_> Statement_
603 %type <statement_> Statement
604 %type <statement_> StatementList
605 %type <statement_> StatementListOpt
606 %type <statement_> StatementListItem
607 %type <functionParameter_> StrictFormalParameters
608 %type <target_> SuperCall
609 %type <target_> SuperProperty
610 %type <statement_> SwitchStatement
611 %type <target_> TemplateLiteral
612 %type <span_> TemplateSpans
613 %type <statement_> ThrowStatement
614 %type <statement_> TryStatement
615 %type <expression_> UnaryExpression_
616 %type <expression_> UnaryExpression
617 %type <binding_> VariableDeclaration
618 %type <bindings_> VariableDeclarationList_
619 %type <bindings_> VariableDeclarationList
620 %type <for_> VariableStatement_
621 %type <statement_> VariableStatement
622 %type <statement_> WithStatement
625 %type <word_> WordOpt
627 %type <expression_> YieldExpression
630 %type <specifier_> IntegerType
631 %type <specifier_> IntegerTypeOpt
632 %type <typedIdentifier_> PrefixedType
633 %type <specifier_> PrimitiveType
634 %type <typedIdentifier_> SuffixedType
635 %type <typedIdentifier_> TypeSignifier
636 %type <modifier_> TypeQualifierLeft
637 %type <typedIdentifier_> TypeQualifierRight
638 %type <typedIdentifier_> TypedIdentifier
639 %type <typedParameter_> TypedParameterList_
640 %type <typedParameter_> TypedParameterList
641 %type <typedParameter_> TypedParameterListOpt
645 %type <expression_> AssignmentExpressionClassic
646 %type <expression_> BoxableExpression
647 %type <statement_> CategoryStatement
648 %type <expression_> ClassSuperOpt
649 %type <expression_> ConditionalExpressionClassic
650 %type <implementationField_> ImplementationFieldListOpt
651 %type <implementationField_> ImplementationFields
652 %type <message_> ClassMessageDeclaration
653 %type <message_> ClassMessageDeclarationListOpt
654 %type <protocol_> ClassProtocolListOpt
655 %type <protocol_> ClassProtocols
656 %type <protocol_> ClassProtocolsOpt
657 %type <statement_> ImplementationStatement
658 %type <target_> MessageExpression
659 %type <messageParameter_> MessageParameter
660 %type <messageParameter_> MessageParameters
661 %type <messageParameter_> MessageParameterList
662 %type <messageParameter_> MessageParameterListOpt
663 %type <bool_> MessageScope
664 %type <argument_> SelectorCall_
665 %type <argument_> SelectorCall
666 %type <selector_> SelectorExpression_
667 %type <selector_> SelectorExpression
668 %type <selector_> SelectorExpressionOpt
669 %type <argument_> SelectorList
670 %type <word_> SelectorWordOpt
671 %type <typedIdentifier_> TypeOpt
672 %type <argument_> VariadicCall
676 %type <propertyIdentifier_> PropertyIdentifier_
677 %type <selector_> PropertySelector_
678 %type <selector_> PropertySelector
679 %type <identifier_> QualifiedIdentifier_
680 %type <identifier_> QualifiedIdentifier
681 %type <identifier_> WildcardIdentifier
682 %type <identifier_> XMLComment
683 %type <identifier_> XMLCDATA
684 %type <identifier_> XMLElement
685 %type <identifier_> XMLElementContent
686 %type <identifier_> XMLMarkup
687 %type <identifier_> XMLPI
689 %type <attribute_> AttributeIdentifier
690 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
691 %type <expression_> PropertyIdentifier
692 %type <expression_> XMLListInitilizer
693 %type <expression_> XMLInitilizer
696 /* Token Priorities {{{ */
712 /* Lexer State {{{ */
713 LexPushInOn: { driver.in_.push(true); };
714 LexPushInOff: { driver.in_.push(false); };
715 LexPopIn: { driver.in_.pop(); };
717 LexPushReturnOn: { driver.return_.push(true); };
718 LexPopReturn: { driver.return_.pop(); };
720 LexPushSuperOn: { driver.super_.push(true); };
721 LexPushSuperOff: { driver.super_.push(false); };
722 LexPopSuper: { driver.super_.pop(); };
724 LexPushYieldOn: { driver.yield_.push(true); };
725 LexPushYieldOff: { driver.yield_.push(false); };
726 LexPopYield: { driver.yield_.pop(); };
729 : { CYMPT(@$); driver.next_ = true; }
733 : { CYMAP(YieldStar, Star); }
737 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
741 : { CYMAP(_class__, _class_); }
745 : { CYMAP(_function__, _function_); }
749 : LexNoBrace LexNoClass LexNoFunction
752 /* Virtual Tokens {{{ */
763 /* 11.6 Names and Keywords {{{ */
765 : Word[pass] { $$ = $pass; }
766 | "for" { $$ = CYNew CYWord("for"); }
767 | "in" { $$ = CYNew CYWord("in"); }
768 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
777 : IdentifierNoOf[pass] { $$ = $pass; }
778 | "auto" { $$ = CYNew CYWord("auto"); }
779 | "break" { $$ = CYNew CYWord("break"); }
780 | "case" { $$ = CYNew CYWord("case"); }
781 | "catch" { $$ = CYNew CYWord("catch"); }
782 | "class" LexOf { $$ = CYNew CYWord("class"); }
783 | ";class" { $$ = CYNew CYWord("class"); }
784 | "const" { $$ = CYNew CYWord("const"); }
785 | "continue" { $$ = CYNew CYWord("continue"); }
786 | "debugger" { $$ = CYNew CYWord("debugger"); }
787 | "default" { $$ = CYNew CYWord("default"); }
788 | "delete" { $$ = CYNew CYWord("delete"); }
789 | "do" { $$ = CYNew CYWord("do"); }
790 | "else" { $$ = CYNew CYWord("else"); }
791 | "enum" { $$ = CYNew CYWord("enum"); }
792 | "export" { $$ = CYNew CYWord("export"); }
793 | "extends" { $$ = CYNew CYWord("extends"); }
794 | "false" { $$ = CYNew CYWord("false"); }
795 | "finally" { $$ = CYNew CYWord("finally"); }
796 | "function" LexOf { $$ = CYNew CYWord("function"); }
797 | "if" { $$ = CYNew CYWord("if"); }
798 | "import" { $$ = CYNew CYWord("import"); }
799 | "!in" { $$ = CYNew CYWord("in"); }
800 | "!of" { $$ = CYNew CYWord("of"); }
801 | "new" { $$ = CYNew CYWord("new"); }
802 | "null" { $$ = CYNew CYWord("null"); }
803 | "return" { $$ = CYNew CYWord("return"); }
804 | "super" { $$ = CYNew CYWord("super"); }
805 | "switch" { $$ = CYNew CYWord("switch"); }
806 | "this" { $$ = CYNew CYWord("this"); }
807 | "throw" { $$ = CYNew CYWord("throw"); }
808 | "true" { $$ = CYNew CYWord("true"); }
809 | "try" { $$ = CYNew CYWord("try"); }
810 | "typeof" { $$ = CYNew CYWord("typeof"); }
811 | "var" { $$ = CYNew CYWord("var"); }
812 | "void" { $$ = CYNew CYWord("void"); }
813 | "while" { $$ = CYNew CYWord("while"); }
814 | "with" { $$ = CYNew CYWord("with"); }
815 | "yield" { $$ = CYNew CYIdentifier("yield"); }
817 | Yield LexOf NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
822 : Word[pass] { $$ = $pass; }
827 /* 11.8.1 Null Literals {{{ */
829 : "null" { $$ = CYNew CYNull(); }
832 /* 11.8.2 Boolean Literals {{{ */
834 : "true" { $$ = CYNew CYTrue(); }
835 | "false" { $$ = CYNew CYFalse(); }
838 /* 11.8.5 Regular Expression Literals {{{ */
839 RegularExpressionSlash
840 : "/" { $$ = false; }
841 | "/=" { $$ = true; }
844 RegularExpressionLiteral
845 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
849 /* 11.9 Automatic Semicolon Insertion {{{ */
851 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
861 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
866 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
870 /* 12.1 Identifiers {{{ */
872 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
873 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
877 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
878 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
879 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
883 : BindingIdentifier[pass] { $$ = $pass; }
884 | LexOf { $$ = NULL; }
888 : Identifier[pass] { $$ = $pass; }
889 | "yield" { $$ = CYNew CYIdentifier("yield"); }
893 : Identifier_[pass] { $$ = $pass; }
894 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
895 | "await" { $$ = CYNew CYIdentifier("await"); }
896 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
897 | "byte" { $$ = CYNew CYIdentifier("byte"); }
898 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
899 | "double" { $$ = CYNew CYIdentifier("double"); }
900 | "each" { $$ = CYNew CYIdentifier("each"); }
901 | "eval" { $$ = CYNew CYIdentifier("eval"); }
902 | "final" { $$ = CYNew CYIdentifier("final"); }
903 | "float" { $$ = CYNew CYIdentifier("float"); }
904 | "from" { $$ = CYNew CYIdentifier("from"); }
905 | "get" { $$ = CYNew CYIdentifier("get"); }
906 | "goto" { $$ = CYNew CYIdentifier("goto"); }
907 | "implements" { $$ = CYNew CYIdentifier("implements"); }
908 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
909 | "interface" { $$ = CYNew CYIdentifier("interface"); }
910 | "let" { $$ = CYNew CYIdentifier("let"); }
911 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
912 | "native" { $$ = CYNew CYIdentifier("native"); }
913 | "package" { $$ = CYNew CYIdentifier("package"); }
914 | "private" { $$ = CYNew CYIdentifier("private"); }
915 | "protected" { $$ = CYNew CYIdentifier("protected"); }
916 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
917 | "public" { $$ = CYNew CYIdentifier("public"); }
918 | "set" { $$ = CYNew CYIdentifier("set"); }
919 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
920 | "target" { $$ = CYNew CYIdentifier("target"); }
921 | "throws" { $$ = CYNew CYIdentifier("throws"); }
922 | "transient" { $$ = CYNew CYIdentifier("transient"); }
923 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
925 | "bool" { $$ = CYNew CYIdentifier("bool"); }
926 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
927 | "id" { $$ = CYNew CYIdentifier("id"); }
928 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
933 : IdentifierTypeNoOf[pass] { $$ = $pass; }
934 | "of" { $$ = CYNew CYIdentifier("of"); }
939 | "char" { $$ = CYNew CYIdentifier("char"); }
940 | "int" { $$ = CYNew CYIdentifier("int"); }
941 | "long" { $$ = CYNew CYIdentifier("long"); }
942 | "short" { $$ = CYNew CYIdentifier("short"); }
943 | "static" { $$ = CYNew CYIdentifier("static"); }
944 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
946 | "extern" { $$ = CYNew CYIdentifier("extern"); }
947 | "signed" { $$ = CYNew CYIdentifier("signed"); }
948 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
949 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
952 | "nil" { $$ = CYNew CYIdentifier("nil"); }
953 | "NO" { $$ = CYNew CYIdentifier("NO"); }
954 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
955 | "YES" { $$ = CYNew CYIdentifier("YES"); }
960 : IdentifierNoOf[pass] { $$ = $pass; }
961 | "of" { $$ = CYNew CYIdentifier("of"); }
962 | "!of" { $$ = CYNew CYIdentifier("of"); }
965 /* 12.2 Primary Expression {{{ */
967 : "this" { $$ = CYNew CYThis(); }
968 | IdentifierReference[pass] { $$ = $pass; }
969 | Literal[pass] { $$ = $pass; }
970 | ArrayLiteral[pass] { $$ = $pass; }
971 | ObjectLiteral[pass] { $$ = $pass; }
972 | FunctionExpression[pass] { $$ = $pass; }
973 | ClassExpression[pass] { $$ = $pass; }
974 | GeneratorExpression[pass] { $$ = $pass; }
975 | RegularExpressionLiteral[pass] { $$ = $pass; }
976 | TemplateLiteral[pass] { $$ = $pass; }
977 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
978 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
981 CoverParenthesizedExpressionAndArrowParameterList
982 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
983 | "(" LexOf ")" { $$ = NULL; }
984 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
985 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
988 /* 12.2.4 Literals {{{ */
990 : NullLiteral[pass] { $$ = $pass; }
991 | BooleanLiteral[pass] { $$ = $pass; }
992 | NumericLiteral[pass] { $$ = $pass; }
993 | StringLiteral[pass] { $$ = $pass; }
996 /* 12.2.5 Array Initializer {{{ */
998 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1002 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1003 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1004 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1008 : ElementList[pass] { $$ = $pass; }
1009 | LexOf { $$ = NULL; }
1012 /* 12.2.6 Object Initializer {{{ */
1014 : BRACE PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1017 PropertyDefinitionList_
1018 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1022 PropertyDefinitionList
1023 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1026 PropertyDefinitionListOpt
1027 : PropertyDefinitionList[properties] { $$ = $properties; }
1032 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1033 | CoverInitializedName[name] { CYNOT(@$); }
1034 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1035 | MethodDefinition[pass] { $$ = $pass; }
1039 : LiteralPropertyName[pass] { $$ = $pass; }
1040 | ComputedPropertyName[pass] { $$ = $pass; }
1044 : IdentifierName[pass] { $$ = $pass; }
1045 | StringLiteral[pass] { $$ = $pass; }
1046 | NumericLiteral[pass] { $$ = $pass; }
1049 ComputedPropertyName
1050 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1053 CoverInitializedName
1054 : IdentifierReference Initializer
1058 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1062 : Initializer[pass] { $$ = $pass; }
1066 /* 12.2.9 Template Literals {{{ */
1068 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1069 | TemplateHead[string] TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1073 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1074 | Expression[value] TemplateTail[string] { $$ = CYNew CYSpan($value, $string, NULL); }
1078 /* 12.3 Left-Hand-Side Expressions {{{ */
1080 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1081 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1082 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1083 | TemplateLiteral { CYNOT(@$); }
1087 : PrimaryExpression[pass] { $$ = $pass; }
1088 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1089 | SuperProperty[pass] { $$ = $pass; }
1090 | MetaProperty { CYNOT(@$); }
1091 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1095 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1096 | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1104 : "new" "." "target"
1108 : MemberExpression[pass] { $$ = $pass; }
1109 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1113 : MemberExpression[pass] { $$ = $pass; }
1114 | CallExpression[pass] { $$ = $pass; }
1118 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1119 | SuperCall[pass] { $$ = $pass; }
1120 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1124 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1128 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1132 : "," ArgumentList[arguments] { $$ = $arguments; }
1137 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1138 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1142 : ArgumentList[pass] { $$ = $pass; }
1143 | LexOf { $$ = NULL; }
1147 : NewExpression[pass] { $$ = $pass; }
1148 | CallExpression[pass] { $$ = $pass; }
1151 LeftHandSideExpression
1152 : AccessExpression[pass] LexCrement { $$ = $pass; }
1153 | IndirectExpression[pass] { $$ = $pass; }
1156 /* 12.4 Postfix Expressions {{{ */
1158 : { CYLIN(PlusPlus); CYLIN(HyphenHyphen); }
1162 : AccessExpression[lhs] LexCrement { $$ = $lhs; }
1163 | AccessExpression[lhs] LexCrement "++" { $$ = CYNew CYPostIncrement($lhs); }
1164 | AccessExpression[lhs] LexCrement "--" { $$ = CYNew CYPostDecrement($lhs); }
1167 /* 12.5 Unary Operators {{{ */
1169 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1170 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1171 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1172 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1173 | "\n++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1174 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1175 | "\n--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1176 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1177 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1178 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1179 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1183 : PostfixExpression[expression] LexOpenBrace { $$ = $expression; }
1184 | UnaryExpression_[pass] { $$ = $pass; }
1187 /* 12.6 Multiplicative Operators {{{ */
1188 MultiplicativeExpression
1189 : UnaryExpression[pass] { $$ = $pass; }
1190 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1191 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1192 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1195 /* 12.7 Additive Operators {{{ */
1197 : MultiplicativeExpression[pass] { $$ = $pass; }
1198 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1199 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1202 /* 12.8 Bitwise Shift Operators {{{ */
1204 : AdditiveExpression[pass] { $$ = $pass; }
1205 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1206 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1207 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1210 /* 12.9 Relational Operators {{{ */
1211 RelationalExpression
1212 : ShiftExpression[pass] { $$ = $pass; }
1213 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1214 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1215 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1216 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1217 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1218 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1221 /* 12.10 Equality Operators {{{ */
1223 : RelationalExpression[pass] { $$ = $pass; }
1224 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1225 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1226 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1227 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1230 /* 12.11 Binary Bitwise Operators {{{ */
1231 BitwiseANDExpression
1232 : EqualityExpression[pass] { $$ = $pass; }
1233 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1236 BitwiseXORExpression
1237 : BitwiseANDExpression[pass] { $$ = $pass; }
1238 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1242 : BitwiseXORExpression[pass] { $$ = $pass; }
1243 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1246 /* 12.12 Binary Logical Operators {{{ */
1247 LogicalANDExpression
1248 : BitwiseORExpression[pass] { $$ = $pass; }
1249 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1253 : LogicalANDExpression[pass] { $$ = $pass; }
1254 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1257 /* 12.13 Conditional Operator ( ? : ) {{{ */
1259 ConditionalExpressionClassic
1260 : LogicalORExpression[pass] { $$ = $pass; }
1261 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1265 ConditionalExpression
1266 : LogicalORExpression[pass] { $$ = $pass; }
1267 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1270 /* 12.14 Assignment Operators {{{ */
1271 LeftHandSideAssignment
1272 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1273 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1274 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1275 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1276 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1277 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1278 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1279 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1280 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1281 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1282 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1283 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1287 AssignmentExpressionClassic
1288 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1289 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1293 AssignmentExpression
1294 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1295 | LexOf YieldExpression[pass] { $$ = $pass; }
1296 | ArrowFunction[pass] { $$ = $pass; }
1297 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1300 AssignmentExpressionOpt
1301 : AssignmentExpression[pass] { $$ = $pass; }
1302 | LexOf { $$ = NULL; }
1305 /* 12.15 Comma Operator ( , ) {{{ */
1307 : AssignmentExpression[pass] { $$ = $pass; }
1308 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1312 : Expression[pass] { $$ = $pass; }
1313 | LexOf { $$ = NULL; }
1317 /* 13 Statements and Declarations {{{ */
1319 : BlockStatement[pass] { $$ = $pass; }
1320 | VariableStatement[pass] { $$ = $pass; }
1321 | EmptyStatement[pass] { $$ = $pass; }
1322 | IfStatement[pass] { $$ = $pass; }
1323 | BreakableStatement[pass] { $$ = $pass; }
1324 | ContinueStatement[pass] { $$ = $pass; }
1325 | BreakStatement[pass] { $$ = $pass; }
1326 | ReturnStatement[pass] { $$ = $pass; }
1327 | WithStatement[pass] { $$ = $pass; }
1328 | LabelledStatement[pass] { $$ = $pass; }
1329 | ThrowStatement[pass] { $$ = $pass; }
1330 | TryStatement[pass] { $$ = $pass; }
1331 | DebuggerStatement[pass] { $$ = $pass; }
1335 : LexOf Statement__[pass] { $$ = $pass; }
1336 | ExpressionStatement[pass] { $$ = $pass; }
1340 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1344 : HoistableDeclaration[pass] { $$ = $pass; }
1345 | ClassDeclaration[pass] { $$ = $pass; }
1349 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1350 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1353 HoistableDeclaration
1354 : FunctionDeclaration[pass] { $$ = $pass; }
1355 | GeneratorDeclaration[pass] { $$ = $pass; }
1359 : IterationStatement[pass] { $$ = $pass; }
1360 | SwitchStatement[pass] { $$ = $pass; }
1363 /* 13.2 Block {{{ */
1365 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1369 : BRACE StatementListOpt[code] "}" { $$ = $code; }
1373 : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
1377 : StatementList[pass] { $$ = $pass; }
1378 | LexSetStatement LexLet LexOf { $$ = NULL; }
1382 : Statement[pass] { $$ = $pass; }
1383 | Declaration[pass] { $$ = $pass; }
1386 /* 13.3 Let and Const Declarations {{{ */
1388 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1392 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1396 : { CYMAP(_let__, _let_); }
1400 : { CYMAP(_of__, _of_); }
1404 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1408 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1409 | LexLet LexOf "const" { $$ = true; }
1413 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1418 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1422 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1423 | LexOf BindingPattern Initializer { CYNOT(@$); }
1426 /* 13.3.2 Variable Statement {{{ */
1428 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1432 : VariableStatement_[statement] Terminator { $$ = $statement; }
1435 VariableDeclarationList_
1436 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1440 VariableDeclarationList
1441 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1445 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1446 | LexOf BindingPattern Initializer { CYNOT(@$); }
1449 /* 13.3.3 Destructuring Binding Patterns {{{ */
1451 : ObjectBindingPattern
1452 | ArrayBindingPattern
1455 ObjectBindingPattern
1456 : "let {" BindingPropertyListOpt "}"
1460 : "let [" { CYNOT(@$); }
1463 BindingPropertyList_
1464 : "," BindingPropertyListOpt
1469 : BindingProperty BindingPropertyList_
1472 BindingPropertyListOpt
1473 : BindingPropertyList
1479 | LexOf PropertyName ":" BindingElement
1483 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1484 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1488 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1492 : "..." BindingIdentifier
1495 /* 13.4 Empty Statement {{{ */
1497 : ";" { $$ = CYNew CYEmpty(); }
1500 /* 13.5 Expression Statement {{{ */
1501 ExpressionStatement_
1502 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1505 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1508 /* 13.6 The if Statement {{{ */
1510 : "else" Statement[false] { $$ = $false; }
1511 | %prec "if" { $$ = NULL; }
1515 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1518 /* 13.7 Iteration Statements {{{ */
1520 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1521 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1522 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1523 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1524 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1525 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1528 ForStatementInitializer
1529 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1530 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1531 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1532 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1535 ForInStatementInitializer
1536 : LexLet LexOf AccessExpression[pass] LexCrement { $$ = $pass; }
1537 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1538 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1539 | ForDeclaration[pass] { $$ = $pass; }
1543 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1547 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1548 | LexOf BindingPattern { CYNOT(@$); }
1551 /* 13.8 The continue Statement {{{ */
1553 : "continue" LexNewLine
1557 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1558 | Continue Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1561 /* 13.9 The break Statement {{{ */
1563 : "break" LexNewLine
1567 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1568 | Break Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1571 /* 13.10 The return Statement {{{ */
1573 : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); } LexNewLine
1577 : Return LexOf TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1578 | Return Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1581 /* 13.11 The with Statement {{{ */
1583 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1586 /* 13.12 The switch Statement {{{ */
1588 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1592 : BRACE CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1596 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1600 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1601 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1605 // XXX: the standard makes certain you can only have one of these
1607 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1610 /* 13.13 Labelled Statements {{{ */
1612 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1616 : Statement[pass] { $$ = $pass; }
1617 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1620 /* 13.14 The throw Statement {{{ */
1622 : "throw" LexNewLine
1626 : Throw[throw] LexOf TerminatorSoft { CYERR(@throw, "throw without exception"); }
1627 | Throw Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1630 /* 13.15 The try Statement {{{ */
1632 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1633 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1634 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1638 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1642 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1646 : BindingIdentifier[pass] { $$ = $pass; }
1647 | LexOf BindingPattern { CYNOT(@$); }
1650 /* 13.16 The debugger Statement {{{ */
1652 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1656 /* 14.1 Function Definitions {{{ */
1658 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1662 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1665 StrictFormalParameters
1666 : FormalParameters[pass] { $$ = $pass; }
1670 : LexBind LexOf { $$ = NULL; }
1671 | FormalParameterList
1674 FormalParameterList_
1675 : "," FormalParameterList[parameters] { $$ = $parameters; }
1680 : LexBind LexOf FunctionRestParameter { CYNOT(@$); }
1681 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1684 FunctionRestParameter
1685 : BindingRestElement
1689 : BindingElement[pass] { $$ = $pass; }
1693 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1696 FunctionStatementList
1697 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1700 /* 14.2 Arrow Function Definitions {{{ */
1702 : { CYLIN(EqualRight); }
1706 : ArrowParameters[parameters] LexEqualRight "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1710 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1711 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1715 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1716 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1719 /* 14.3 Method Definitions {{{ */
1721 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1722 | GeneratorMethod[pass] { $$ = $pass; }
1723 | "get" PropertyName[name] "(" ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1724 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1727 PropertySetParameterList
1728 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1731 /* 14.4 Generator Function Definitions {{{ */
1733 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1736 GeneratorDeclaration
1737 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1741 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1745 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1749 : "!yield" LexNewLine LexNoStar
1753 : Yield LexOf NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1754 | Yield AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1755 | Yield LexOf YieldStar AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1758 /* 14.5 Class Definitions {{{ */
1760 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1764 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1768 : ClassHeritageOpt[tail] { driver.class_.push($tail); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1772 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1776 : ClassHeritage[pass] { $$ = $pass; }
1777 | { $$ = CYNew CYClassTail(NULL); }
1790 : ClassElementListOpt ClassElement
1799 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1800 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1805 /* 15.1 Scripts {{{ */
1807 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1811 : StatementList[pass] { $$ = $pass; }
1815 : ScriptBody[pass] { $$ = $pass; }
1816 | LexSetStatement LexLet LexOf { $$ = NULL; }
1819 /* 15.2 Modules {{{ */
1834 : ModuleItemListOpt ModuleItem
1843 : LexSetStatement LexLet LexOf ImportDeclaration
1844 | LexSetStatement LexLet LexOf ExportDeclaration
1848 /* 15.2.2 Imports {{{ */
1850 : "import" ImportClause FromClause Terminator
1851 | "import" LexOf ModuleSpecifier Terminator
1855 : ImportedDefaultBinding
1856 | LexOf NameSpaceImport
1857 | LexOf NamedImports
1858 | ImportedDefaultBinding "," NameSpaceImport
1859 | ImportedDefaultBinding "," NamedImports
1862 ImportedDefaultBinding
1867 : "*" "as" ImportedBinding
1871 : BRACE ImportsListOpt "}"
1875 : "from" ModuleSpecifier
1879 : "," ImportsListOpt
1884 : ImportSpecifier ImportsList_
1894 | LexOf IdentifierName "as" ImportedBinding
1905 /* 15.2.3 Exports {{{ */
1907 : "*" FromClause Terminator
1908 | ExportClause FromClause Terminator
1909 | ExportClause Terminator
1911 | "default" LexSetStatement LexOf HoistableDeclaration
1912 | "default" LexSetStatement LexOf ClassDeclaration
1913 | "default" LexSetStatement AssignmentExpression Terminator
1917 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1918 | "export" Declaration
1922 : ";{" ExportsListOpt "}"
1926 : "," ExportsListOpt
1931 : ExportSpecifier ExportsList_
1941 | IdentifierName "as" IdentifierName
1946 /* Cycript (C): Type Encoding {{{ */
1948 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1949 | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; }
1953 : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1954 | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1955 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1956 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1957 | TypeSignifier[pass] { $$ = $pass; }
1958 | { $$ = CYNew CYTypedIdentifier(@$); }
1962 : "*" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1967 | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1968 | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1972 : PrefixedType[pass] { $$ = $pass; }
1973 | SuffixedType[pass] { $$ = $pass; }
1974 | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1975 | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1979 : "int" { $$ = CYNew CYTypeVariable("int"); }
1980 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
1981 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
1982 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
1983 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
1987 : IntegerType[pass] { $$ = $pass; }
1988 | { $$ = CYNew CYTypeVariable("int"); }
1992 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
1993 | IntegerType[pass] { $$ = $pass; }
1994 | "void" { $$ = CYNew CYTypeVoid(); }
1995 | "char" { $$ = CYNew CYTypeVariable("char"); }
1996 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1997 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2001 : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2005 : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2011 /* Cycript (Objective-C): @class Declaration {{{ */
2013 /* XXX: why the hell did I choose MemberExpression? */
2014 : ":" MemberExpression[extends] { $$ = $extends; }
2018 ImplementationFieldListOpt
2019 : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2023 ImplementationFields
2024 : BRACE ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
2028 : "+" { $$ = false; }
2029 | "-" { $$ = true; }
2033 : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
2034 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2038 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2041 MessageParameterList
2042 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2045 MessageParameterListOpt
2046 : MessageParameterList[pass] { $$ = $pass; }
2051 : MessageParameterList[pass] { $$ = $pass; }
2052 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2055 ClassMessageDeclaration
2056 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] BRACE LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2059 ClassMessageDeclarationListOpt
2060 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2064 // XXX: this should be AssignmentExpressionNoRight
2066 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2070 : "," ClassProtocols[protocols] { $$ = $protocols; }
2074 ClassProtocolListOpt
2075 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2079 ImplementationStatement
2080 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2088 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2092 : ImplementationStatement[pass] { $$ = $pass; }
2093 | CategoryStatement[pass] { $$ = $pass; }
2096 /* Cycript (Objective-C): Send Message {{{ */
2098 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2103 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2104 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2108 : SelectorCall[pass] { $$ = $pass; }
2109 | VariadicCall[pass] { $$ = $pass; }
2113 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2117 : SelectorCall[pass] { $$ = $pass; }
2118 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2122 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2123 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2127 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2131 : SelectorExpression_[pass] { $$ = $pass; }
2132 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2135 SelectorExpressionOpt
2136 : SelectorExpression_[pass] { $$ = $pass; }
2141 : MessageExpression[pass] { $$ = $pass; }
2142 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2147 /* Cycript: @import Directive {{{ */
2149 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2150 | Word[part] { $$ = CYNew CYModule($part); }
2154 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2159 /* Cycript (Objective-C): Boxed Expressions {{{ */
2161 : NullLiteral[pass] { $$ = $pass; }
2162 | BooleanLiteral[pass] { $$ = $pass; }
2163 | NumericLiteral[pass] { $$ = $pass; }
2164 | StringLiteral[pass] { $$ = $pass; }
2165 | ArrayLiteral[pass] { $$ = $pass; }
2166 | ObjectLiteral[pass] { $$ = $pass; }
2167 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2168 | "YES" { $$ = CYNew CYTrue(); }
2169 | "NO" { $$ = CYNew CYFalse(); }
2173 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2174 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2175 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2176 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2177 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2178 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2181 /* Cycript (Objective-C): Block Expressions {{{ */
2183 : "^" TypedIdentifier[type] { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); } BRACE FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2186 /* Cycript (Objective-C): Instance Literals {{{ */
2188 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2194 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2196 : IndirectExpression[pass] { $$ = $pass; }
2200 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2204 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2208 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2209 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2210 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2213 /* Cycript (C): auto Compatibility {{{ */
2218 /* Cycript (C): Lambda Expressions {{{ */
2220 : "," TypedParameterList[parameters] { $$ = $parameters; }
2225 : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2228 TypedParameterListOpt
2229 : TypedParameterList[pass] { $$ = $pass; }
2234 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] BRACE FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2237 /* Cycript (C): Type Definitions {{{ */
2239 : "typedef" TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
2242 /* Cycript (C): extern "C" {{{ */
2244 : "extern" StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($abi, $typed); }
2251 /* Lexer State {{{ */
2253 : { driver.PushCondition(CYDriver::RegExpCondition); }
2257 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2261 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2265 : { driver.PopCondition(); }
2269 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2273 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2276 /* Virtual Tokens {{{ */
2283 /* 8.1 Context Keywords {{{ */
2285 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2286 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2289 /* 8.3 XML Initializer Input Elements {{{ */
2291 : XMLComment { $$ = $1; }
2292 | XMLCDATA { $$ = $1; }
2293 | XMLPI { $$ = $1; }
2297 /* 11.1 Primary Expressions {{{ */
2299 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2300 | XMLInitilizer { $$ = $1; }
2301 | XMLListInitilizer { $$ = $1; }
2305 : AttributeIdentifier { $$ = $1; }
2306 | QualifiedIdentifier { $$ = $1; }
2307 | WildcardIdentifier { $$ = $1; }
2310 /* 11.1.1 Attribute Identifiers {{{ */
2312 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2316 : PropertySelector { $$ = $1; }
2317 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2321 : Identifier { $$ = CYNew CYSelector($1); }
2322 | WildcardIdentifier { $$ = $1; }
2325 /* 11.1.2 Qualified Identifiers {{{ */
2326 QualifiedIdentifier_
2327 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2328 | QualifiedIdentifier { $$ = $1; }
2332 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2335 /* 11.1.3 Wildcard Identifiers {{{ */
2337 : "*" { $$ = CYNew CYWildcard(); }
2340 /* 11.1.4 XML Initializer {{{ */
2342 : XMLMarkup { $$ = $1; }
2343 | XMLElement { $$ = $1; }
2347 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2348 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2352 : LexPushXMLTag XMLTagName XMLAttributes
2356 : BRACE LexPushRegExp Expression LexPop "}"
2365 : XMLAttributes_ XMLAttribute
2370 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2371 | XMLAttributes_ XMLWhitespaceOpt
2380 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2384 : XMLExpression XMLElementContentOpt
2385 | XMLMarkup XMLElementContentOpt
2386 | XMLText XMLElementContentOpt
2387 | XMLElement XMLElementContentOpt
2390 XMLElementContentOpt
2395 /* 11.1.5 XMLList Initializer {{{ */
2397 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2401 /* 11.2 Left-Hand-Side Expressions {{{ */
2403 : Identifier { $$ = $1; }
2404 | PropertyIdentifier { $$ = $1; }
2408 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2409 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2410 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2413 /* 12.1 The default xml namespace Statement {{{ */
2414 /* XXX: DefaultXMLNamespaceStatement
2415 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2419 : DefaultXMLNamespaceStatement { $$ = $1; }
2424 /* JavaScript FTL: Array Comprehensions {{{ */
2426 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2430 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2433 /* JavaScript FTL: for each {{{ */
2435 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2439 /* JavaScript FTW: Array Comprehensions {{{ */
2441 : ArrayComprehension
2445 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2449 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2454 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2455 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2459 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2460 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2464 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2467 /* JavaScript FTW: Coalesce Operator {{{ */
2468 ConditionalExpression
2469 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2472 /* JavaScript FTW: Named Arguments {{{ */
2474 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2477 /* JavaScript FTW: Ruby Blocks {{{ */
2478 RubyProcParameterList_
2479 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2483 RubyProcParameterList
2484 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2485 | LexOf { $$ = NULL; }
2489 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2490 | "||" { $$ = NULL; }
2493 RubyProcParametersOpt
2494 : RubyProcParameters[pass] { $$ = $pass; }
2499 : { CYLIN(OpenBrace); }
2503 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2507 : BRACE RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2511 : PostfixExpression[lhs] LexOpenBrace RubyProcExpression[rhs] { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2517 bool CYDriver::Parse(CYMark mark) {
2519 CYLocal<CYPool> local(&pool_);
2520 cy::parser parser(*this);
2522 parser.set_debug_level(debug_);
2524 return parser.parse() != 0;
2527 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2531 CYDriver::Error error;
2532 error.warning_ = true;
2533 error.location_ = location;
2534 error.message_ = message;
2535 errors_.push_back(error);
2538 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2539 CYDriver::Error error;
2540 error.warning_ = false;
2541 error.location_ = location;
2542 error.message_ = message;
2543 driver.errors_.push_back(error);