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 *);
118 typedef cy::parser::token tk;
120 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
121 driver.newline_ = false;
124 int token(cylex(&data, location, driver.scanner_));
125 *semantic = data.semantic_;
129 case tk::OpenBracket:
131 driver.in_.push(false);
135 if (driver.in_.top())
140 case tk::CloseBracket:
147 if (driver.yield_.top())
148 token = tk::_yield__;
152 driver.newline_ = true;
160 #define yylex_(semantic, location, driver) ({ \
162 if (driver.hold_ == cy::parser::empty_symbol) \
163 type = yytranslate_(cylex_(semantic, location, driver)); \
165 type = driver.hold_; \
166 driver.hold_ = cy::parser::empty_symbol; \
170 #define CYLEX() do if (yyla.empty()) { \
171 YYCDEBUG << "Mapping a token: "; \
172 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
173 YY_SYMBOL_PRINT("Next token is", yyla); \
176 #define CYMAP(to, from) do { \
178 if (yyla.type == yytranslate_(token::from)) \
179 yyla.type = yytranslate_(token::to); \
182 #define CYERR(location, message) do { \
183 error(location, message); \
187 #define CYEOK() do { \
189 driver.errors_.pop_back(); \
192 #define CYNOT(location) \
193 CYERR(location, "unimplemented feature")
195 #define CYMPT(location) do { \
196 if (!yyla.empty() && yyla.type_get() != yyeof_) \
197 CYERR(location, "unexpected lookahead"); \
207 @$.begin.filename = @$.end.filename = &driver.filename_;
209 switch (driver.mark_) {
211 driver.hold_ = yytranslate_(token::MarkScript);
214 driver.hold_ = yytranslate_(token::MarkModule);
222 %define api.location.type { CYLocation }
229 %param { CYDriver &driver }
231 /* Token Declarations {{{ */
237 %token XMLAttributeValue
239 %token XMLTagCharacters
245 %token LeftRight "<>"
246 %token LeftSlashRight "</>"
248 %token SlashRight "/>"
249 %token LeftSlash "</"
251 %token ColonColon "::"
252 %token PeriodPeriod ".."
255 @begin E4X ObjectiveC
261 %token AmpersandAmpersand "&&"
262 %token AmpersandEqual "&="
264 %token CarrotEqual "^="
266 %token EqualEqual "=="
267 %token EqualEqualEqual "==="
268 %token EqualRight "=>"
269 %token Exclamation "!"
270 %token ExclamationEqual "!="
271 %token ExclamationEqualEqual "!=="
273 %token HyphenEqual "-="
274 %token HyphenHyphen "--"
275 %token HyphenRight "->"
277 %token LeftEqual "<="
279 %token LeftLeftEqual "<<="
281 %token PercentEqual "%="
283 %token PeriodPeriodPeriod "..."
285 %token PipeEqual "|="
288 %token PlusEqual "+="
291 %token RightEqual ">="
292 %token RightRight ">>"
293 %token RightRightEqual ">>="
294 %token RightRightRight ">>>"
295 %token RightRightRightEqual ">>>="
297 %token SlashEqual "/="
299 %token StarEqual "*="
312 %token CloseParen ")"
315 %token OpenBrace_ ";{"
316 %token OpenBrace_let "let {"
317 %token CloseBrace "}"
319 %token OpenBracket "["
320 %token OpenBracket_let "let ["
321 %token CloseBracket "]"
323 %token At_error_ "@error"
326 %token At_class_ "@class"
330 %token _typedef_ "typedef"
331 %token _unsigned_ "unsigned"
332 %token _signed_ "signed"
333 %token _extern_ "extern"
337 %token At_encode_ "@encode"
341 %token At_implementation_ "@implementation"
342 %token At_import_ "@import"
343 %token At_end_ "@end"
344 %token At_selector_ "@selector"
345 %token At_null_ "@null"
346 %token At_YES_ "@YES"
348 %token At_true_ "@true"
349 %token At_false_ "@false"
354 %token _false_ "false"
358 %token _break_ "break"
360 %token _catch_ "catch"
361 %token _class_ "class"
362 %token _class__ ";class"
363 %token _const_ "const"
364 %token _continue_ "continue"
365 %token _debugger_ "debugger"
366 %token _default_ "default"
367 %token _delete_ "delete"
371 %token _export_ "export"
372 %token _extends_ "extends"
373 %token _finally_ "finally"
375 %token _function_ "function"
376 %token _function__ ";function"
378 %token _import_ "import"
381 %token _Infinity_ "Infinity"
382 %token _instanceof_ "instanceof"
384 %token _return_ "return"
385 %token _super_ "super"
386 %token _switch_ "switch"
387 %token _target_ "target"
389 %token _throw_ "throw"
391 %token _typeof_ "typeof"
394 %token _while_ "while"
397 %token _abstract_ "abstract"
398 %token _await_ "await"
399 %token _boolean_ "boolean"
402 %token _constructor_ "constructor"
403 %token _double_ "double"
405 %token _final_ "final"
406 %token _float_ "float"
410 %token _implements_ "implements"
412 %token _interface_ "interface"
416 %token _native_ "native"
417 %token _package_ "package"
418 %token _private_ "private"
419 %token _protected_ "protected"
420 %token _prototype_ "prototype"
421 %token _public_ "public"
423 %token _short_ "short"
424 %token _static_ "static"
425 %token _synchronized_ "synchronized"
426 %token _throws_ "throws"
427 %token _transient_ "transient"
428 %token _volatile_ "volatile"
429 %token _yield_ "yield"
430 %token _yield__ "!yield"
432 %token _undefined_ "undefined"
448 %token _namespace_ "namespace"
453 %token YieldStar "yield *"
455 %token <identifier_> Identifier_
456 %token <number_> NumericLiteral
457 %token <string_> StringLiteral
458 %token <literal_> RegularExpressionLiteral_
460 %token <string_> NoSubstitutionTemplate
461 %token <string_> TemplateHead
462 %token <string_> TemplateMiddle
463 %token <string_> TemplateTail
465 %type <target_> AccessExpression
466 %type <expression_> AdditiveExpression
467 %type <argument_> ArgumentList_
468 %type <argument_> ArgumentList
469 %type <argument_> ArgumentListOpt
470 %type <argument_> Arguments
471 %type <target_> ArrayComprehension
472 %type <literal_> ArrayLiteral
473 %type <expression_> ArrowFunction
474 %type <functionParameter_> ArrowParameters
475 %type <expression_> AssignmentExpression
476 %type <expression_> AssignmentExpressionOpt
477 %type <identifier_> BindingIdentifier
478 %type <identifier_> BindingIdentifierOpt
479 %type <bindings_> BindingList_
480 %type <bindings_> BindingList
481 %type <expression_> BitwiseANDExpression
482 %type <statement_> Block
483 %type <statement_> BlockStatement
484 %type <boolean_> BooleanLiteral
485 %type <binding_> BindingElement
486 %type <expression_> BitwiseORExpression
487 %type <expression_> BitwiseXORExpression
488 %type <statement_> BreakStatement
489 %type <statement_> BreakableStatement
490 %type <expression_> CallExpression_
491 %type <target_> CallExpression
492 %type <clause_> CaseBlock
493 %type <clause_> CaseClause
494 %type <clause_> CaseClausesOpt
496 %type <identifier_> CatchParameter
497 %type <statement_> ClassDeclaration
498 %type <target_> ClassExpression
499 %type <classTail_> ClassHeritage
500 %type <classTail_> ClassHeritageOpt
501 %type <classTail_> ClassTail
502 %type <target_> Comprehension
503 %type <comprehension_> ComprehensionFor
504 %type <comprehension_> ComprehensionIf
505 %type <comprehension_> ComprehensionTail
506 %type <propertyName_> ComputedPropertyName
507 %type <expression_> ConditionalExpression
508 %type <statement_> ContinueStatement
509 %type <statement_> ConciseBody
510 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
511 %type <statement_> DebuggerStatement
512 %type <statement_> Declaration_
513 %type <statement_> Declaration
514 %type <clause_> DefaultClause
515 %type <element_> ElementList
516 %type <element_> ElementListOpt
517 %type <statement_> ElseStatementOpt
518 %type <for_> EmptyStatement
519 %type <expression_> EqualityExpression
520 %type <expression_> Expression
521 %type <expression_> ExpressionOpt
522 %type <for_> ExpressionStatement_
523 %type <statement_> ExpressionStatement
524 %type <finally_> Finally
525 %type <binding_> ForBinding
526 %type <forin_> ForDeclaration
527 %type <forin_> ForInStatementInitializer
528 %type <for_> ForStatementInitializer
529 %type <binding_> FormalParameter
530 %type <functionParameter_> FormalParameterList_
531 %type <functionParameter_> FormalParameterList
532 %type <functionParameter_> FormalParameters
533 %type <statement_> FunctionBody
534 %type <statement_> FunctionDeclaration
535 %type <target_> FunctionExpression
536 %type <statement_> FunctionStatementList
537 %type <statement_> GeneratorBody
538 %type <statement_> GeneratorDeclaration
539 %type <target_> GeneratorExpression
540 %type <method_> GeneratorMethod
541 %type <statement_> HoistableDeclaration
542 %type <identifier_> Identifier
543 %type <identifier_> IdentifierNoOf
544 %type <identifier_> IdentifierType
545 %type <identifier_> IdentifierTypeNoOf
546 %type <word_> IdentifierName
547 %type <variable_> IdentifierReference
548 %type <statement_> IfStatement
549 %type <target_> IndirectExpression
550 %type <expression_> Initializer
551 %type <expression_> InitializerOpt
552 %type <statement_> IterationStatement
553 %type <identifier_> LabelIdentifier
554 %type <statement_> LabelledItem
555 %type <statement_> LabelledStatement
556 %type <assignment_> LeftHandSideAssignment
557 %type <target_> LeftHandSideExpression
558 %type <bool_> LetOrConst
559 %type <binding_> LexicalBinding
560 %type <for_> LexicalDeclaration_
561 %type <statement_> LexicalDeclaration
562 %type <literal_> Literal
563 %type <propertyName_> LiteralPropertyName
564 %type <expression_> LogicalANDExpression
565 %type <expression_> LogicalORExpression
566 %type <access_> MemberAccess
567 %type <target_> MemberExpression
568 %type <method_> MethodDefinition
569 %type <module_> ModulePath
570 %type <expression_> MultiplicativeExpression
571 %type <target_> NewExpression
572 %type <null_> NullLiteral
573 %type <literal_> ObjectLiteral
574 %type <expression_> PostfixExpression
575 %type <target_> PrimaryExpression
576 %type <propertyName_> PropertyName
577 %type <property_> PropertyDefinition
578 %type <property_> PropertyDefinitionList_
579 %type <property_> PropertyDefinitionList
580 %type <property_> PropertyDefinitionListOpt
581 %type <functionParameter_> PropertySetParameterList
582 %type <literal_> RegularExpressionLiteral
583 %type <bool_> RegularExpressionSlash
584 %type <expression_> RelationalExpression
585 %type <statement_> ReturnStatement
586 %type <rubyProc_> RubyProcExpression
587 %type <functionParameter_> RubyProcParameterList_
588 %type <functionParameter_> RubyProcParameterList
589 %type <functionParameter_> RubyProcParameters
590 %type <functionParameter_> RubyProcParametersOpt
591 %type <statement_> Script
592 %type <statement_> ScriptBody
593 %type <statement_> ScriptBodyOpt
594 %type <expression_> ShiftExpression
595 %type <binding_> SingleNameBinding
596 %type <statement_> Statement__
597 %type <statement_> Statement_
598 %type <statement_> Statement
599 %type <statement_> StatementList
600 %type <statement_> StatementListOpt
601 %type <statement_> StatementListItem
602 %type <functionParameter_> StrictFormalParameters
603 %type <target_> SuperCall
604 %type <target_> SuperProperty
605 %type <statement_> SwitchStatement
606 %type <target_> TemplateLiteral
607 %type <span_> TemplateSpans
608 %type <statement_> ThrowStatement
609 %type <statement_> TryStatement
610 %type <expression_> UnaryExpression_
611 %type <expression_> UnaryExpression
612 %type <binding_> VariableDeclaration
613 %type <bindings_> VariableDeclarationList_
614 %type <bindings_> VariableDeclarationList
615 %type <for_> VariableStatement_
616 %type <statement_> VariableStatement
617 %type <statement_> WithStatement
620 %type <word_> WordOpt
622 %type <expression_> YieldExpression
625 %type <specifier_> IntegerType
626 %type <specifier_> IntegerTypeOpt
627 %type <typedIdentifier_> PrefixedType
628 %type <specifier_> PrimitiveType
629 %type <typedIdentifier_> SuffixedType
630 %type <typedIdentifier_> TypeSignifier
631 %type <modifier_> TypeQualifierLeft
632 %type <typedIdentifier_> TypeQualifierRight
633 %type <typedIdentifier_> TypedIdentifier
634 %type <typedParameter_> TypedParameterList_
635 %type <typedParameter_> TypedParameterList
636 %type <typedParameter_> TypedParameterListOpt
640 %type <expression_> AssignmentExpressionClassic
641 %type <expression_> BoxableExpression
642 %type <statement_> CategoryStatement
643 %type <expression_> ClassSuperOpt
644 %type <expression_> ConditionalExpressionClassic
645 %type <implementationField_> ImplementationFieldListOpt
646 %type <implementationField_> ImplementationFields
647 %type <message_> ClassMessageDeclaration
648 %type <message_> ClassMessageDeclarationListOpt
649 %type <protocol_> ClassProtocolListOpt
650 %type <protocol_> ClassProtocols
651 %type <protocol_> ClassProtocolsOpt
652 %type <statement_> ImplementationStatement
653 %type <target_> MessageExpression
654 %type <messageParameter_> MessageParameter
655 %type <messageParameter_> MessageParameters
656 %type <messageParameter_> MessageParameterList
657 %type <messageParameter_> MessageParameterListOpt
658 %type <bool_> MessageScope
659 %type <argument_> SelectorCall_
660 %type <argument_> SelectorCall
661 %type <selector_> SelectorExpression_
662 %type <selector_> SelectorExpression
663 %type <selector_> SelectorExpressionOpt
664 %type <argument_> SelectorList
665 %type <word_> SelectorWordOpt
666 %type <typedIdentifier_> TypeOpt
667 %type <argument_> VariadicCall
671 %type <propertyIdentifier_> PropertyIdentifier_
672 %type <selector_> PropertySelector_
673 %type <selector_> PropertySelector
674 %type <identifier_> QualifiedIdentifier_
675 %type <identifier_> QualifiedIdentifier
676 %type <identifier_> WildcardIdentifier
677 %type <identifier_> XMLComment
678 %type <identifier_> XMLCDATA
679 %type <identifier_> XMLElement
680 %type <identifier_> XMLElementContent
681 %type <identifier_> XMLMarkup
682 %type <identifier_> XMLPI
684 %type <attribute_> AttributeIdentifier
685 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
686 %type <expression_> PropertyIdentifier
687 %type <expression_> XMLListInitilizer
688 %type <expression_> XMLInitilizer
691 /* Token Priorities {{{ */
707 /* Lexer State {{{ */
708 LexPushInOn: { driver.in_.push(true); };
709 LexPushInOff: { driver.in_.push(false); };
710 LexPopIn: { driver.in_.pop(); };
712 LexPushReturnOn: { driver.return_.push(true); };
713 LexPopReturn: { driver.return_.pop(); };
715 LexPushSuperOn: { driver.super_.push(true); };
716 LexPushSuperOff: { driver.super_.push(false); };
717 LexPopSuper: { driver.super_.pop(); };
719 LexPushYieldOn: { driver.yield_.push(true); };
720 LexPushYieldOff: { driver.yield_.push(false); };
721 LexPopYield: { driver.yield_.pop(); };
724 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
728 : { 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::__); }
732 : { CYMAP(YieldStar, Star); }
736 : { CYMAP(OpenBrace_, OpenBrace); }
740 : { CYMAP(_class__, _class_); }
744 : { CYMAP(_function__, _function_); }
748 : LexNoBrace LexNoClass LexNoFunction
751 /* Virtual Tokens {{{ */
757 /* 11.6 Names and Keywords {{{ */
759 : Word[pass] { $$ = $pass; }
760 | "for" { $$ = CYNew CYWord("for"); }
761 | "in" { $$ = CYNew CYWord("in"); }
762 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
766 : IdentifierNoOf[pass] { $$ = $pass; }
767 | "break" { $$ = CYNew CYWord("break"); }
768 | "case" { $$ = CYNew CYWord("case"); }
769 | "catch" { $$ = CYNew CYWord("catch"); }
770 | "class" LexOf { $$ = CYNew CYWord("class"); }
771 | ";class" { $$ = CYNew CYWord("class"); }
772 | "const" { $$ = CYNew CYWord("const"); }
773 | "continue" { $$ = CYNew CYWord("continue"); }
774 | "debugger" { $$ = CYNew CYWord("debugger"); }
775 | "default" { $$ = CYNew CYWord("default"); }
776 | "delete" { $$ = CYNew CYWord("delete"); }
777 | "do" { $$ = CYNew CYWord("do"); }
778 | "else" { $$ = CYNew CYWord("else"); }
779 | "enum" { $$ = CYNew CYWord("enum"); }
780 | "export" { $$ = CYNew CYWord("export"); }
781 | "extends" { $$ = CYNew CYWord("extends"); }
782 | "false" { $$ = CYNew CYWord("false"); }
783 | "finally" { $$ = CYNew CYWord("finally"); }
784 | "function" LexOf { $$ = CYNew CYWord("function"); }
785 | "if" { $$ = CYNew CYWord("if"); }
786 | "import" { $$ = CYNew CYWord("import"); }
787 | "!in" { $$ = CYNew CYWord("in"); }
788 | "!of" { $$ = CYNew CYWord("of"); }
789 | "new" { $$ = CYNew CYWord("new"); }
790 | "null" { $$ = CYNew CYWord("null"); }
791 | "return" { $$ = CYNew CYWord("return"); }
792 | "super" { $$ = CYNew CYWord("super"); }
793 | "switch" { $$ = CYNew CYWord("switch"); }
794 | "this" { $$ = CYNew CYWord("this"); }
795 | "throw" { $$ = CYNew CYWord("throw"); }
796 | "true" { $$ = CYNew CYWord("true"); }
797 | "try" { $$ = CYNew CYWord("try"); }
798 | "typeof" { $$ = CYNew CYWord("typeof"); }
799 | "var" { $$ = CYNew CYWord("var"); }
800 | "void" { $$ = CYNew CYWord("void"); }
801 | "while" { $$ = CYNew CYWord("while"); }
802 | "with" { $$ = CYNew CYWord("with"); }
803 | "yield" { $$ = CYNew CYIdentifier("yield"); }
808 : Word[pass] { $$ = $pass; }
813 /* 11.8.1 Null Literals {{{ */
815 : "null" { $$ = CYNew CYNull(); }
818 /* 11.8.2 Boolean Literals {{{ */
820 : "true" { $$ = CYNew CYTrue(); }
821 | "false" { $$ = CYNew CYFalse(); }
824 /* 11.8.5 Regular Expression Literals {{{ */
825 RegularExpressionSlash
826 : "/" { $$ = false; }
827 | "/=" { $$ = true; }
830 RegularExpressionLiteral
831 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
835 /* 11.9 Automatic Semicolon Insertion {{{ */
837 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
845 : LexNewLineOrNot "\n"
850 : LexNewLineOrNot "\n" StrictSemi
851 | NewLineNot LexOf Terminator
856 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
861 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
865 /* 12.1 Identifiers {{{ */
867 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
868 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
872 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
873 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
874 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
878 : BindingIdentifier[pass] { $$ = $pass; }
879 | LexOf { $$ = NULL; }
883 : Identifier[pass] { $$ = $pass; }
884 | "yield" { $$ = CYNew CYIdentifier("yield"); }
888 : Identifier_[pass] { $$ = $pass; }
889 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
890 | "await" { $$ = CYNew CYIdentifier("await"); }
891 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
892 | "byte" { $$ = CYNew CYIdentifier("byte"); }
893 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
894 | "double" { $$ = CYNew CYIdentifier("double"); }
895 | "each" { $$ = CYNew CYIdentifier("each"); }
896 | "eval" { $$ = CYNew CYIdentifier("eval"); }
897 | "final" { $$ = CYNew CYIdentifier("final"); }
898 | "float" { $$ = CYNew CYIdentifier("float"); }
899 | "from" { $$ = CYNew CYIdentifier("from"); }
900 | "get" { $$ = CYNew CYIdentifier("get"); }
901 | "goto" { $$ = CYNew CYIdentifier("goto"); }
902 | "implements" { $$ = CYNew CYIdentifier("implements"); }
903 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
904 | "interface" { $$ = CYNew CYIdentifier("interface"); }
905 | "let" { $$ = CYNew CYIdentifier("let"); }
906 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
907 | "native" { $$ = CYNew CYIdentifier("native"); }
908 | "package" { $$ = CYNew CYIdentifier("package"); }
909 | "private" { $$ = CYNew CYIdentifier("private"); }
910 | "protected" { $$ = CYNew CYIdentifier("protected"); }
911 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
912 | "public" { $$ = CYNew CYIdentifier("public"); }
913 | "set" { $$ = CYNew CYIdentifier("set"); }
914 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
915 | "target" { $$ = CYNew CYIdentifier("target"); }
916 | "throws" { $$ = CYNew CYIdentifier("throws"); }
917 | "transient" { $$ = CYNew CYIdentifier("transient"); }
918 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
920 | "bool" { $$ = CYNew CYIdentifier("bool"); }
921 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
922 | "id" { $$ = CYNew CYIdentifier("id"); }
923 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
928 : IdentifierTypeNoOf[pass] { $$ = $pass; }
929 | "of" { $$ = CYNew CYIdentifier("of"); }
934 | "char" { $$ = CYNew CYIdentifier("char"); }
935 | "int" { $$ = CYNew CYIdentifier("int"); }
936 | "long" { $$ = CYNew CYIdentifier("long"); }
937 | "short" { $$ = CYNew CYIdentifier("short"); }
938 | "static" { $$ = CYNew CYIdentifier("static"); }
939 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
941 | "signed" { $$ = CYNew CYIdentifier("signed"); }
942 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
945 | "nil" { $$ = CYNew CYIdentifier("nil"); }
946 | "NO" { $$ = CYNew CYIdentifier("NO"); }
947 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
948 | "YES" { $$ = CYNew CYIdentifier("YES"); }
953 : IdentifierNoOf[pass] { $$ = $pass; }
954 | "of" { $$ = CYNew CYIdentifier("of"); }
955 | "!of" { $$ = CYNew CYIdentifier("of"); }
958 /* 12.2 Primary Expression {{{ */
960 : "this" { $$ = CYNew CYThis(); }
961 | IdentifierReference[pass] { $$ = $pass; }
962 | Literal[pass] { $$ = $pass; }
963 | ArrayLiteral[pass] { $$ = $pass; }
964 | ObjectLiteral[pass] { $$ = $pass; }
965 | FunctionExpression[pass] { $$ = $pass; }
966 | ClassExpression[pass] { $$ = $pass; }
967 | GeneratorExpression[pass] { $$ = $pass; }
968 | RegularExpressionLiteral[pass] { $$ = $pass; }
969 | TemplateLiteral[pass] { $$ = $pass; }
970 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
971 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
974 CoverParenthesizedExpressionAndArrowParameterList
975 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
976 | "(" LexOf ")" { $$ = NULL; }
977 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
978 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
981 /* 12.2.4 Literals {{{ */
983 : NullLiteral[pass] { $$ = $pass; }
984 | BooleanLiteral[pass] { $$ = $pass; }
985 | NumericLiteral[pass] { $$ = $pass; }
986 | StringLiteral[pass] { $$ = $pass; }
989 /* 12.2.5 Array Initializer {{{ */
991 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
995 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
996 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
997 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1001 : ElementList[pass] { $$ = $pass; }
1002 | LexOf { $$ = NULL; }
1005 /* 12.2.6 Object Initializer {{{ */
1007 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1010 PropertyDefinitionList_
1011 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1015 PropertyDefinitionList
1016 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1019 PropertyDefinitionListOpt
1020 : PropertyDefinitionList[properties] { $$ = $properties; }
1025 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1026 | CoverInitializedName[name] { CYNOT(@$); }
1027 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1028 | MethodDefinition[pass] { $$ = $pass; }
1032 : LiteralPropertyName[pass] { $$ = $pass; }
1033 | ComputedPropertyName[pass] { $$ = $pass; }
1037 : IdentifierName[pass] { $$ = $pass; }
1038 | StringLiteral[pass] { $$ = $pass; }
1039 | NumericLiteral[pass] { $$ = $pass; }
1042 ComputedPropertyName
1043 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1046 CoverInitializedName
1047 : IdentifierReference Initializer
1051 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1055 : Initializer[pass] { $$ = $pass; }
1059 /* 12.2.9 Template Literals {{{ */
1061 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1062 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1066 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1067 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1071 /* 12.3 Left-Hand-Side Expressions {{{ */
1073 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1074 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1075 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1076 | TemplateLiteral { CYNOT(@$); }
1080 : PrimaryExpression[pass] { $$ = $pass; }
1081 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1082 | SuperProperty[pass] { $$ = $pass; }
1083 | MetaProperty { CYNOT(@$); }
1084 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1088 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1089 | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1097 : "new" "." "target"
1101 : MemberExpression[pass] { $$ = $pass; }
1102 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1106 : MemberExpression[pass] { $$ = $pass; }
1107 | CallExpression[pass] { $$ = $pass; }
1111 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1112 | SuperCall[pass] { $$ = $pass; }
1113 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1117 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1121 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1125 : "," ArgumentList[arguments] { $$ = $arguments; }
1130 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1131 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1135 : ArgumentList[pass] { $$ = $pass; }
1136 | LexOf { $$ = NULL; }
1140 : NewExpression[pass] { $$ = $pass; }
1141 | CallExpression[pass] { $$ = $pass; }
1144 LeftHandSideExpression
1145 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
1146 | IndirectExpression[pass] { $$ = $pass; }
1149 /* 12.4 Postfix Expressions {{{ */
1151 : AccessExpression[lhs] LexNewLineOrOpt { $$ = $lhs; }
1152 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1153 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1156 /* 12.5 Unary Operators {{{ */
1158 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1159 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1160 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1161 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1162 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1163 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1164 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1165 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1166 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1170 : PostfixExpression[expression] { $$ = $expression; }
1171 | PostfixExpression[expression] "\n" { $$ = $expression; }
1172 | UnaryExpression_[pass] { $$ = $pass; }
1175 /* 12.6 Multiplicative Operators {{{ */
1176 MultiplicativeExpression
1177 : UnaryExpression[pass] { $$ = $pass; }
1178 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1179 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1180 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1183 /* 12.7 Additive Operators {{{ */
1185 : MultiplicativeExpression[pass] { $$ = $pass; }
1186 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1187 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1190 /* 12.8 Bitwise Shift Operators {{{ */
1192 : AdditiveExpression[pass] { $$ = $pass; }
1193 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1194 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1195 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1198 /* 12.9 Relational Operators {{{ */
1199 RelationalExpression
1200 : ShiftExpression[pass] { $$ = $pass; }
1201 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1202 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1203 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1204 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1205 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1206 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1209 /* 12.10 Equality Operators {{{ */
1211 : RelationalExpression[pass] { $$ = $pass; }
1212 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1213 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1214 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1215 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1218 /* 12.11 Binary Bitwise Operators {{{ */
1219 BitwiseANDExpression
1220 : EqualityExpression[pass] { $$ = $pass; }
1221 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1224 BitwiseXORExpression
1225 : BitwiseANDExpression[pass] { $$ = $pass; }
1226 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1230 : BitwiseXORExpression[pass] { $$ = $pass; }
1231 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1234 /* 12.12 Binary Logical Operators {{{ */
1235 LogicalANDExpression
1236 : BitwiseORExpression[pass] { $$ = $pass; }
1237 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1241 : LogicalANDExpression[pass] { $$ = $pass; }
1242 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1245 /* 12.13 Conditional Operator ( ? : ) {{{ */
1247 ConditionalExpressionClassic
1248 : LogicalORExpression[pass] { $$ = $pass; }
1249 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1253 ConditionalExpression
1254 : LogicalORExpression[pass] { $$ = $pass; }
1255 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1258 /* 12.14 Assignment Operators {{{ */
1259 LeftHandSideAssignment
1260 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1261 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1262 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1263 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1264 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1265 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1266 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1267 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1268 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1269 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1270 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1271 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1275 AssignmentExpressionClassic
1276 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1277 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1281 AssignmentExpression
1282 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1283 | LexOf YieldExpression[pass] { $$ = $pass; }
1284 | ArrowFunction[pass] { $$ = $pass; }
1285 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1288 AssignmentExpressionOpt
1289 : AssignmentExpression[pass] { $$ = $pass; }
1290 | LexOf { $$ = NULL; }
1293 /* 12.15 Comma Operator ( , ) {{{ */
1295 : AssignmentExpression[pass] { $$ = $pass; }
1296 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1300 : Expression[pass] { $$ = $pass; }
1301 | LexOf { $$ = NULL; }
1305 /* 13 Statements and Declarations {{{ */
1307 : BlockStatement[pass] { $$ = $pass; }
1308 | VariableStatement[pass] { $$ = $pass; }
1309 | EmptyStatement[pass] { $$ = $pass; }
1310 | IfStatement[pass] { $$ = $pass; }
1311 | BreakableStatement[pass] { $$ = $pass; }
1312 | ContinueStatement[pass] { $$ = $pass; }
1313 | BreakStatement[pass] { $$ = $pass; }
1314 | ReturnStatement[pass] { $$ = $pass; }
1315 | WithStatement[pass] { $$ = $pass; }
1316 | LabelledStatement[pass] { $$ = $pass; }
1317 | ThrowStatement[pass] { $$ = $pass; }
1318 | TryStatement[pass] { $$ = $pass; }
1319 | DebuggerStatement[pass] { $$ = $pass; }
1323 : LexOf Statement__[pass] { $$ = $pass; }
1324 | ExpressionStatement[pass] { $$ = $pass; }
1328 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1332 : HoistableDeclaration[pass] { $$ = $pass; }
1333 | ClassDeclaration[pass] { $$ = $pass; }
1337 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1338 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1341 HoistableDeclaration
1342 : FunctionDeclaration[pass] { $$ = $pass; }
1343 | GeneratorDeclaration[pass] { $$ = $pass; }
1347 : IterationStatement[pass] { $$ = $pass; }
1348 | SwitchStatement[pass] { $$ = $pass; }
1351 /* 13.2 Block {{{ */
1353 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1357 : "{" StatementListOpt[code] "}" { $$ = $code; }
1361 : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
1365 : StatementList[pass] { $$ = $pass; }
1366 | LexSetStatement LexLet LexOf { $$ = NULL; }
1370 : Statement[pass] { $$ = $pass; }
1371 | Declaration[pass] { $$ = $pass; }
1374 /* 13.3 Let and Const Declarations {{{ */
1376 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1380 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1384 : { CYMAP(_let__, _let_); }
1388 : { CYMAP(_of__, _of_); }
1392 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1396 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1397 | LexLet LexOf "const" { $$ = true; }
1401 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1406 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1410 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1411 | LexOf BindingPattern Initializer { CYNOT(@$); }
1414 /* 13.3.2 Variable Statement {{{ */
1416 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1420 : VariableStatement_[statement] Terminator { $$ = $statement; }
1423 VariableDeclarationList_
1424 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1428 VariableDeclarationList
1429 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1433 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1434 | LexOf BindingPattern Initializer { CYNOT(@$); }
1437 /* 13.3.3 Destructuring Binding Patterns {{{ */
1439 : ObjectBindingPattern
1440 | ArrayBindingPattern
1443 ObjectBindingPattern
1444 : "let {" BindingPropertyListOpt "}"
1448 : "let [" BindingElementListOpt "]"
1451 BindingPropertyList_
1452 : "," BindingPropertyListOpt
1457 : BindingProperty BindingPropertyList_
1460 BindingPropertyListOpt
1461 : BindingPropertyList
1466 : BindingElementOpt[element] "," BindingElementListOpt[next]
1467 | BindingRestElement[element]
1468 | BindingElement[element]
1471 BindingElementListOpt
1472 : BindingElementList[pass]
1478 | LexOf PropertyName ":" BindingElement
1482 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1483 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1487 : BindingElement[pass]
1492 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1496 : LexBind LexOf "..." BindingIdentifier
1499 /* 13.4 Empty Statement {{{ */
1501 : ";" { $$ = CYNew CYEmpty(); }
1504 /* 13.5 Expression Statement {{{ */
1505 ExpressionStatement_
1506 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1509 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1512 /* 13.6 The if Statement {{{ */
1514 : "else" Statement[false] { $$ = $false; }
1515 | %prec "if" { $$ = NULL; }
1519 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1522 /* 13.7 Iteration Statements {{{ */
1524 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1525 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1526 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1527 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1528 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1529 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1532 ForStatementInitializer
1533 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1534 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1535 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1536 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1539 ForInStatementInitializer
1540 : LexLet LexOf AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
1541 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1542 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1543 | ForDeclaration[pass] { $$ = $pass; }
1547 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1551 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1552 | LexOf BindingPattern { CYNOT(@$); }
1555 /* 13.8 The continue Statement {{{ */
1557 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1558 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1561 /* 13.9 The break Statement {{{ */
1563 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1564 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1567 /* 13.10 The return Statement {{{ */
1569 : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
1573 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1574 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1577 /* 13.11 The with Statement {{{ */
1579 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1582 /* 13.12 The switch Statement {{{ */
1584 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1588 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1592 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1596 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1597 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1601 // XXX: the standard makes certain you can only have one of these
1603 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1606 /* 13.13 Labelled Statements {{{ */
1608 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1612 : Statement[pass] { $$ = $pass; }
1613 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1616 /* 13.14 The throw Statement {{{ */
1618 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1619 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1622 /* 13.15 The try Statement {{{ */
1624 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1625 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1626 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1630 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1634 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1638 : BindingIdentifier[pass] { $$ = $pass; }
1639 | LexOf BindingPattern { CYNOT(@$); }
1642 /* 13.16 The debugger Statement {{{ */
1644 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1648 /* 14.1 Function Definitions {{{ */
1650 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1654 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1657 StrictFormalParameters
1658 : FormalParameters[pass] { $$ = $pass; }
1662 : LexBind LexOf { $$ = NULL; }
1663 | FormalParameterList
1666 FormalParameterList_
1667 : "," FormalParameterList[parameters] { $$ = $parameters; }
1672 : FunctionRestParameter { CYNOT(@$); }
1673 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1676 FunctionRestParameter
1677 : BindingRestElement
1681 : BindingElement[pass] { $$ = $pass; }
1685 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1688 FunctionStatementList
1689 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1692 /* 14.2 Arrow Function Definitions {{{ */
1694 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1698 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1699 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1703 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1704 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1707 /* 14.3 Method Definitions {{{ */
1709 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1710 | GeneratorMethod[pass] { $$ = $pass; }
1711 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1712 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1715 PropertySetParameterList
1716 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1719 /* 14.4 Generator Function Definitions {{{ */
1721 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1724 GeneratorDeclaration
1725 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1729 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1733 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1737 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1738 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1739 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1740 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1743 /* 14.5 Class Definitions {{{ */
1745 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1749 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1753 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1757 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1761 : ClassHeritage[pass] { $$ = $pass; }
1762 | { $$ = CYNew CYClassTail(NULL); }
1775 : ClassElementListOpt ClassElement
1784 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1785 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1790 /* 15.1 Scripts {{{ */
1792 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1796 : StatementList[pass] { $$ = $pass; }
1800 : ScriptBody[pass] { $$ = $pass; }
1801 | LexSetStatement LexLet LexOf { $$ = NULL; }
1804 /* 15.2 Modules {{{ */
1819 : ModuleItemListOpt ModuleItem
1828 : LexSetStatement LexLet LexOf ImportDeclaration
1829 | LexSetStatement LexLet LexOf ExportDeclaration
1833 /* 15.2.2 Imports {{{ */
1835 : "import" ImportClause FromClause Terminator
1836 | "import" LexOf ModuleSpecifier Terminator
1840 : ImportedDefaultBinding
1841 | LexOf NameSpaceImport
1842 | LexOf NamedImports
1843 | ImportedDefaultBinding "," NameSpaceImport
1844 | ImportedDefaultBinding "," NamedImports
1847 ImportedDefaultBinding
1852 : "*" "as" ImportedBinding
1856 : "{" ImportsListOpt "}"
1860 : "from" ModuleSpecifier
1864 : "," ImportsListOpt
1869 : ImportSpecifier ImportsList_
1879 | LexOf IdentifierName "as" ImportedBinding
1890 /* 15.2.3 Exports {{{ */
1892 : "*" FromClause Terminator
1893 | ExportClause FromClause Terminator
1894 | ExportClause Terminator
1896 | "default" LexSetStatement LexOf HoistableDeclaration
1897 | "default" LexSetStatement LexOf ClassDeclaration
1898 | "default" LexSetStatement AssignmentExpression Terminator
1902 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1903 | "export" Declaration
1907 : ";{" ExportsListOpt "}"
1911 : "," ExportsListOpt
1916 : ExportSpecifier ExportsList_
1926 | IdentifierName "as" IdentifierName
1931 /* Cycript (C): Type Encoding {{{ */
1933 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1934 | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; }
1938 : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1939 | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1940 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1941 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1942 | TypeSignifier[pass] { $$ = $pass; }
1943 | { $$ = CYNew CYTypedIdentifier(@$); }
1947 : "*" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1952 | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1953 | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1957 : PrefixedType[pass] { $$ = $pass; }
1958 | SuffixedType[pass] { $$ = $pass; }
1959 | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1960 | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1964 : "int" { $$ = CYNew CYTypeVariable("int"); }
1965 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
1966 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
1967 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
1968 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
1972 : IntegerType[pass] { $$ = $pass; }
1973 | { $$ = CYNew CYTypeVariable("int"); }
1977 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
1978 | IntegerType[pass] { $$ = $pass; }
1979 | "void" { $$ = CYNew CYTypeVoid(); }
1980 | "char" { $$ = CYNew CYTypeVariable("char"); }
1981 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1982 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1986 : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
1990 : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
1996 /* Cycript (Objective-C): @class Declaration {{{ */
1998 /* XXX: why the hell did I choose MemberExpression? */
1999 : ":" MemberExpression[extends] { $$ = $extends; }
2003 ImplementationFieldListOpt
2004 : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2008 ImplementationFields
2009 : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
2013 : "+" { $$ = false; }
2014 | "-" { $$ = true; }
2018 : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
2019 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2023 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2026 MessageParameterList
2027 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2030 MessageParameterListOpt
2031 : MessageParameterList[pass] { $$ = $pass; }
2036 : MessageParameterList[pass] { $$ = $pass; }
2037 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2040 ClassMessageDeclaration
2041 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2044 ClassMessageDeclarationListOpt
2045 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2049 // XXX: this should be AssignmentExpressionNoRight
2051 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2055 : "," ClassProtocols[protocols] { $$ = $protocols; }
2059 ClassProtocolListOpt
2060 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2064 ImplementationStatement
2065 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2073 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2077 : ImplementationStatement[pass] { $$ = $pass; }
2078 | CategoryStatement[pass] { $$ = $pass; }
2081 /* Cycript (Objective-C): Send Message {{{ */
2083 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2088 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2089 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2093 : SelectorCall[pass] { $$ = $pass; }
2094 | VariadicCall[pass] { $$ = $pass; }
2098 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2102 : SelectorCall[pass] { $$ = $pass; }
2103 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2107 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2108 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2112 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2116 : SelectorExpression_[pass] { $$ = $pass; }
2117 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2120 SelectorExpressionOpt
2121 : SelectorExpression_[pass] { $$ = $pass; }
2126 : MessageExpression[pass] { $$ = $pass; }
2127 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2132 /* Cycript: @import Directive {{{ */
2134 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2135 | Word[part] { $$ = CYNew CYModule($part); }
2139 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2144 /* Cycript (Objective-C): Boxed Expressions {{{ */
2146 : NullLiteral[pass] { $$ = $pass; }
2147 | BooleanLiteral[pass] { $$ = $pass; }
2148 | NumericLiteral[pass] { $$ = $pass; }
2149 | StringLiteral[pass] { $$ = $pass; }
2150 | ArrayLiteral[pass] { $$ = $pass; }
2151 | ObjectLiteral[pass] { $$ = $pass; }
2152 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2153 | "YES" { $$ = CYNew CYTrue(); }
2154 | "NO" { $$ = CYNew CYFalse(); }
2158 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2159 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2160 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2161 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2162 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2163 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2166 /* Cycript (Objective-C): Block Expressions {{{ */
2168 : "^" TypedIdentifier[type] { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); } "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2171 /* Cycript (Objective-C): Instance Literals {{{ */
2173 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2179 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2181 : IndirectExpression[pass] { $$ = $pass; }
2185 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2189 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2193 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2194 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2195 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2198 /* Cycript (C): Lambda Expressions {{{ */
2200 : "," TypedParameterList[parameters] { $$ = $parameters; }
2205 : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2208 TypedParameterListOpt
2209 : TypedParameterList[pass] { $$ = $pass; }
2214 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2217 /* Cycript (C): Type Definitions {{{ */
2219 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2223 : "typedef" NewLineNot TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
2226 /* Cycript (C): extern "C" {{{ */
2228 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2232 : "extern" NewLineNot 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); }
2239 /* Lexer State {{{ */
2241 : { driver.PushCondition(CYDriver::RegExpCondition); }
2245 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2249 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2253 : { driver.PopCondition(); }
2257 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2261 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2264 /* Virtual Tokens {{{ */
2271 /* 8.1 Context Keywords {{{ */
2273 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2274 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2277 /* 8.3 XML Initializer Input Elements {{{ */
2279 : XMLComment { $$ = $1; }
2280 | XMLCDATA { $$ = $1; }
2281 | XMLPI { $$ = $1; }
2285 /* 11.1 Primary Expressions {{{ */
2287 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2288 | XMLInitilizer { $$ = $1; }
2289 | XMLListInitilizer { $$ = $1; }
2293 : AttributeIdentifier { $$ = $1; }
2294 | QualifiedIdentifier { $$ = $1; }
2295 | WildcardIdentifier { $$ = $1; }
2298 /* 11.1.1 Attribute Identifiers {{{ */
2300 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2304 : PropertySelector { $$ = $1; }
2305 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2309 : Identifier { $$ = CYNew CYSelector($1); }
2310 | WildcardIdentifier { $$ = $1; }
2313 /* 11.1.2 Qualified Identifiers {{{ */
2314 QualifiedIdentifier_
2315 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2316 | QualifiedIdentifier { $$ = $1; }
2320 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2323 /* 11.1.3 Wildcard Identifiers {{{ */
2325 : "*" { $$ = CYNew CYWildcard(); }
2328 /* 11.1.4 XML Initializer {{{ */
2330 : XMLMarkup { $$ = $1; }
2331 | XMLElement { $$ = $1; }
2335 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2336 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2340 : LexPushXMLTag XMLTagName XMLAttributes
2344 : "{" LexPushRegExp Expression LexPop "}"
2353 : XMLAttributes_ XMLAttribute
2358 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2359 | XMLAttributes_ XMLWhitespaceOpt
2368 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2372 : XMLExpression XMLElementContentOpt
2373 | XMLMarkup XMLElementContentOpt
2374 | XMLText XMLElementContentOpt
2375 | XMLElement XMLElementContentOpt
2378 XMLElementContentOpt
2383 /* 11.1.5 XMLList Initializer {{{ */
2385 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2389 /* 11.2 Left-Hand-Side Expressions {{{ */
2391 : Identifier { $$ = $1; }
2392 | PropertyIdentifier { $$ = $1; }
2396 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2397 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2398 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2401 /* 12.1 The default xml namespace Statement {{{ */
2402 /* XXX: DefaultXMLNamespaceStatement
2403 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2407 : DefaultXMLNamespaceStatement { $$ = $1; }
2412 /* JavaScript FTL: Array Comprehensions {{{ */
2414 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2418 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2421 /* JavaScript FTL: for each {{{ */
2423 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2427 /* JavaScript FTW: Array Comprehensions {{{ */
2429 : ArrayComprehension
2433 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2437 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2442 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2443 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2447 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2448 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2452 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2455 /* JavaScript FTW: Coalesce Operator {{{ */
2456 ConditionalExpression
2457 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2460 /* JavaScript FTW: Named Arguments {{{ */
2462 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2465 /* JavaScript FTW: Ruby Blocks {{{ */
2466 RubyProcParameterList_
2467 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2471 RubyProcParameterList
2472 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2473 | LexOf { $$ = NULL; }
2477 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2478 | "||" { $$ = NULL; }
2481 RubyProcParametersOpt
2482 : RubyProcParameters[pass] { $$ = $pass; }
2487 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2491 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2495 : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2501 bool CYDriver::Parse(CYMark mark) {
2503 CYLocal<CYPool> local(&pool_);
2504 cy::parser parser(*this);
2506 parser.set_debug_level(debug_);
2508 return parser.parse() != 0;
2511 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2515 CYDriver::Error error;
2516 error.warning_ = true;
2517 error.location_ = location;
2518 error.message_ = message;
2519 errors_.push_back(error);
2522 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2523 CYDriver::Error error;
2524 error.warning_ = false;
2525 error.location_ = location;
2526 error.message_ = message;
2527 driver.errors_.push_back(error);