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 cyscanner driver.scanner_
24 #define YYSTACKEXPANDABLE 1
31 #define CYNew new(driver.pool_)
34 #include "ObjectiveC/Syntax.hpp"
38 #include "E4X/Syntax.hpp"
41 #include "Highlight.hpp"
44 %union { bool bool_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBoolean *boolean_; }
49 %union { CYClause *clause_; }
50 %union { cy::Syntax::Catch *catch_; }
51 %union { CYComprehension *comprehension_; }
52 %union { CYDeclaration *declaration_; }
53 %union { CYDeclarations *declarations_; }
54 %union { CYElement *element_; }
55 %union { CYExpression *expression_; }
56 %union { CYFalse *false_; }
57 %union { CYFinally *finally_; }
58 %union { CYForInitializer *for_; }
59 %union { CYForInInitializer *forin_; }
60 %union { CYFunctionParameter *functionParameter_; }
61 %union { CYIdentifier *identifier_; }
62 %union { CYInfix *infix_; }
63 %union { CYLiteral *literal_; }
64 %union { CYMember *member_; }
65 %union { CYModule *module_; }
66 %union { CYNull *null_; }
67 %union { CYNumber *number_; }
68 %union { CYParenthetical *parenthetical_; }
69 %union { CYProperty *property_; }
70 %union { CYPropertyName *propertyName_; }
71 %union { CYRubyProc *rubyProc_; }
72 %union { CYSpan *span_; }
73 %union { CYStatement *statement_; }
74 %union { CYString *string_; }
75 %union { CYThis *this_; }
76 %union { CYTrue *true_; }
77 %union { CYWord *word_; }
80 %union { CYTypeModifier *modifier_; }
81 %union { CYTypeSpecifier *specifier_; }
82 %union { CYTypedIdentifier *typedIdentifier_; }
83 %union { CYTypedParameter *typedParameter_; }
87 %union { CYClassName *className_; }
88 %union { CYClassField *classField_; }
89 %union { CYMessage *message_; }
90 %union { CYMessageParameter *messageParameter_; }
91 %union { CYProtocol *protocol_; }
92 %union { CYSelectorPart *selector_; }
96 %union { CYAttribute *attribute_; }
97 %union { CYPropertyIdentifier *propertyIdentifier_; }
98 %union { CYSelector *selector_; }
104 cy::parser::semantic_type semantic_;
105 hi::Value highlight_;
108 int cylex(YYSTYPE *, CYLocation *, void *);
115 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, void *scanner) {
117 int token(cylex(&data, location, scanner));
118 *semantic = data.semantic_;
122 #define CYMAP(to, from) do { \
124 yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, cyscanner)); \
125 if (yyla.type == yytranslate_(token::from)) \
126 yyla.type = yytranslate_(token::to); \
136 @$.begin.filename = @$.end.filename = &driver.filename_;
142 %define api.location.type { CYLocation }
149 %parse-param { CYDriver &driver }
150 %lex-param { void *cyscanner }
152 /* Token Declarations {{{ */
158 %token XMLAttributeValue
160 %token XMLTagCharacters
166 %token LeftRight "<>"
167 %token LeftSlashRight "</>"
169 %token SlashRight "/>"
170 %token LeftSlash "</"
172 %token ColonColon "::"
173 %token PeriodPeriod ".."
176 @begin E4X ObjectiveC
182 %token AmpersandAmpersand "&&"
183 %token AmpersandEqual "&="
185 %token CarrotEqual "^="
187 %token EqualEqual "=="
188 %token EqualEqualEqual "==="
189 %token EqualRight "=>"
190 %token EqualRight_ "\n=>"
191 %token Exclamation "!"
192 %token ExclamationEqual "!="
193 %token ExclamationEqualEqual "!=="
195 %token HyphenEqual "-="
196 %token HyphenHyphen "--"
197 %token HyphenHyphen_ "\n--"
198 %token HyphenRight "->"
200 %token LeftEqual "<="
202 %token LeftLeftEqual "<<="
204 %token PercentEqual "%="
206 %token PeriodPeriodPeriod "..."
208 %token PipeEqual "|="
211 %token PlusEqual "+="
213 %token PlusPlus_ "\n++"
215 %token RightEqual ">="
216 %token RightRight ">>"
217 %token RightRightEqual ">>="
218 %token RightRightRight ">>>"
219 %token RightRightRightEqual ">>>="
221 %token SlashEqual "/="
223 %token StarEqual "*="
235 %token CloseParen ")"
238 %token OpenBrace_ "\n{"
239 %token OpenBrace__ ";{"
240 %token CloseBrace "}"
242 %token OpenBracket "["
243 %token CloseBracket "]"
245 %token At_error_ "@error"
248 %token At_class_ "@class"
252 %token _typedef_ "typedef"
253 %token _unsigned_ "unsigned"
254 %token _signed_ "signed"
255 %token _extern_ "extern"
259 %token At_encode_ "@encode"
263 %token At_implementation_ "@implementation"
264 %token At_import_ "@import"
265 %token At_end_ "@end"
266 %token At_selector_ "@selector"
267 %token At_null_ "@null"
268 %token At_YES_ "@YES"
270 %token At_true_ "@true"
271 %token At_false_ "@false"
276 %token _false_ "false"
280 %token _break_ "break"
282 %token _catch_ "catch"
283 %token _class_ "class"
284 %token _class__ "!class"
285 %token _const_ "const"
286 %token _continue_ "continue"
287 %token _debugger_ "debugger"
288 %token _default_ "default"
289 %token _delete_ "delete"
293 %token _export_ "export"
294 %token _extends_ "extends"
295 %token _finally_ "finally"
297 %token _function_ "function"
298 %token _function__ ";function"
300 %token _import_ "import"
303 %token _instanceof_ "instanceof"
305 %token _return_ "return"
306 %token _super_ "super"
307 %token _switch_ "switch"
309 %token _throw_ "throw"
311 %token _typeof_ "typeof"
314 %token _while_ "while"
317 %token _abstract_ "abstract"
318 %token _await_ "await"
319 %token _boolean_ "boolean"
322 %token _double_ "double"
323 %token _final_ "final"
324 %token _float_ "float"
326 %token _implements_ "implements"
328 %token _interface_ "interface"
331 %token _native_ "native"
332 %token _package_ "package"
333 %token _private_ "private"
334 %token _protected_ "protected"
335 %token _public_ "public"
336 %token _short_ "short"
337 %token _static_ "static"
338 %token _synchronized_ "synchronized"
339 %token _throws_ "throws"
340 %token _transient_ "transient"
341 %token _volatile_ "volatile"
342 %token _yield_ "yield"
344 %token _undefined_ "undefined"
360 %token _namespace_ "namespace"
366 %token <identifier_> Identifier_
367 %token <number_> NumericLiteral
368 %token <string_> StringLiteral
369 %token <literal_> RegularExpressionLiteral
371 %token <string_> NoSubstitutionTemplate
372 %token <string_> TemplateHead
373 %token <string_> TemplateMiddle
374 %token <string_> TemplateTail
376 %type <expression_> AdditiveExpression
377 %type <argument_> ArgumentList_
378 %type <argument_> ArgumentList
379 %type <argument_> ArgumentListOpt
380 %type <argument_> Arguments
381 %type <expression_> ArrayComprehension
382 %type <literal_> ArrayLiteral
383 %type <expression_> ArrowFunction
384 %type <functionParameter_> ArrowParameters
385 %type <expression_> AssignmentExpression
386 %type <expression_> AssignmentExpressionOpt
387 %type <identifier_> Binding
388 %type <identifier_> BindingIdentifier
389 %type <expression_> BitwiseANDExpression
390 %type <statement_> Block
391 %type <statement_> BlockStatement
392 %type <boolean_> BooleanLiteral
393 %type <declaration_> BindingElement
394 %type <expression_> BitwiseORExpression
395 %type <expression_> BitwiseXORExpression
396 %type <statement_> BreakStatement
397 %type <statement_> BreakableStatement
398 %type <expression_> CallExpression_
399 %type <expression_> CallExpression
400 %type <clause_> CaseBlock
401 %type <clause_> CaseClause
402 %type <clause_> CaseClausesOpt
404 %type <identifier_> CatchParameter
405 %type <expression_> Comprehension
406 %type <comprehension_> ComprehensionFor
407 %type <comprehension_> ComprehensionIf
408 %type <comprehension_> ComprehensionTail
409 %type <expression_> ConditionalExpression
410 %type <statement_> ContinueStatement
411 %type <statement_> ConciseBody
412 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
413 %type <statement_> DebuggerStatement
414 %type <statement_> Declaration__
415 %type <statement_> Declaration_
416 %type <statement_> Declaration
417 %type <clause_> DefaultClause
418 %type <element_> ElementList
419 %type <element_> ElementListOpt
420 %type <statement_> ElseStatementOpt
421 %type <statement_> EmptyStatement
422 %type <expression_> EqualityExpression
423 %type <expression_> Expression
424 %type <expression_> ExpressionOpt
425 %type <statement_> ExpressionStatement
426 %type <finally_> Finally
427 %type <for_> ForStatementInitializer
428 %type <forin_> ForInStatementInitializer
429 %type <declaration_> FormalParameter
430 %type <functionParameter_> FormalParameterList_
431 %type <functionParameter_> FormalParameterList
432 %type <functionParameter_> FormalParameterListOpt
433 %type <statement_> FunctionBody
434 %type <statement_> FunctionDeclaration
435 %type <expression_> FunctionExpression
436 %type <statement_> HoistableDeclaration
437 %type <identifier_> Identifier
438 %type <identifier_> IdentifierOpt
439 %type <identifier_> IdentifierType
440 %type <word_> IdentifierName
441 %type <expression_> IdentifierReference
442 %type <statement_> IfStatement
443 %type <expression_> Initializer
444 %type <expression_> InitializerOpt
445 %type <statement_> IterationStatement
446 %type <identifier_> LabelIdentifier
447 %type <statement_> LabelledItem
448 %type <statement_> LabelledStatement
449 %type <expression_> LeftHandSideExpression
450 %type <statement_> LetStatement
451 %type <statement_> LexicalDeclaration
452 %type <literal_> Literal
453 %type <expression_> LogicalANDExpression
454 %type <expression_> LogicalORExpression
455 %type <member_> MemberAccess
456 %type <expression_> MemberExpression_
457 %type <expression_> MemberExpression
458 %type <module_> Module
459 %type <expression_> MultiplicativeExpression
460 %type <expression_> NewExpression
461 %type <null_> NullLiteral
462 %type <literal_> ObjectLiteral
463 %type <expression_> PostfixExpression
464 %type <expression_> PrimaryExpression
465 %type <propertyName_> PropertyName_
466 %type <propertyName_> PropertyName
467 %type <property_> PropertyDefinition
468 %type <property_> PropertyDefinitionList_
469 %type <property_> PropertyDefinitionList
470 %type <property_> PropertyDefinitionListOpt
471 %type <expression_> RelationalExpression
472 %type <statement_> ReturnStatement
473 %type <rubyProc_> RubyProcExpression
474 %type <functionParameter_> RubyProcParameterList_
475 %type <functionParameter_> RubyProcParameterList
476 %type <functionParameter_> RubyProcParameters
477 %type <functionParameter_> RubyProcParametersOpt
478 %type <statement_> Script
479 %type <statement_> ScriptBody
480 %type <statement_> ScriptBodyOpt
481 %type <expression_> ShiftExpression
482 %type <declaration_> SingleNameBinding
483 %type <statement_> Statement__
484 %type <statement_> Statement_
485 %type <statement_> Statement
486 %type <statement_> StatementList
487 %type <statement_> StatementListOpt
488 %type <statement_> StatementListItem
489 %type <statement_> SwitchStatement
490 %type <expression_> TemplateLiteral
491 %type <span_> TemplateSpans
492 %type <statement_> ThrowStatement
493 %type <statement_> TryStatement
494 %type <expression_> UnaryExpression_
495 %type <expression_> UnaryExpression
496 %type <declaration_> VariableDeclaration
497 %type <declarations_> VariableDeclarationList_
498 %type <declarations_> VariableDeclarationList
499 %type <statement_> VariableStatement
500 %type <statement_> WithStatement
503 %type <word_> WordOpt
507 %type <specifier_> IntegerType
508 %type <specifier_> IntegerTypeOpt
509 %type <typedIdentifier_> PrefixedType
510 %type <specifier_> PrimitiveType
511 %type <typedIdentifier_> SuffixedType
512 %type <typedIdentifier_> TypeSignifier
513 %type <modifier_> TypeQualifierLeft
514 %type <typedIdentifier_> TypeQualifierRight
515 %type <typedIdentifier_> TypedIdentifier
516 %type <typedParameter_> TypedParameterList_
517 %type <typedParameter_> TypedParameterList
518 %type <typedParameter_> TypedParameterListOpt
522 %type <expression_> BoxableExpression
523 %type <statement_> CategoryStatement
524 %type <classField_> ClassFieldListOpt
525 %type <classField_> ClassFields
526 %type <statement_> ClassStatement
527 %type <expression_> ClassSuperOpt
528 %type <message_> ClassMessageDeclaration
529 %type <message_> ClassMessageDeclarationListOpt
530 %type <className_> ClassName
531 %type <protocol_> ClassProtocolListOpt
532 %type <protocol_> ClassProtocols
533 %type <protocol_> ClassProtocolsOpt
534 %type <expression_> MessageExpression
535 %type <messageParameter_> MessageParameter
536 %type <messageParameter_> MessageParameters
537 %type <messageParameter_> MessageParameterList
538 %type <messageParameter_> MessageParameterListOpt
539 %type <bool_> MessageScope
540 %type <argument_> SelectorCall_
541 %type <argument_> SelectorCall
542 %type <selector_> SelectorExpression_
543 %type <selector_> SelectorExpression
544 %type <selector_> SelectorExpressionOpt
545 %type <argument_> SelectorList
546 %type <word_> SelectorWordOpt
547 %type <typedIdentifier_> TypeOpt
548 %type <argument_> VariadicCall
552 %type <propertyIdentifier_> PropertyIdentifier_
553 %type <selector_> PropertySelector_
554 %type <selector_> PropertySelector
555 %type <identifier_> QualifiedIdentifier_
556 %type <identifier_> QualifiedIdentifier
557 %type <identifier_> WildcardIdentifier
558 %type <identifier_> XMLComment
559 %type <identifier_> XMLCDATA
560 %type <identifier_> XMLElement
561 %type <identifier_> XMLElementContent
562 %type <identifier_> XMLMarkup
563 %type <identifier_> XMLPI
565 %type <attribute_> AttributeIdentifier
566 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
567 %type <expression_> PropertyIdentifier
568 %type <expression_> XMLListInitialiser
569 %type <expression_> XMLInitialiser
572 /* Token Priorities {{{ */
584 /* Lexer State {{{ */
586 : { driver.in_.push(true); }
590 : { driver.in_.push(false); }
594 : { driver.in_.pop(); }
598 : { driver.SetCondition(CYDriver::RegExpCondition); }
602 : { if (!yyla.empty() && yyla.type_get() != yyeof_) error(@$, "unexpected lookahead"); driver.next_ = true; }
606 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
610 : { CYMAP(_class__, _class_); }
614 : { CYMAP(_function__, _function_); }
618 : LexNoBrace LexNoClass LexNoFunction
621 /* Virtual Tokens {{{ */
632 /* 11.6 Names and Keywords {{{ */
635 | "for" { $$ = CYNew CYWord("for"); }
636 | "in" { $$ = CYNew CYWord("in"); }
637 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
641 : Identifier { $$ = $1; }
642 | "auto" { $$ = CYNew CYWord("auto"); }
643 | "break" { $$ = CYNew CYWord("break"); }
644 | "case" { $$ = CYNew CYWord("case"); }
645 | "catch" { $$ = CYNew CYWord("catch"); }
646 | "class" { $$ = CYNew CYWord("class"); }
647 | "!class" { $$ = CYNew CYWord("class"); }
648 | "const" { $$ = CYNew CYWord("const"); }
649 | "continue" { $$ = CYNew CYWord("continue"); }
650 | "debugger" { $$ = CYNew CYWord("debugger"); }
651 | "default" { $$ = CYNew CYWord("default"); }
652 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
653 | "do" { $$ = CYNew CYWord("do"); }
654 | "else" { $$ = CYNew CYWord("else"); }
655 | "enum" { $$ = CYNew CYWord("enum"); }
656 | "export" { $$ = CYNew CYWord("export"); }
657 | "extends" { $$ = CYNew CYWord("extends"); }
658 | "false" { $$ = CYNew CYWord("false"); }
659 | "finally" { $$ = CYNew CYWord("finally"); }
660 | "function" { $$ = CYNew CYWord("function"); }
661 | "if" { $$ = CYNew CYWord("if"); }
662 | "import" { $$ = CYNew CYWord("import"); }
663 | "!in" { $$ = CYNew CYWord("in"); }
664 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
665 | "null" { $$ = CYNew CYWord("null"); }
666 | "return" { $$ = CYNew CYWord("return"); }
667 | "super" { $$ = CYNew CYWord("super"); }
668 | "switch" { $$ = CYNew CYWord("switch"); }
669 | "this" { $$ = CYNew CYWord("this"); }
670 | "throw" { $$ = CYNew CYWord("throw"); }
671 | "true" { $$ = CYNew CYWord("true"); }
672 | "try" { $$ = CYNew CYWord("try"); }
673 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
674 | "var" { $$ = CYNew CYWord("var"); }
675 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
676 | "while" { $$ = CYNew CYWord("while"); }
677 | "with" { $$ = CYNew CYWord("with"); }
679 // XXX: should be Identifier
680 | "let" { $$ = CYNew CYIdentifier("let"); }
690 /* 11.8.1 Null Literals {{{ */
692 : "null" { $$ = CYNew CYNull(); }
695 /* 11.8.2 Boolean Literals {{{ */
697 : "true" { $$ = CYNew CYTrue(); }
698 | "false" { $$ = CYNew CYFalse(); }
702 /* 11.9 Automatic Semicolon Insertion {{{ */
704 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
714 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
719 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
723 /* 12.1 Identifiers {{{ */
725 : Identifier { $$ = CYNew CYVariable($1); }
730 : Identifier { $$ = $1; }
735 : Identifier { $$ = $1; }
740 : Identifier_ { $$ = $1; }
741 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
742 | "await" { $$ = CYNew CYIdentifier("await"); }
743 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
744 | "byte" { $$ = CYNew CYIdentifier("byte"); }
745 | "double" { $$ = CYNew CYIdentifier("double"); }
746 | "each" { $$ = CYNew CYIdentifier("each"); }
747 | "final" { $$ = CYNew CYIdentifier("final"); }
748 | "float" { $$ = CYNew CYIdentifier("float"); }
749 | "goto" { $$ = CYNew CYIdentifier("goto"); }
750 | "implements" { $$ = CYNew CYIdentifier("implements"); }
751 | "interface" { $$ = CYNew CYIdentifier("interface"); }
752 | "native" { $$ = CYNew CYIdentifier("native"); }
753 | "of" { $$ = CYNew CYIdentifier("of"); }
754 | "package" { $$ = CYNew CYIdentifier("package"); }
755 | "private" { $$ = CYNew CYIdentifier("private"); }
756 | "protected" { $$ = CYNew CYIdentifier("protected"); }
757 | "public" { $$ = CYNew CYIdentifier("public"); }
758 | "static" { $$ = CYNew CYIdentifier("static"); }
759 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
760 | "throws" { $$ = CYNew CYIdentifier("throws"); }
761 | "transient" { $$ = CYNew CYIdentifier("transient"); }
762 | "yield" { $$ = CYNew CYIdentifier("yield"); }
764 | "bool" { $$ = CYNew CYIdentifier("bool"); }
765 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
766 | "id" { $$ = CYNew CYIdentifier("id"); }
767 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
773 | "char" { $$ = CYNew CYIdentifier("char"); }
774 | "int" { $$ = CYNew CYIdentifier("int"); }
775 | "long" { $$ = CYNew CYIdentifier("long"); }
776 | "short" { $$ = CYNew CYIdentifier("short"); }
777 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
778 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
780 | "extern" { $$ = CYNew CYIdentifier("extern"); }
781 | "signed" { $$ = CYNew CYIdentifier("signed"); }
782 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
783 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
786 | "nil" { $$ = CYNew CYIdentifier("nil"); }
787 | "NO" { $$ = CYNew CYIdentifier("NO"); }
788 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
789 | "YES" { $$ = CYNew CYIdentifier("YES"); }
794 : Identifier { $$ = $1; }
798 /* 12.2 Primary Expression {{{ */
800 : "this" { $$ = CYNew CYThis(); }
801 | IdentifierReference { $$ = $1; }
802 | Literal { $$ = $1; }
803 | ArrayLiteral { $$ = $1; }
804 | ObjectLiteral { $$ = $1; }
805 | RegularExpressionLiteral { $$ = $1; }
806 | TemplateLiteral { $$ = $1; }
807 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) error(@1, "invalid parenthetical"); $$ = $1; }
808 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
811 CoverParenthesizedExpressionAndArrowParameterList
812 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
813 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
816 /* 12.2.4 Literals {{{ */
818 : NullLiteral { $$ = $1; }
819 | BooleanLiteral { $$ = $1; }
820 | NumericLiteral { $$ = $1; }
821 | StringLiteral { $$ = $1; }
824 /* 12.2.5 Array Initializer {{{ */
826 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
830 : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
831 | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
832 | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
836 : ElementList { $$ = $1; }
837 | LexSetRegExp { $$ = NULL; }
840 /* 12.2.6 Object Initializer {{{ */
842 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
845 PropertyDefinitionList_
846 : "," PropertyDefinitionList { $$ = $2; }
847 | "," LexSetRegExp { $$ = NULL; }
851 PropertyDefinitionList
852 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
855 PropertyDefinitionListOpt
856 : PropertyDefinitionList { $$ = $1; }
857 | LexSetRegExp { $$ = NULL; }
861 // XXX: this should be IdentifierName
862 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
863 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
868 : IdentifierName { $$ = $1; }
869 | StringLiteral { $$ = $1; }
870 | NumericLiteral { $$ = $1; }
874 : LexSetRegExp PropertyName_ { $$ = $2; }
879 : "=" AssignmentExpression { $$ = $2; }
883 : Initializer { $$ = $1; }
887 /* 12.2.9 Template Literals {{{ */
889 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
890 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
894 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
895 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
899 /* 12.3+ Left-Hand-Side Expressions {{{ */
901 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
902 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
903 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
907 : MemberExpression { $$ = $1; }
908 //| "super" { $$ = $1; }
912 : LexSetRegExp PrimaryExpression { $$ = $2; }
913 | LexSetRegExp FunctionExpression { $$ = $2; }
914 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
915 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
919 : MemberExpression { $$ = $1; }
920 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
929 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
930 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
934 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
938 : "," ArgumentList { $$ = $2; }
943 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
944 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
948 : ArgumentList { $$ = $1; }
949 | LexSetRegExp { $$ = NULL; }
952 LeftHandSideExpression
953 : NewExpression { $$ = $1; }
954 | CallExpression { $$ = $1; }
957 /* 12.4 Postfix Expressions {{{ */
959 : %prec "" LeftHandSideExpression { $$ = $1; }
960 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
961 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
964 /* 12.5 Unary Operators {{{ */
966 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
967 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
968 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
969 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
970 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
971 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
972 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
973 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
974 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
975 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
976 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
980 : PostfixExpression { $$ = $1; }
981 | LexSetRegExp UnaryExpression_ { $$ = $2; }
984 /* 12.6 Multiplicative Operators {{{ */
985 MultiplicativeExpression
986 : UnaryExpression { $$ = $1; }
987 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
988 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
989 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
992 /* 12.7 Additive Operators {{{ */
994 : MultiplicativeExpression { $$ = $1; }
995 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
996 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
999 /* 12.8 Bitwise Shift Operators {{{ */
1001 : AdditiveExpression { $$ = $1; }
1002 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1003 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1004 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1007 /* 12.9 Relational Operators {{{ */
1008 RelationalExpression
1009 : ShiftExpression { $$ = $1; }
1010 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1011 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1012 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1013 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1014 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1015 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1018 /* 12.10 Equality Operators {{{ */
1020 : RelationalExpression { $$ = $1; }
1021 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1022 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1023 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1024 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1027 /* 12.11 Binary Bitwise Operators {{{ */
1028 BitwiseANDExpression
1029 : EqualityExpression { $$ = $1; }
1030 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1033 BitwiseXORExpression
1034 : BitwiseANDExpression { $$ = $1; }
1035 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1039 : BitwiseXORExpression { $$ = $1; }
1040 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1043 /* 12.12 Binary Logical Operators {{{ */
1044 LogicalANDExpression
1045 : BitwiseORExpression { $$ = $1; }
1046 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1050 : LogicalANDExpression { $$ = $1; }
1051 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1054 /* 12.13 Conditional Operator ( ? : ) {{{ */
1055 ConditionalExpression
1056 : LogicalORExpression { $$ = $1; }
1057 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1060 /* 12.14 Assignment Operators {{{ */
1061 AssignmentExpression
1062 : ConditionalExpression { $$ = $1; }
1063 // XXX: | YieldExpression { $$ = $1; }
1064 | ArrowFunction { $$ = $1; }
1065 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1066 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1067 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1068 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1069 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1070 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1071 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1072 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1073 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1074 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1075 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1076 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1079 AssignmentExpressionOpt
1080 : AssignmentExpression { $$ = $1; }
1081 | LexSetRegExp { $$ = NULL; }
1084 /* 12.15 Comma Operator ( , ) {{{ */
1086 : AssignmentExpression { $$ = $1; }
1087 /* XXX: I have this backwards... */
1088 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1092 : Expression { $$ = $1; }
1093 | LexSetRegExp { $$ = NULL; }
1097 /* 13 Statements and Declarations {{{ */
1099 : BlockStatement { $$ = $1; }
1100 | VariableStatement { $$ = $1; }
1101 | EmptyStatement { $$ = $1; }
1102 | IfStatement { $$ = $1; }
1103 | BreakableStatement { $$ = $1; }
1104 | ContinueStatement { $$ = $1; }
1105 | BreakStatement { $$ = $1; }
1106 | ReturnStatement { $$ = $1; }
1107 | WithStatement { $$ = $1; }
1108 | LabelledStatement { $$ = $1; }
1109 | ThrowStatement { $$ = $1; }
1110 | TryStatement { $$ = $1; }
1111 | DebuggerStatement { $$ = $1; }
1115 : LexSetRegExp Statement__ { $$ = $2; }
1116 | ExpressionStatement { $$ = $1; }
1120 : LexSetStatement Statement_ { $$ = $2; }
1124 : HoistableDeclaration { $$ = $1; }
1125 // XXX: | ClassDeclaration { $$ = $1; }
1126 | LexicalDeclaration { $$ = $1; }
1130 : LexSetRegExp Declaration__ { $$ = $2; }
1134 : LexSetStatement Declaration_ { $$ = $2; }
1137 HoistableDeclaration
1138 : FunctionDeclaration
1139 // XXX: | GeneratorDeclaration
1143 : IterationStatement { $$ = $1; }
1144 | SwitchStatement { $$ = $1; }
1147 /* 13.2 Block {{{ */
1149 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1153 : BRACE StatementListOpt "}" { $$ = $2; }
1157 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1161 : StatementList { $$ = $1; }
1162 | LexSetStatement LexSetRegExp { $$ = NULL; }
1166 : Statement { $$ = $1; }
1167 | Declaration { $$ = $1; }
1170 /* 13.3+ Let and Const Declarations {{{ */
1172 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1184 // XXX: lots of binding stuff
1186 /* 13.3.2+ Variable Statement {{{ */
1188 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1191 VariableDeclarationList_
1192 : "," VariableDeclarationList { $$ = $2; }
1196 VariableDeclarationList
1197 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1201 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1202 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1205 /* 13.3.3+ Destructuring Binding Patterns {{{ */
1209 : SingleNameBinding { $$ = $1; }
1213 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1216 /* 13.4 Empty Statement {{{ */
1218 : ";" { $$ = CYNew CYEmpty(); }
1221 /* 13.5 Expression Statement {{{ */
1223 : Expression Terminator { $$ = CYNew CYExpress($1); }
1226 /* 13.6 The if Statement {{{ */
1228 : "else" Statement { $$ = $2; }
1229 | %prec "if" { $$ = NULL; }
1233 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1236 /* 13.7+ Iteration Statements {{{ */
1238 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1239 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1240 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1241 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1242 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1245 ForStatementInitializer
1246 : ExpressionOpt { $$ = $1; }
1247 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1250 ForInStatementInitializer
1251 : LeftHandSideExpression { $$ = $1; }
1252 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1255 /* 13.8 The continue Statement {{{ */
1257 : "continue" LexNewLine
1261 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1262 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1265 /* 13.9 The break Statement {{{ */
1267 : "break" LexNewLine
1271 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1272 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1275 /* 13.10 The return Statement {{{ */
1277 : "return" LexNewLine
1281 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1282 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1285 /* 13.11 The with Statement {{{ */
1287 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1290 /* 13.12 The switch Statement {{{ */
1292 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1296 : BRACE CaseClausesOpt "}" { $$ = $2; }
1300 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1304 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1305 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1309 // XXX: the standard makes certain you can only have one of these
1311 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1314 /* 13.13 Labelled Statements {{{ */
1316 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1320 : Statement { $$ = $1; }
1321 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1324 /* 13.14 The throw Statement {{{ */
1326 : "throw" LexNewLine
1330 : Throw LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1331 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1334 /* 13.15 The try Statement {{{ */
1336 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1337 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1338 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1342 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1346 : "finally" Block { $$ = CYNew CYFinally($2); }
1350 : BindingIdentifier { $$ = $1; }
1351 // XXX: BindingPattern
1354 /* 13.16 The debugger Statement {{{ */
1356 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1360 /* 14.1+ Function Definitions {{{ */
1362 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1366 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1369 FormalParameterList_
1370 : "," FormalParameterList { $$ = $2; }
1375 // XXX: : FunctionRestParameter { $$ = $1; }
1376 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1379 FormalParameterListOpt
1380 : FormalParameterList
1384 /* XXX: FunctionRestParameter
1385 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1389 : BindingElement { $$ = $1; }
1393 : StatementListOpt { $$ = $1; }
1396 /* 14.2 Arrow Function Definitions {{{ */
1398 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1402 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1403 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1407 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1408 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1411 /* 14.3+ Method Definitions {{{ */
1413 /* 14.4+ Generator Function Definitions {{{ */
1415 /* 14.5+ Class Definitions {{{ */
1418 /* 15.1 Scripts {{{ */
1420 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1424 : StatementList { $$ = $1; }
1428 : ScriptBody { $$ = $1; }
1429 | LexSetStatement LexSetRegExp { $$ = NULL; }
1432 /* 15.2+ Modules {{{ */
1434 /* 15.2.2+ Imports {{{ */
1436 /* 15.2.3+ Exports {{{ */
1440 /* Cycript (C): Type Encoding {{{ */
1442 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1443 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1447 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1448 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1449 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1450 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1451 | TypeSignifier { $$ = $1; }
1452 | { $$ = CYNew CYTypedIdentifier(@$); }
1456 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1461 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1462 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1466 : PrefixedType { $$ = $1; }
1467 | SuffixedType { $$ = $1; }
1468 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1469 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1473 : "int" { $$ = CYNew CYTypeVariable("int"); }
1474 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1475 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1476 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1477 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1481 : IntegerType { $$ = $1; }
1482 | { $$ = CYNew CYTypeVariable("int"); }
1486 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1487 | IntegerType { $$ = $1; }
1488 | "void" { $$ = CYNew CYTypeVoid(); }
1489 | "char" { $$ = CYNew CYTypeVariable("char"); }
1490 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1491 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1495 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1499 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1505 /* Cycript (Objective-C): @class Declaration {{{ */
1507 /* XXX: why the hell did I choose MemberExpression? */
1508 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1513 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1514 | LexSetRegExp { $$ = NULL; }
1518 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1522 : "+" { $$ = false; }
1523 | "-" { $$ = true; }
1527 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1528 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1532 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1535 MessageParameterList
1536 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1539 MessageParameterListOpt
1540 : MessageParameterList { $$ = $1; }
1545 : MessageParameterList { $$ = $1; }
1546 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1549 ClassMessageDeclaration
1550 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1553 ClassMessageDeclarationListOpt
1554 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1559 : Identifier { $$ = $1; }
1560 | "(" AssignmentExpression ")" { $$ = $2; }
1563 // XXX: this should be AssignmentExpressionNoRight
1565 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1569 : "," ClassProtocols { $$ = $2; }
1573 ClassProtocolListOpt
1574 : "<" ClassProtocols ">" { $$ = $2; }
1579 : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1587 : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1591 : ClassStatement { $$ = $1; }
1592 | CategoryStatement { $$ = $1; }
1595 /* Cycript (Objective-C): Send Message {{{ */
1597 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1602 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1603 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1607 : SelectorCall { $$ = $1; }
1608 | VariadicCall { $$ = $1; }
1612 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1616 : SelectorCall { $$ = $1; }
1617 | Word { $$ = CYNew CYArgument($1, NULL); }
1621 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1622 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1626 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1630 : SelectorExpression_ { $$ = $1; }
1631 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1634 SelectorExpressionOpt
1635 : SelectorExpression_ { $$ = $1; }
1640 : MessageExpression { $$ = $1; }
1641 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1646 /* Cycript: @import Directive {{{ */
1648 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1649 | Word { $$ = CYNew CYModule($1); }
1653 : "@import" Module { $$ = CYNew CYImport($2); }
1658 /* Cycript (Objective-C): Boxed Expressions {{{ */
1660 : NullLiteral { $$ = $1; }
1661 | BooleanLiteral { $$ = $1; }
1662 | NumericLiteral { $$ = $1; }
1663 | StringLiteral { $$ = $1; }
1664 | ArrayLiteral { $$ = $1; }
1665 | ObjectLiteral { $$ = $1; }
1666 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
1667 | "YES" { $$ = CYNew CYTrue(); }
1668 | "NO" { $$ = CYNew CYFalse(); }
1672 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1673 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1674 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1675 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1676 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1677 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1680 /* Cycript (Objective-C): Block Expressions {{{ */
1682 : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); }
1685 /* Cycript (Objective-C): Instance Literals {{{ */
1687 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1693 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1694 LeftHandSideExpression
1695 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1699 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1703 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1704 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1705 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1708 /* Cycript (C): auto Compatibility {{{ */
1713 /* Cycript (C): Lambda Expressions {{{ */
1715 : "," TypedParameterList { $$ = $2; }
1720 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1723 TypedParameterListOpt
1724 : TypedParameterList { $$ = $1; }
1729 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1732 /* Cycript (C): Type Definitions {{{ */
1734 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1737 /* Cycript (C): extern "C" {{{ */
1739 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) error(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
1746 /* Lexer State {{{ */
1748 : { driver.PushCondition(CYDriver::RegExpCondition); }
1752 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1756 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1760 : { driver.PopCondition(); }
1764 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1768 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1771 /* Virtual Tokens {{{ */
1778 /* 8.1 Context Keywords {{{ */
1780 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1781 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1784 /* 8.3 XML Initializer Input Elements {{{ */
1786 : XMLComment { $$ = $1; }
1787 | XMLCDATA { $$ = $1; }
1788 | XMLPI { $$ = $1; }
1792 /* 11.1 Primary Expressions {{{ */
1794 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1795 | XMLInitialiser { $$ = $1; }
1796 | XMLListInitialiser { $$ = $1; }
1800 : AttributeIdentifier { $$ = $1; }
1801 | QualifiedIdentifier { $$ = $1; }
1802 | WildcardIdentifier { $$ = $1; }
1805 /* 11.1.1 Attribute Identifiers {{{ */
1807 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1811 : PropertySelector { $$ = $1; }
1812 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1816 : Identifier { $$ = CYNew CYSelector($1); }
1817 | WildcardIdentifier { $$ = $1; }
1820 /* 11.1.2 Qualified Identifiers {{{ */
1821 QualifiedIdentifier_
1822 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1823 | QualifiedIdentifier { $$ = $1; }
1827 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1830 /* 11.1.3 Wildcard Identifiers {{{ */
1832 : "*" { $$ = CYNew CYWildcard(); }
1835 /* 11.1.4 XML Initializer {{{ */
1837 : XMLMarkup { $$ = $1; }
1838 | XMLElement { $$ = $1; }
1842 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1843 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1847 : LexPushXMLTag XMLTagName XMLAttributes
1851 : BRACE LexPushRegExp Expression LexPop "}"
1860 : XMLAttributes_ XMLAttribute
1865 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1866 | XMLAttributes_ XMLWhitespaceOpt
1875 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1879 : XMLExpression XMLElementContentOpt
1880 | XMLMarkup XMLElementContentOpt
1881 | XMLText XMLElementContentOpt
1882 | XMLElement XMLElementContentOpt
1885 XMLElementContentOpt
1890 /* 11.1.5 XMLList Initializer {{{ */
1892 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1896 /* 11.2 Left-Hand-Side Expressions {{{ */
1898 : Identifier { $$ = $1; }
1899 | PropertyIdentifier { $$ = $1; }
1903 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1904 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1905 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1908 /* 12.1 The default xml namespace Statement {{{ */
1909 /* XXX: DefaultXMLNamespaceStatement
1910 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1914 : DefaultXMLNamespaceStatement { $$ = $1; }
1919 /* JavaScript FTL: Array Comprehensions {{{ */
1921 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1925 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1926 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1929 /* JavaScript FTL: for each {{{ */
1931 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1934 /* JavaScript FTL: let Statements {{{ */
1936 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1944 /* JavaScript FTW: Array Comprehensions {{{ */
1946 : ArrayComprehension
1950 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
1954 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
1959 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
1960 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
1964 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
1968 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
1971 /* JavaScript FTW: Coalesce Operator {{{ */
1972 ConditionalExpression
1973 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1976 /* JavaScript FTW: Ruby Blocks {{{ */
1977 RubyProcParameterList_
1978 : "," RubyProcParameterList { $$ = $2; }
1982 RubyProcParameterList
1983 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1988 : "|" RubyProcParameterList "|" { $$ = $2; }
1989 | "||" { $$ = NULL; }
1992 RubyProcParametersOpt
1993 : RubyProcParameters
1998 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2002 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2006 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }