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 { CYTypeStructField *structField_; }
84 %union { CYTypeModifier *modifier_; }
85 %union { CYTypeSpecifier *specifier_; }
86 %union { CYTypedIdentifier *typedIdentifier_; }
87 %union { CYTypedParameter *typedParameter_; }
91 %union { CYImplementationField *implementationField_; }
92 %union { CYMessage *message_; }
93 %union { CYMessageParameter *messageParameter_; }
94 %union { CYProtocol *protocol_; }
95 %union { CYSelectorPart *selector_; }
99 %union { CYAttribute *attribute_; }
100 %union { CYPropertyIdentifier *propertyIdentifier_; }
101 %union { CYSelector *selector_; }
107 cy::parser::semantic_type semantic_;
108 hi::Value highlight_;
111 int cylex(YYSTYPE *, CYLocation *, void *);
119 typedef cy::parser::token tk;
121 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
122 driver.newline_ = false;
125 int token(cylex(&data, location, driver.scanner_));
126 *semantic = data.semantic_;
130 case tk::OpenBracket:
132 driver.in_.push(false);
136 if (driver.in_.top())
141 case tk::CloseBracket:
148 if (driver.yield_.top())
149 token = tk::_yield__;
153 driver.newline_ = true;
161 #define yylex_(semantic, location, driver) ({ \
163 if (driver.hold_ == cy::parser::empty_symbol) \
164 type = yytranslate_(cylex_(semantic, location, driver)); \
166 type = driver.hold_; \
167 driver.hold_ = cy::parser::empty_symbol; \
171 #define CYLEX() do if (yyla.empty()) { \
172 YYCDEBUG << "Mapping a token: "; \
173 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
174 YY_SYMBOL_PRINT("Next token is", yyla); \
177 #define CYMAP(to, from) do { \
179 if (yyla.type == yytranslate_(token::from)) \
180 yyla.type = yytranslate_(token::to); \
183 #define CYERR(location, message) do { \
184 error(location, message); \
188 #define CYEOK() do { \
190 driver.errors_.pop_back(); \
193 #define CYNOT(location) \
194 CYERR(location, "unimplemented feature")
196 #define CYMPT(location) do { \
197 if (!yyla.empty() && yyla.type_get() != yyeof_) \
198 CYERR(location, "unexpected lookahead"); \
208 @$.begin.filename = @$.end.filename = &driver.filename_;
210 switch (driver.mark_) {
212 driver.hold_ = yytranslate_(token::MarkScript);
215 driver.hold_ = yytranslate_(token::MarkModule);
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 Exclamation "!"
271 %token ExclamationEqual "!="
272 %token ExclamationEqualEqual "!=="
274 %token HyphenEqual "-="
275 %token HyphenHyphen "--"
276 %token HyphenRight "->"
278 %token LeftEqual "<="
280 %token LeftLeftEqual "<<="
282 %token PercentEqual "%="
284 %token PeriodPeriodPeriod "..."
286 %token PipeEqual "|="
289 %token PlusEqual "+="
292 %token RightEqual ">="
293 %token RightRight ">>"
294 %token RightRightEqual ">>="
295 %token RightRightRight ">>>"
296 %token RightRightRightEqual ">>>="
298 %token SlashEqual "/="
300 %token StarEqual "*="
313 %token CloseParen ")"
316 %token OpenBrace_ ";{"
317 %token OpenBrace_let "let {"
318 %token CloseBrace "}"
320 %token OpenBracket "["
321 %token OpenBracket_let "let ["
322 %token CloseBracket "]"
324 %token At_error_ "@error"
327 %token At_class_ "@class"
331 %token _typedef_ "typedef"
332 %token _unsigned_ "unsigned"
333 %token _signed_ "signed"
334 %token _struct_ "struct"
335 %token _extern_ "extern"
339 %token At_encode_ "@encode"
343 %token At_implementation_ "@implementation"
344 %token At_import_ "@import"
345 %token At_end_ "@end"
346 %token At_selector_ "@selector"
347 %token At_null_ "@null"
348 %token At_YES_ "@YES"
350 %token At_true_ "@true"
351 %token At_false_ "@false"
356 %token _false_ "false"
360 %token _break_ "break"
362 %token _catch_ "catch"
363 %token _class_ "class"
364 %token _class__ ";class"
365 %token _const_ "const"
366 %token _continue_ "continue"
367 %token _debugger_ "debugger"
368 %token _default_ "default"
369 %token _delete_ "delete"
373 %token _export_ "export"
374 %token _extends_ "extends"
375 %token _finally_ "finally"
377 %token _function_ "function"
378 %token _function__ ";function"
380 %token _import_ "import"
383 %token _Infinity_ "Infinity"
384 %token _instanceof_ "instanceof"
386 %token _return_ "return"
387 %token _super_ "super"
388 %token _switch_ "switch"
389 %token _target_ "target"
391 %token _throw_ "throw"
393 %token _typeof_ "typeof"
396 %token _while_ "while"
399 %token _abstract_ "abstract"
400 %token _await_ "await"
401 %token _boolean_ "boolean"
404 %token _constructor_ "constructor"
405 %token _double_ "double"
407 %token _final_ "final"
408 %token _float_ "float"
412 %token _implements_ "implements"
414 %token _interface_ "interface"
418 %token _native_ "native"
419 %token _package_ "package"
420 %token _private_ "private"
421 %token _protected_ "protected"
422 %token ___proto___ "__proto__"
423 %token _prototype_ "prototype"
424 %token _public_ "public"
426 %token _short_ "short"
427 %token _static_ "static"
428 %token _synchronized_ "synchronized"
429 %token _throws_ "throws"
430 %token _transient_ "transient"
431 %token _volatile_ "volatile"
432 %token _yield_ "yield"
433 %token _yield__ "!yield"
435 %token _undefined_ "undefined"
451 %token _namespace_ "namespace"
456 %token YieldStar "yield *"
458 %token <identifier_> Identifier_
459 %token <number_> NumericLiteral
460 %token <string_> StringLiteral
461 %token <literal_> RegularExpressionLiteral_
463 %token <string_> NoSubstitutionTemplate
464 %token <string_> TemplateHead
465 %token <string_> TemplateMiddle
466 %token <string_> TemplateTail
468 %type <target_> AccessExpression
469 %type <expression_> AdditiveExpression
470 %type <argument_> ArgumentList_
471 %type <argument_> ArgumentList
472 %type <argument_> ArgumentListOpt
473 %type <argument_> Arguments
474 %type <target_> ArrayComprehension
475 %type <literal_> ArrayLiteral
476 %type <expression_> ArrowFunction
477 %type <functionParameter_> ArrowParameters
478 %type <expression_> AssignmentExpression
479 %type <expression_> AssignmentExpressionOpt
480 %type <identifier_> BindingIdentifier
481 %type <identifier_> BindingIdentifierOpt
482 %type <bindings_> BindingList_
483 %type <bindings_> BindingList
484 %type <expression_> BitwiseANDExpression
485 %type <statement_> Block
486 %type <statement_> BlockStatement
487 %type <boolean_> BooleanLiteral
488 %type <binding_> BindingElement
489 %type <expression_> BitwiseORExpression
490 %type <expression_> BitwiseXORExpression
491 %type <statement_> BreakStatement
492 %type <statement_> BreakableStatement
493 %type <expression_> CallExpression_
494 %type <target_> CallExpression
495 %type <clause_> CaseBlock
496 %type <clause_> CaseClause
497 %type <clause_> CaseClausesOpt
499 %type <identifier_> CatchParameter
500 %type <statement_> ClassDeclaration
501 %type <target_> ClassExpression
502 %type <classTail_> ClassHeritage
503 %type <classTail_> ClassHeritageOpt
504 %type <classTail_> ClassTail
505 %type <target_> Comprehension
506 %type <comprehension_> ComprehensionFor
507 %type <comprehension_> ComprehensionIf
508 %type <comprehension_> ComprehensionTail
509 %type <propertyName_> ComputedPropertyName
510 %type <expression_> ConditionalExpression
511 %type <statement_> ContinueStatement
512 %type <statement_> ConciseBody
513 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
514 %type <statement_> DebuggerStatement
515 %type <statement_> Declaration_
516 %type <statement_> Declaration
517 %type <clause_> DefaultClause
518 %type <element_> ElementList
519 %type <element_> ElementListOpt
520 %type <statement_> ElseStatementOpt
521 %type <for_> EmptyStatement
522 %type <expression_> EqualityExpression
523 %type <expression_> Expression
524 %type <expression_> ExpressionOpt
525 %type <for_> ExpressionStatement_
526 %type <statement_> ExpressionStatement
527 %type <statement_> ExternC
528 %type <statement_> ExternCStatement
529 %type <statement_> ExternCStatementListOpt
530 %type <finally_> Finally
531 %type <binding_> ForBinding
532 %type <forin_> ForDeclaration
533 %type <forin_> ForInStatementInitializer
534 %type <for_> ForStatementInitializer
535 %type <binding_> FormalParameter
536 %type <functionParameter_> FormalParameterList_
537 %type <functionParameter_> FormalParameterList
538 %type <functionParameter_> FormalParameters
539 %type <statement_> FunctionBody
540 %type <statement_> FunctionDeclaration
541 %type <target_> FunctionExpression
542 %type <statement_> FunctionStatementList
543 %type <statement_> GeneratorBody
544 %type <statement_> GeneratorDeclaration
545 %type <target_> GeneratorExpression
546 %type <method_> GeneratorMethod
547 %type <statement_> HoistableDeclaration
548 %type <identifier_> Identifier
549 %type <identifier_> IdentifierNoOf
550 %type <identifier_> IdentifierType
551 %type <identifier_> IdentifierTypeNoOf
552 %type <identifier_> IdentifierTypeOpt
553 %type <word_> IdentifierName
554 %type <variable_> IdentifierReference
555 %type <statement_> IfStatement
556 %type <target_> IndirectExpression
557 %type <expression_> Initializer
558 %type <expression_> InitializerOpt
559 %type <statement_> IterationStatement
560 %type <identifier_> LabelIdentifier
561 %type <statement_> LabelledItem
562 %type <statement_> LabelledStatement
563 %type <assignment_> LeftHandSideAssignment
564 %type <target_> LeftHandSideExpression
565 %type <bool_> LetOrConst
566 %type <binding_> LexicalBinding
567 %type <for_> LexicalDeclaration_
568 %type <statement_> LexicalDeclaration
569 %type <literal_> Literal
570 %type <propertyName_> LiteralPropertyName
571 %type <expression_> LogicalANDExpression
572 %type <expression_> LogicalORExpression
573 %type <access_> MemberAccess
574 %type <target_> MemberExpression
575 %type <method_> MethodDefinition
576 %type <module_> ModulePath
577 %type <expression_> MultiplicativeExpression
578 %type <target_> NewExpression
579 %type <null_> NullLiteral
580 %type <literal_> ObjectLiteral
581 %type <expression_> PostfixExpression
582 %type <target_> PrimaryExpression
583 %type <propertyName_> PropertyName
584 %type <property_> PropertyDefinition
585 %type <property_> PropertyDefinitionList_
586 %type <property_> PropertyDefinitionList
587 %type <property_> PropertyDefinitionListOpt
588 %type <functionParameter_> PropertySetParameterList
589 %type <literal_> RegularExpressionLiteral
590 %type <bool_> RegularExpressionSlash
591 %type <expression_> RelationalExpression
592 %type <statement_> ReturnStatement
593 %type <target_> RubyBlockExpression_
594 %type <target_> RubyBlockExpression
595 %type <rubyProc_> RubyProcExpression
596 %type <functionParameter_> RubyProcParameterList_
597 %type <functionParameter_> RubyProcParameterList
598 %type <functionParameter_> RubyProcParameters
599 %type <functionParameter_> RubyProcParametersOpt
600 %type <statement_> Script
601 %type <statement_> ScriptBody
602 %type <statement_> ScriptBodyOpt
603 %type <expression_> ShiftExpression
604 %type <binding_> SingleNameBinding
605 %type <statement_> Statement__
606 %type <statement_> Statement_
607 %type <statement_> Statement
608 %type <statement_> StatementList
609 %type <statement_> StatementListOpt
610 %type <statement_> StatementListItem
611 %type <functionParameter_> StrictFormalParameters
612 %type <target_> SuperCall
613 %type <target_> SuperProperty
614 %type <statement_> SwitchStatement
615 %type <target_> TemplateLiteral
616 %type <span_> TemplateSpans
617 %type <statement_> ThrowStatement
618 %type <statement_> TryStatement
619 %type <statement_> TypeDefinition
620 %type <expression_> UnaryExpression_
621 %type <expression_> UnaryExpression
622 %type <binding_> VariableDeclaration
623 %type <bindings_> VariableDeclarationList_
624 %type <bindings_> VariableDeclarationList
625 %type <for_> VariableStatement_
626 %type <statement_> VariableStatement
627 %type <statement_> WithStatement
630 %type <word_> WordOpt
632 %type <expression_> YieldExpression
635 %type <specifier_> IntegerType
636 %type <specifier_> IntegerTypeOpt
637 %type <typedIdentifier_> PrefixedType
638 %type <specifier_> PrimitiveType
639 %type <structField_> StructFieldListOpt
640 %type <typedIdentifier_> SuffixedType
641 %type <typedIdentifier_> SuffixedTypeOpt
642 %type <typedIdentifier_> TypeSignifier
643 %type <typedIdentifier_> TypeSignifierOpt
644 %type <modifier_> TypeQualifierLeft
645 %type <modifier_> TypeQualifierLeftOpt
646 %type <typedIdentifier_> TypeQualifierRight
647 %type <typedIdentifier_> TypeQualifierRightOpt
648 %type <typedIdentifier_> TypedIdentifierMaybe
649 %type <typedIdentifier_> TypedIdentifierNo
650 %type <typedIdentifier_> TypedIdentifierYes
651 %type <typedParameter_> TypedParameterList_
652 %type <typedParameter_> TypedParameterList
653 %type <typedParameter_> TypedParameterListOpt
657 %type <expression_> AssignmentExpressionClassic
658 %type <expression_> BoxableExpression
659 %type <statement_> CategoryStatement
660 %type <expression_> ClassSuperOpt
661 %type <expression_> ConditionalExpressionClassic
662 %type <message_> ClassMessageDeclaration
663 %type <message_> ClassMessageDeclarationListOpt
664 %type <protocol_> ClassProtocolListOpt
665 %type <protocol_> ClassProtocols
666 %type <protocol_> ClassProtocolsOpt
667 %type <implementationField_> ImplementationFieldListOpt
668 %type <statement_> ImplementationStatement
669 %type <target_> MessageExpression
670 %type <messageParameter_> MessageParameter
671 %type <messageParameter_> MessageParameters
672 %type <messageParameter_> MessageParameterList
673 %type <messageParameter_> MessageParameterListOpt
674 %type <bool_> MessageScope
675 %type <argument_> SelectorCall_
676 %type <argument_> SelectorCall
677 %type <selector_> SelectorExpression_
678 %type <selector_> SelectorExpression
679 %type <selector_> SelectorExpressionOpt
680 %type <argument_> SelectorList
681 %type <word_> SelectorWordOpt
682 %type <typedIdentifier_> TypeOpt
683 %type <argument_> VariadicCall
687 %type <propertyIdentifier_> PropertyIdentifier_
688 %type <selector_> PropertySelector_
689 %type <selector_> PropertySelector
690 %type <identifier_> QualifiedIdentifier_
691 %type <identifier_> QualifiedIdentifier
692 %type <identifier_> WildcardIdentifier
693 %type <identifier_> XMLComment
694 %type <identifier_> XMLCDATA
695 %type <identifier_> XMLElement
696 %type <identifier_> XMLElementContent
697 %type <identifier_> XMLMarkup
698 %type <identifier_> XMLPI
700 %type <attribute_> AttributeIdentifier
701 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
702 %type <expression_> PropertyIdentifier
703 %type <expression_> XMLListInitilizer
704 %type <expression_> XMLInitilizer
707 /* Token Priorities {{{ */
723 /* Lexer State {{{ */
724 LexPushInOn: { driver.in_.push(true); };
725 LexPushInOff: { driver.in_.push(false); };
726 LexPopIn: { driver.in_.pop(); };
728 LexPushReturnOn: { driver.return_.push(true); };
729 LexPopReturn: { driver.return_.pop(); };
730 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
732 LexPushSuperOn: { driver.super_.push(true); };
733 LexPushSuperOff: { driver.super_.push(false); };
734 LexPopSuper: { driver.super_.pop(); };
735 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
737 LexPushYieldOn: { driver.yield_.push(true); };
738 LexPushYieldOff: { driver.yield_.push(false); };
739 LexPopYield: { driver.yield_.pop(); };
742 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
746 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
750 : { CYMAP(YieldStar, Star); }
754 : { CYMAP(OpenBrace_, OpenBrace); }
758 : { CYMAP(_class__, _class_); }
762 : { CYMAP(_function__, _function_); }
766 : LexNoBrace LexNoClass LexNoFunction
769 /* Virtual Tokens {{{ */
775 /* 11.6 Names and Keywords {{{ */
777 : Word[pass] { $$ = $pass; }
778 | "for" { $$ = CYNew CYWord("for"); }
779 | "in" { $$ = CYNew CYWord("in"); }
780 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
784 : IdentifierNoOf[pass] { $$ = $pass; }
785 | "break" { $$ = CYNew CYWord("break"); }
786 | "case" { $$ = CYNew CYWord("case"); }
787 | "catch" { $$ = CYNew CYWord("catch"); }
788 | "class" LexOf { $$ = CYNew CYWord("class"); }
789 | ";class" { $$ = CYNew CYWord("class"); }
790 | "const" { $$ = CYNew CYWord("const"); }
791 | "continue" { $$ = CYNew CYWord("continue"); }
792 | "debugger" { $$ = CYNew CYWord("debugger"); }
793 | "default" { $$ = CYNew CYWord("default"); }
794 | "delete" { $$ = CYNew CYWord("delete"); }
795 | "do" { $$ = CYNew CYWord("do"); }
796 | "else" { $$ = CYNew CYWord("else"); }
797 | "enum" { $$ = CYNew CYWord("enum"); }
798 | "export" { $$ = CYNew CYWord("export"); }
799 | "extends" { $$ = CYNew CYWord("extends"); }
800 | "false" { $$ = CYNew CYWord("false"); }
801 | "finally" { $$ = CYNew CYWord("finally"); }
802 | "function" LexOf { $$ = CYNew CYWord("function"); }
803 | "if" { $$ = CYNew CYWord("if"); }
804 | "import" { $$ = CYNew CYWord("import"); }
805 | "!in" { $$ = CYNew CYWord("in"); }
806 | "!of" { $$ = CYNew CYWord("of"); }
807 | "new" { $$ = CYNew CYWord("new"); }
808 | "null" { $$ = CYNew CYWord("null"); }
809 | "return" { $$ = CYNew CYWord("return"); }
810 | "super" { $$ = CYNew CYWord("super"); }
811 | "switch" { $$ = CYNew CYWord("switch"); }
812 | "this" { $$ = CYNew CYWord("this"); }
813 | "throw" { $$ = CYNew CYWord("throw"); }
814 | "true" { $$ = CYNew CYWord("true"); }
815 | "try" { $$ = CYNew CYWord("try"); }
816 | "typeof" { $$ = CYNew CYWord("typeof"); }
817 | "var" { $$ = CYNew CYWord("var"); }
818 | "void" { $$ = CYNew CYWord("void"); }
819 | "while" { $$ = CYNew CYWord("while"); }
820 | "with" { $$ = CYNew CYWord("with"); }
821 | "yield" { $$ = CYNew CYIdentifier("yield"); }
826 : Word[pass] { $$ = $pass; }
831 /* 11.8.1 Null Literals {{{ */
833 : "null" { $$ = CYNew CYNull(); }
836 /* 11.8.2 Boolean Literals {{{ */
838 : "true" { $$ = CYNew CYTrue(); }
839 | "false" { $$ = CYNew CYFalse(); }
842 /* 11.8.5 Regular Expression Literals {{{ */
843 RegularExpressionSlash
844 : "/" { $$ = false; }
845 | "/=" { $$ = true; }
848 RegularExpressionLiteral
849 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
853 /* 11.9 Automatic Semicolon Insertion {{{ */
855 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
863 : LexNewLineOrNot "\n"
868 : LexNewLineOrNot "\n" StrictSemi
869 | NewLineNot LexOf Terminator
874 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
879 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
884 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
888 /* 12.1 Identifiers {{{ */
890 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
891 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
895 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
896 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
897 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
901 : BindingIdentifier[pass] { $$ = $pass; }
902 | LexOf { $$ = NULL; }
906 : Identifier[pass] { $$ = $pass; }
907 | "yield" { $$ = CYNew CYIdentifier("yield"); }
911 : Identifier_[pass] { $$ = $pass; }
912 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
913 | "await" { $$ = CYNew CYIdentifier("await"); }
914 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
915 | "byte" { $$ = CYNew CYIdentifier("byte"); }
916 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
917 | "double" { $$ = CYNew CYIdentifier("double"); }
918 | "each" { $$ = CYNew CYIdentifier("each"); }
919 | "eval" { $$ = CYNew CYIdentifier("eval"); }
920 | "final" { $$ = CYNew CYIdentifier("final"); }
921 | "float" { $$ = CYNew CYIdentifier("float"); }
922 | "from" { $$ = CYNew CYIdentifier("from"); }
923 | "get" { $$ = CYNew CYIdentifier("get"); }
924 | "goto" { $$ = CYNew CYIdentifier("goto"); }
925 | "implements" { $$ = CYNew CYIdentifier("implements"); }
926 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
927 | "interface" { $$ = CYNew CYIdentifier("interface"); }
928 | "let" { $$ = CYNew CYIdentifier("let"); }
929 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
930 | "native" { $$ = CYNew CYIdentifier("native"); }
931 | "package" { $$ = CYNew CYIdentifier("package"); }
932 | "private" { $$ = CYNew CYIdentifier("private"); }
933 | "protected" { $$ = CYNew CYIdentifier("protected"); }
934 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
935 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
936 | "public" { $$ = CYNew CYIdentifier("public"); }
937 | "set" { $$ = CYNew CYIdentifier("set"); }
938 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
939 | "target" { $$ = CYNew CYIdentifier("target"); }
940 | "throws" { $$ = CYNew CYIdentifier("throws"); }
941 | "transient" { $$ = CYNew CYIdentifier("transient"); }
942 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
944 | "bool" { $$ = CYNew CYIdentifier("bool"); }
945 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
946 | "id" { $$ = CYNew CYIdentifier("id"); }
947 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
952 : IdentifierTypeNoOf[pass] { $$ = $pass; }
953 | "of" { $$ = CYNew CYIdentifier("of"); }
957 : IdentifierType[pass] { $$ = $pass; }
963 | "char" { $$ = CYNew CYIdentifier("char"); }
964 | "int" { $$ = CYNew CYIdentifier("int"); }
965 | "long" { $$ = CYNew CYIdentifier("long"); }
966 | "short" { $$ = CYNew CYIdentifier("short"); }
967 | "static" { $$ = CYNew CYIdentifier("static"); }
968 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
970 | "signed" { $$ = CYNew CYIdentifier("signed"); }
971 | "struct" { $$ = CYNew CYIdentifier("struct"); }
972 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
975 | "nil" { $$ = CYNew CYIdentifier("nil"); }
976 | "NO" { $$ = CYNew CYIdentifier("NO"); }
977 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
978 | "YES" { $$ = CYNew CYIdentifier("YES"); }
983 : IdentifierNoOf[pass] { $$ = $pass; }
984 | "of" { $$ = CYNew CYIdentifier("of"); }
985 | "!of" { $$ = CYNew CYIdentifier("of"); }
988 /* 12.2 Primary Expression {{{ */
990 : "this" { $$ = CYNew CYThis(); }
991 | IdentifierReference[pass] { $$ = $pass; }
992 | Literal[pass] { $$ = $pass; }
993 | ArrayLiteral[pass] { $$ = $pass; }
994 | ObjectLiteral[pass] { $$ = $pass; }
995 | FunctionExpression[pass] { $$ = $pass; }
996 | ClassExpression[pass] { $$ = $pass; }
997 | GeneratorExpression[pass] { $$ = $pass; }
998 | RegularExpressionLiteral[pass] { $$ = $pass; }
999 | TemplateLiteral[pass] { $$ = $pass; }
1000 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1001 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1004 CoverParenthesizedExpressionAndArrowParameterList
1005 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1006 | "(" LexOf ")" { $$ = NULL; }
1007 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1008 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1011 /* 12.2.4 Literals {{{ */
1013 : NullLiteral[pass] { $$ = $pass; }
1014 | BooleanLiteral[pass] { $$ = $pass; }
1015 | NumericLiteral[pass] { $$ = $pass; }
1016 | StringLiteral[pass] { $$ = $pass; }
1019 /* 12.2.5 Array Initializer {{{ */
1021 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1025 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1026 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1027 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1031 : ElementList[pass] { $$ = $pass; }
1032 | LexOf { $$ = NULL; }
1035 /* 12.2.6 Object Initializer {{{ */
1037 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1040 PropertyDefinitionList_
1041 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1045 PropertyDefinitionList
1046 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1049 PropertyDefinitionListOpt
1050 : PropertyDefinitionList[properties] { $$ = $properties; }
1055 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1056 | CoverInitializedName[name] { CYNOT(@$); }
1057 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1058 | MethodDefinition[pass] { $$ = $pass; }
1062 : LiteralPropertyName[pass] { $$ = $pass; }
1063 | ComputedPropertyName[pass] { $$ = $pass; }
1067 : IdentifierName[pass] { $$ = $pass; }
1068 | StringLiteral[pass] { $$ = $pass; }
1069 | NumericLiteral[pass] { $$ = $pass; }
1072 ComputedPropertyName
1073 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1076 CoverInitializedName
1077 : IdentifierReference Initializer
1081 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1085 : Initializer[pass] { $$ = $pass; }
1089 /* 12.2.9 Template Literals {{{ */
1091 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1092 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1096 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1097 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1101 /* 12.3 Left-Hand-Side Expressions {{{ */
1103 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1104 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1105 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1106 | TemplateLiteral { CYNOT(@$); }
1110 : PrimaryExpression[pass] { $$ = $pass; }
1111 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1112 | SuperProperty[pass] { $$ = $pass; }
1113 | MetaProperty { CYNOT(@$); }
1114 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1118 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1119 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1127 : "new" "." "target"
1131 : MemberExpression[pass] { $$ = $pass; }
1132 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1136 : MemberExpression[pass] { $$ = $pass; }
1137 | CallExpression[pass] { $$ = $pass; }
1141 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1142 | SuperCall[pass] { $$ = $pass; }
1143 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1147 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1151 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1155 : "," ArgumentList[arguments] { $$ = $arguments; }
1160 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1161 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1165 : ArgumentList[pass] { $$ = $pass; }
1166 | LexOf { $$ = NULL; }
1170 : NewExpression[pass] { $$ = $pass; }
1171 | CallExpression[pass] { $$ = $pass; }
1174 LeftHandSideExpression
1175 : RubyBlockExpression[pass] { $$ = $pass; }
1176 | IndirectExpression[pass] { $$ = $pass; }
1179 /* 12.4 Postfix Expressions {{{ */
1181 : RubyBlockExpression[pass] { $$ = $pass; }
1182 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1183 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1186 /* 12.5 Unary Operators {{{ */
1188 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1189 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1190 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1191 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1192 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1193 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1194 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1195 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1196 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1200 : PostfixExpression[expression] { $$ = $expression; }
1201 | UnaryExpression_[pass] { $$ = $pass; }
1204 /* 12.6 Multiplicative Operators {{{ */
1205 MultiplicativeExpression
1206 : UnaryExpression[pass] { $$ = $pass; }
1207 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1208 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1209 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1212 /* 12.7 Additive Operators {{{ */
1214 : MultiplicativeExpression[pass] { $$ = $pass; }
1215 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1216 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1219 /* 12.8 Bitwise Shift Operators {{{ */
1221 : AdditiveExpression[pass] { $$ = $pass; }
1222 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1223 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1224 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1227 /* 12.9 Relational Operators {{{ */
1228 RelationalExpression
1229 : ShiftExpression[pass] { $$ = $pass; }
1230 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1231 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1232 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1233 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1234 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1235 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1238 /* 12.10 Equality Operators {{{ */
1240 : RelationalExpression[pass] { $$ = $pass; }
1241 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1242 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1243 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1244 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1247 /* 12.11 Binary Bitwise Operators {{{ */
1248 BitwiseANDExpression
1249 : EqualityExpression[pass] { $$ = $pass; }
1250 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1253 BitwiseXORExpression
1254 : BitwiseANDExpression[pass] { $$ = $pass; }
1255 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1259 : BitwiseXORExpression[pass] { $$ = $pass; }
1260 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1263 /* 12.12 Binary Logical Operators {{{ */
1264 LogicalANDExpression
1265 : BitwiseORExpression[pass] { $$ = $pass; }
1266 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1270 : LogicalANDExpression[pass] { $$ = $pass; }
1271 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1274 /* 12.13 Conditional Operator ( ? : ) {{{ */
1276 ConditionalExpressionClassic
1277 : LogicalORExpression[pass] { $$ = $pass; }
1278 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1282 ConditionalExpression
1283 : LogicalORExpression[pass] { $$ = $pass; }
1284 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1287 /* 12.14 Assignment Operators {{{ */
1288 LeftHandSideAssignment
1289 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1290 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1291 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1292 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1293 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1294 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1295 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1296 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1297 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1298 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1299 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1300 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1304 AssignmentExpressionClassic
1305 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1306 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1310 AssignmentExpression
1311 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1312 | LexOf YieldExpression[pass] { $$ = $pass; }
1313 | ArrowFunction[pass] { $$ = $pass; }
1314 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1317 AssignmentExpressionOpt
1318 : AssignmentExpression[pass] { $$ = $pass; }
1319 | LexOf { $$ = NULL; }
1322 /* 12.15 Comma Operator ( , ) {{{ */
1324 : AssignmentExpression[pass] { $$ = $pass; }
1325 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1329 : Expression[pass] { $$ = $pass; }
1330 | LexOf { $$ = NULL; }
1334 /* 13 Statements and Declarations {{{ */
1336 : BlockStatement[pass] { $$ = $pass; }
1337 | VariableStatement[pass] { $$ = $pass; }
1338 | EmptyStatement[pass] { $$ = $pass; }
1339 | IfStatement[pass] { $$ = $pass; }
1340 | BreakableStatement[pass] { $$ = $pass; }
1341 | ContinueStatement[pass] { $$ = $pass; }
1342 | BreakStatement[pass] { $$ = $pass; }
1343 | ReturnStatement[pass] { $$ = $pass; }
1344 | WithStatement[pass] { $$ = $pass; }
1345 | LabelledStatement[pass] { $$ = $pass; }
1346 | ThrowStatement[pass] { $$ = $pass; }
1347 | TryStatement[pass] { $$ = $pass; }
1348 | DebuggerStatement[pass] { $$ = $pass; }
1352 : LexOf Statement__[pass] { $$ = $pass; }
1353 | ExpressionStatement[pass] { $$ = $pass; }
1357 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1361 : HoistableDeclaration[pass] { $$ = $pass; }
1362 | ClassDeclaration[pass] { $$ = $pass; }
1366 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1367 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1370 HoistableDeclaration
1371 : FunctionDeclaration[pass] { $$ = $pass; }
1372 | GeneratorDeclaration[pass] { $$ = $pass; }
1376 : IterationStatement[pass] { $$ = $pass; }
1377 | SwitchStatement[pass] { $$ = $pass; }
1380 /* 13.2 Block {{{ */
1382 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1386 : "{" StatementListOpt[code] "}" { $$ = $code; }
1390 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1394 : StatementList[pass] { $$ = $pass; }
1395 | LexSetStatement LexLet LexOf { $$ = NULL; }
1399 : Statement[pass] { $$ = $pass; }
1400 | Declaration[pass] { $$ = $pass; }
1403 /* 13.3 Let and Const Declarations {{{ */
1405 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1409 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1413 : { CYMAP(_let__, _let_); }
1417 : { CYMAP(_of__, _of_); }
1421 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1425 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1426 | LexLet LexOf "const" { $$ = true; }
1430 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1435 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1439 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1440 | LexOf BindingPattern Initializer { CYNOT(@$); }
1443 /* 13.3.2 Variable Statement {{{ */
1445 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1449 : VariableStatement_[statement] Terminator { $$ = $statement; }
1452 VariableDeclarationList_
1453 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1457 VariableDeclarationList
1458 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1462 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1463 | LexOf BindingPattern Initializer { CYNOT(@$); }
1466 /* 13.3.3 Destructuring Binding Patterns {{{ */
1468 : ObjectBindingPattern
1469 | ArrayBindingPattern
1472 ObjectBindingPattern
1473 : "let {" BindingPropertyListOpt "}"
1477 : "let [" BindingElementListOpt "]"
1480 BindingPropertyList_
1481 : "," BindingPropertyListOpt
1486 : BindingProperty BindingPropertyList_
1489 BindingPropertyListOpt
1490 : BindingPropertyList
1495 : BindingElementOpt[element] "," BindingElementListOpt[next]
1496 | BindingRestElement[element]
1497 | BindingElement[element]
1500 BindingElementListOpt
1501 : BindingElementList[pass]
1507 | LexOf PropertyName ":" BindingElement
1511 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1512 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1516 : BindingElement[pass]
1521 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1525 : LexBind LexOf "..." BindingIdentifier
1528 /* 13.4 Empty Statement {{{ */
1530 : ";" { $$ = CYNew CYEmpty(); }
1533 /* 13.5 Expression Statement {{{ */
1534 ExpressionStatement_
1535 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1538 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1541 /* 13.6 The if Statement {{{ */
1543 : "else" Statement[false] { $$ = $false; }
1544 | %prec "if" { $$ = NULL; }
1548 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1551 /* 13.7 Iteration Statements {{{ */
1553 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1554 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1555 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1556 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1557 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1558 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1561 ForStatementInitializer
1562 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1563 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1564 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1565 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1568 ForInStatementInitializer
1569 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1570 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1571 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1572 | ForDeclaration[pass] { $$ = $pass; }
1576 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1580 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1581 | LexOf BindingPattern { CYNOT(@$); }
1584 /* 13.8 The continue Statement {{{ */
1586 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1587 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1590 /* 13.9 The break Statement {{{ */
1592 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1593 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1596 /* 13.10 The return Statement {{{ */
1598 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1599 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1602 /* 13.11 The with Statement {{{ */
1604 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1607 /* 13.12 The switch Statement {{{ */
1609 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1613 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1617 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1621 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1622 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1626 // XXX: the standard makes certain you can only have one of these
1628 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1631 /* 13.13 Labelled Statements {{{ */
1633 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1637 : Statement[pass] { $$ = $pass; }
1638 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1641 /* 13.14 The throw Statement {{{ */
1643 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1644 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1647 /* 13.15 The try Statement {{{ */
1649 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1650 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1651 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1655 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1659 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1663 : BindingIdentifier[pass] { $$ = $pass; }
1664 | LexOf BindingPattern { CYNOT(@$); }
1667 /* 13.16 The debugger Statement {{{ */
1669 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1673 /* 14.1 Function Definitions {{{ */
1675 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1679 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1682 StrictFormalParameters
1683 : FormalParameters[pass] { $$ = $pass; }
1687 : LexBind LexOf { $$ = NULL; }
1688 | FormalParameterList
1691 FormalParameterList_
1692 : "," FormalParameterList[parameters] { $$ = $parameters; }
1697 : FunctionRestParameter { CYNOT(@$); }
1698 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1701 FunctionRestParameter
1702 : BindingRestElement
1706 : BindingElement[pass] { $$ = $pass; }
1710 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1713 FunctionStatementList
1714 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1717 /* 14.2 Arrow Function Definitions {{{ */
1719 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1723 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1724 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1728 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1729 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1732 /* 14.3 Method Definitions {{{ */
1734 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1735 | GeneratorMethod[pass] { $$ = $pass; }
1736 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1737 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1740 PropertySetParameterList
1741 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1744 /* 14.4 Generator Function Definitions {{{ */
1746 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1749 GeneratorDeclaration
1750 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1754 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1758 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1762 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1763 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1764 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1765 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1768 /* 14.5 Class Definitions {{{ */
1770 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1774 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1778 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1782 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1786 : ClassHeritage[pass] { $$ = $pass; }
1787 | { $$ = CYNew CYClassTail(NULL); }
1800 : ClassElementListOpt ClassElement
1809 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1810 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1815 /* 15.1 Scripts {{{ */
1817 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1821 : StatementList[pass] { $$ = $pass; }
1825 : ScriptBody[pass] { $$ = $pass; }
1826 | LexSetStatement LexLet LexOf { $$ = NULL; }
1829 /* 15.2 Modules {{{ */
1844 : ModuleItemListOpt ModuleItem
1853 : LexSetStatement LexLet LexOf ImportDeclaration
1854 | LexSetStatement LexLet LexOf ExportDeclaration
1858 /* 15.2.2 Imports {{{ */
1860 : "import" ImportClause FromClause Terminator
1861 | "import" LexOf ModuleSpecifier Terminator
1865 : ImportedDefaultBinding
1866 | LexOf NameSpaceImport
1867 | LexOf NamedImports
1868 | ImportedDefaultBinding "," NameSpaceImport
1869 | ImportedDefaultBinding "," NamedImports
1872 ImportedDefaultBinding
1877 : "*" "as" ImportedBinding
1881 : "{" ImportsListOpt "}"
1885 : "from" ModuleSpecifier
1889 : "," ImportsListOpt
1894 : ImportSpecifier ImportsList_
1904 | LexOf IdentifierName "as" ImportedBinding
1915 /* 15.2.3 Exports {{{ */
1917 : "*" FromClause Terminator
1918 | ExportClause FromClause Terminator
1919 | ExportClause Terminator
1921 | "default" LexSetStatement LexOf HoistableDeclaration
1922 | "default" LexSetStatement LexOf ClassDeclaration
1923 | "default" LexSetStatement AssignmentExpression Terminator
1927 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1928 | "export" Declaration
1932 : ";{" ExportsListOpt "}"
1936 : "," ExportsListOpt
1941 : ExportSpecifier ExportsList_
1951 | IdentifierName "as" IdentifierName
1956 /* Cycript (C): Type Encoding {{{ */
1958 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1959 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1963 : TypeSignifier[pass] { $$ = $pass; }
1964 | { $$ = CYNew CYTypedIdentifier(@$); }
1968 : SuffixedTypeOpt[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1969 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1970 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1971 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1975 : SuffixedType[pass] { $$ = $pass; }
1976 | TypeSignifierOpt[pass] { $$ = $pass; }
1980 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1984 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1985 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1988 TypeQualifierLeftOpt
1989 : TypeQualifierLeft[pass] { $$ = $pass; }
1994 : SuffixedType[pass] { $$ = $pass; }
1995 | PrefixedType[pass] { $$ = $pass; }
1996 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1997 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2000 TypeQualifierRightOpt
2001 : TypeQualifierRight[pass] { $$ = $pass; }
2002 | TypeSignifierOpt[pass] { $$ = $pass; }
2006 : "int" { $$ = CYNew CYTypeVariable("int"); }
2007 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
2008 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
2009 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
2010 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
2014 : IntegerType[pass] { $$ = $pass; }
2015 | { $$ = CYNew CYTypeVariable("int"); }
2019 : TypedIdentifierMaybe[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2024 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2025 | IntegerType[pass] { $$ = $pass; }
2026 | "char" { $$ = CYNew CYTypeVariable("char"); }
2027 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
2028 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2029 | "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYTypeStruct($name, $fields); }
2032 TypedIdentifierMaybe
2033 : TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2034 | TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2035 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2039 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2043 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2047 : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2053 /* Cycript (Objective-C): @class Declaration {{{ */
2055 /* XXX: why the hell did I choose MemberExpression? */
2056 : ":" MemberExpression[extends] { $$ = $extends; }
2060 ImplementationFieldListOpt
2061 : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2066 : "+" { $$ = false; }
2067 | "-" { $$ = true; }
2071 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2072 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2076 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2079 MessageParameterList
2080 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2083 MessageParameterListOpt
2084 : MessageParameterList[pass] { $$ = $pass; }
2089 : MessageParameterList[pass] { $$ = $pass; }
2090 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2093 ClassMessageDeclaration
2094 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2097 ClassMessageDeclarationListOpt
2098 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2102 // XXX: this should be AssignmentExpressionNoRight
2104 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2108 : "," ClassProtocols[protocols] { $$ = $protocols; }
2112 ClassProtocolListOpt
2113 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2117 ImplementationStatement
2118 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2126 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2130 : ImplementationStatement[pass] { $$ = $pass; }
2131 | CategoryStatement[pass] { $$ = $pass; }
2134 /* Cycript (Objective-C): Send Message {{{ */
2136 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2141 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2142 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2146 : SelectorCall[pass] { $$ = $pass; }
2147 | VariadicCall[pass] { $$ = $pass; }
2151 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2155 : SelectorCall[pass] { $$ = $pass; }
2156 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2160 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2161 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2165 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2169 : SelectorExpression_[pass] { $$ = $pass; }
2170 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2173 SelectorExpressionOpt
2174 : SelectorExpression_[pass] { $$ = $pass; }
2179 : MessageExpression[pass] { $$ = $pass; }
2180 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2185 /* Cycript: @import Directive {{{ */
2187 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2188 | Word[part] { $$ = CYNew CYModule($part); }
2192 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2197 /* Cycript (Objective-C): Boxed Expressions {{{ */
2199 : NullLiteral[pass] { $$ = $pass; }
2200 | BooleanLiteral[pass] { $$ = $pass; }
2201 | NumericLiteral[pass] { $$ = $pass; }
2202 | StringLiteral[pass] { $$ = $pass; }
2203 | ArrayLiteral[pass] { $$ = $pass; }
2204 | ObjectLiteral[pass] { $$ = $pass; }
2205 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2206 | "YES" { $$ = CYNew CYTrue(); }
2207 | "NO" { $$ = CYNew CYFalse(); }
2211 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2212 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2213 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2214 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2215 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2216 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2219 /* Cycript (Objective-C): Block Expressions {{{ */
2221 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2224 /* Cycript (Objective-C): Instance Literals {{{ */
2226 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2232 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2234 : IndirectExpression[pass] { $$ = $pass; }
2238 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2242 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2246 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2247 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2248 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2251 /* Cycript (C): Lambda Expressions {{{ */
2253 : "," TypedParameterList[parameters] { $$ = $parameters; }
2258 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2261 TypedParameterListOpt
2262 : TypedParameterList[pass] { $$ = $pass; }
2263 | "void" { $$ = NULL; }
2268 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2271 /* Cycript (C): Type Definitions {{{ */
2273 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2277 : "typedef" NewLineNot TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2281 : TypeDefinition[pass] { $$ = $pass; }
2285 : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2288 /* Cycript (C): extern "C" {{{ */
2290 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2294 : TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2295 | TypeDefinition[pass] { $$ = $pass; }
2298 ExternCStatementListOpt
2299 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2304 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2305 | ExternCStatement[pass] { $$ = $pass; }
2309 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2316 /* Lexer State {{{ */
2318 : { driver.PushCondition(CYDriver::RegExpCondition); }
2322 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2326 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2330 : { driver.PopCondition(); }
2334 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2338 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2341 /* Virtual Tokens {{{ */
2348 /* 8.1 Context Keywords {{{ */
2350 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2351 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2354 /* 8.3 XML Initializer Input Elements {{{ */
2356 : XMLComment { $$ = $1; }
2357 | XMLCDATA { $$ = $1; }
2358 | XMLPI { $$ = $1; }
2362 /* 11.1 Primary Expressions {{{ */
2364 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2365 | XMLInitilizer { $$ = $1; }
2366 | XMLListInitilizer { $$ = $1; }
2370 : AttributeIdentifier { $$ = $1; }
2371 | QualifiedIdentifier { $$ = $1; }
2372 | WildcardIdentifier { $$ = $1; }
2375 /* 11.1.1 Attribute Identifiers {{{ */
2377 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2381 : PropertySelector { $$ = $1; }
2382 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2386 : Identifier { $$ = CYNew CYSelector($1); }
2387 | WildcardIdentifier { $$ = $1; }
2390 /* 11.1.2 Qualified Identifiers {{{ */
2391 QualifiedIdentifier_
2392 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2393 | QualifiedIdentifier { $$ = $1; }
2397 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2400 /* 11.1.3 Wildcard Identifiers {{{ */
2402 : "*" { $$ = CYNew CYWildcard(); }
2405 /* 11.1.4 XML Initializer {{{ */
2407 : XMLMarkup { $$ = $1; }
2408 | XMLElement { $$ = $1; }
2412 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2413 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2417 : LexPushXMLTag XMLTagName XMLAttributes
2421 : "{" LexPushRegExp Expression LexPop "}"
2430 : XMLAttributes_ XMLAttribute
2435 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2436 | XMLAttributes_ XMLWhitespaceOpt
2445 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2449 : XMLExpression XMLElementContentOpt
2450 | XMLMarkup XMLElementContentOpt
2451 | XMLText XMLElementContentOpt
2452 | XMLElement XMLElementContentOpt
2455 XMLElementContentOpt
2460 /* 11.1.5 XMLList Initializer {{{ */
2462 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2466 /* 11.2 Left-Hand-Side Expressions {{{ */
2468 : Identifier { $$ = $1; }
2469 | PropertyIdentifier { $$ = $1; }
2473 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2474 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2475 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2478 /* 12.1 The default xml namespace Statement {{{ */
2479 /* XXX: DefaultXMLNamespaceStatement
2480 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2484 : DefaultXMLNamespaceStatement { $$ = $1; }
2489 /* JavaScript FTL: Array Comprehensions {{{ */
2491 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2495 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2498 /* JavaScript FTL: for each {{{ */
2500 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2504 /* JavaScript FTW: Array Comprehensions {{{ */
2506 : ArrayComprehension
2510 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2514 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2519 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2520 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2524 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2525 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2529 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2532 /* JavaScript FTW: Coalesce Operator {{{ */
2533 ConditionalExpression
2534 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2537 /* JavaScript FTW: Named Arguments {{{ */
2539 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2542 /* JavaScript FTW: Ruby Blocks {{{ */
2543 RubyProcParameterList_
2544 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2548 RubyProcParameterList
2549 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2550 | LexOf { $$ = NULL; }
2554 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2555 | "||" { $$ = NULL; }
2558 RubyProcParametersOpt
2559 : RubyProcParameters[pass] { $$ = $pass; }
2564 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2568 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2571 RubyBlockExpression_
2572 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2573 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2577 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2578 | RubyBlockExpression_[pass] { $$ = $pass; }
2584 bool CYDriver::Parse(CYMark mark) {
2586 CYLocal<CYPool> local(&pool_);
2587 cy::parser parser(*this);
2589 parser.set_debug_level(debug_);
2591 return parser.parse() != 0;
2594 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2598 CYDriver::Error error;
2599 error.warning_ = true;
2600 error.location_ = location;
2601 error.message_ = message;
2602 errors_.push_back(error);
2605 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2606 CYDriver::Error error;
2607 error.warning_ = false;
2608 error.location_ = location;
2609 error.message_ = message;
2610 driver.errors_.push_back(error);