]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
ce895ae1e961ea6980be5f7297efab3071ca6e46
[cycript.git] / Cycript.yy.in
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
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.
11
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.
16
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/>.
19 **/
20 /* }}} */
21
22 %code top {
23 #define cyscanner driver.scanner_
24 #define YYSTACKEXPANDABLE 1
25 }
26
27 %code requires {
28 #include "Driver.hpp"
29 #include "Parser.hpp"
30 #include "Stack.hpp"
31 #define CYNew new(driver.pool_)
32
33 @begin ObjectiveC
34 #include "ObjectiveC/Syntax.hpp"
35 @end
36
37 @begin E4X
38 #include "E4X/Syntax.hpp"
39 @end
40
41 #include "Highlight.hpp"
42 }
43
44 %union { bool bool_; }
45
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_; }
78
79 @begin C
80 %union { CYTypeModifier *modifier_; }
81 %union { CYTypeSpecifier *specifier_; }
82 %union { CYTypedIdentifier *typedIdentifier_; }
83 %union { CYTypedParameter *typedParameter_; }
84 @end
85
86 @begin ObjectiveC
87 %union { CYClassName *className_; }
88 %union { CYClassField *classField_; }
89 %union { CYMessage *message_; }
90 %union { CYMessageParameter *messageParameter_; }
91 %union { CYProtocol *protocol_; }
92 %union { CYSelectorPart *selector_; }
93 @end
94
95 @begin E4X
96 %union { CYAttribute *attribute_; }
97 %union { CYPropertyIdentifier *propertyIdentifier_; }
98 %union { CYSelector *selector_; }
99 @end
100
101 %code provides {
102
103 struct YYSTYPE {
104 cy::parser::semantic_type semantic_;
105 hi::Value highlight_;
106 };
107
108 int cylex(YYSTYPE *, CYLocation *, void *);
109
110 }
111
112 %code {
113
114 #undef yylex
115 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, void *scanner) {
116 YYSTYPE data;
117 int token(cylex(&data, location, scanner));
118 *semantic = data.semantic_;
119 return token;
120 }
121
122 #define CYMAP(to, from) do { \
123 if (yyla.empty()) \
124 yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, cyscanner)); \
125 if (yyla.type == yytranslate_(token::from)) \
126 yyla.type = yytranslate_(token::to); \
127 } while (false)
128
129 }
130
131 %name-prefix "cy"
132
133 %language "C++"
134
135 %initial-action {
136 @$.begin.filename = @$.end.filename = &driver.filename_;
137 };
138
139 %locations
140 %defines
141
142 %define api.location.type { CYLocation }
143
144 //%glr-parser
145 //%expect 1
146
147 %error-verbose
148
149 %parse-param { CYDriver &driver }
150 %lex-param { void *cyscanner }
151
152 /* Token Declarations {{{ */
153 @begin E4X
154 %token XMLCDATA
155 %token XMLComment
156 %token XMLPI
157
158 %token XMLAttributeValue
159 %token XMLName
160 %token XMLTagCharacters
161 %token XMLText
162 %token XMLWhitespace
163 @end
164
165 @begin E4X
166 %token LeftRight "<>"
167 %token LeftSlashRight "</>"
168
169 %token SlashRight "/>"
170 %token LeftSlash "</"
171
172 %token ColonColon "::"
173 %token PeriodPeriod ".."
174 @end
175
176 @begin E4X ObjectiveC
177 %token At "@"
178 %token Pound "#"
179 @end
180
181 %token Ampersand "&"
182 %token AmpersandAmpersand "&&"
183 %token AmpersandEqual "&="
184 %token Carrot "^"
185 %token CarrotEqual "^="
186 %token Equal "="
187 %token EqualEqual "=="
188 %token EqualEqualEqual "==="
189 %token EqualRight "=>"
190 %token EqualRight_ "\n=>"
191 %token Exclamation "!"
192 %token ExclamationEqual "!="
193 %token ExclamationEqualEqual "!=="
194 %token Hyphen "-"
195 %token HyphenEqual "-="
196 %token HyphenHyphen "--"
197 %token HyphenHyphen_ "\n--"
198 %token HyphenRight "->"
199 %token Left "<"
200 %token LeftEqual "<="
201 %token LeftLeft "<<"
202 %token LeftLeftEqual "<<="
203 %token Percent "%"
204 %token PercentEqual "%="
205 %token Period "."
206 %token PeriodPeriodPeriod "..."
207 %token Pipe "|"
208 %token PipeEqual "|="
209 %token PipePipe "||"
210 %token Plus "+"
211 %token PlusEqual "+="
212 %token PlusPlus "++"
213 %token PlusPlus_ "\n++"
214 %token Right ">"
215 %token RightEqual ">="
216 %token RightRight ">>"
217 %token RightRightEqual ">>="
218 %token RightRightRight ">>>"
219 %token RightRightRightEqual ">>>="
220 %token Slash "/"
221 %token SlashEqual "/="
222 %token Star "*"
223 %token StarEqual "*="
224 %token Tilde "~"
225
226 %token Colon ":"
227 %token Comma ","
228 %token Question "?"
229 %token SemiColon ";"
230 %token NewLine "\n"
231
232 %token Comment
233
234 %token OpenParen "("
235 %token CloseParen ")"
236
237 %token OpenBrace "{"
238 %token OpenBrace_ "\n{"
239 %token OpenBrace__ ";{"
240 %token CloseBrace "}"
241
242 %token OpenBracket "["
243 %token CloseBracket "]"
244
245 %token At_error_ "@error"
246
247 @begin Java
248 %token At_class_ "@class"
249 @end
250
251 @begin C
252 %token _typedef_ "typedef"
253 %token _unsigned_ "unsigned"
254 %token _signed_ "signed"
255 %token _extern_ "extern"
256 @end
257
258 @begin C
259 %token At_encode_ "@encode"
260 @end
261
262 @begin ObjectiveC
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"
269 %token At_NO_ "@NO"
270 %token At_true_ "@true"
271 %token At_false_ "@false"
272 %token _YES_ "YES"
273 %token _NO_ "NO"
274 @end
275
276 %token _false_ "false"
277 %token _null_ "null"
278 %token _true_ "true"
279
280 %token _break_ "break"
281 %token _case_ "case"
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"
290 %token _do_ "do"
291 %token _else_ "else"
292 %token _enum_ "enum"
293 %token _export_ "export"
294 %token _extends_ "extends"
295 %token _finally_ "finally"
296 %token _for_ "for"
297 %token _function_ "function"
298 %token _function__ ";function"
299 %token _if_ "if"
300 %token _import_ "import"
301 %token _in_ "in"
302 %token _in__ "!in"
303 %token _instanceof_ "instanceof"
304 %token _new_ "new"
305 %token _return_ "return"
306 %token _super_ "super"
307 %token _switch_ "switch"
308 %token _this_ "this"
309 %token _throw_ "throw"
310 %token _try_ "try"
311 %token _typeof_ "typeof"
312 %token _var_ "var"
313 %token _void_ "void"
314 %token _while_ "while"
315 %token _with_ "with"
316
317 %token _abstract_ "abstract"
318 %token _await_ "await"
319 %token _boolean_ "boolean"
320 %token _byte_ "byte"
321 %token _char_ "char"
322 %token _double_ "double"
323 %token _final_ "final"
324 %token _float_ "float"
325 %token _goto_ "goto"
326 %token _implements_ "implements"
327 %token _int_ "int"
328 %token _interface_ "interface"
329 %token _let_ "let"
330 %token _long_ "long"
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"
343
344 %token _undefined_ "undefined"
345
346 @begin ObjectiveC
347 %token _bool_ "bool"
348 %token _BOOL_ "BOOL"
349 %token _id_ "id"
350 %token _nil_ "nil"
351 %token _NULL_ "NULL"
352 %token _SEL_ "SEL"
353 @end
354
355 %token _auto_ "auto"
356 %token _each_ "each"
357 %token _of_ "of"
358
359 @begin E4X
360 %token _namespace_ "namespace"
361 %token _xml_ "xml"
362 @end
363
364 %token AutoComplete
365
366 %token <identifier_> Identifier_
367 %token <number_> NumericLiteral
368 %token <string_> StringLiteral
369 %token <literal_> RegularExpressionLiteral
370
371 %token <string_> NoSubstitutionTemplate
372 %token <string_> TemplateHead
373 %token <string_> TemplateMiddle
374 %token <string_> TemplateTail
375
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
403 %type <catch_> Catch
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
501 %type <word_> Word
502 @begin ObjectiveC
503 %type <word_> WordOpt
504 @end
505
506 @begin C
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
519 @end
520
521 @begin ObjectiveC
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
549 @end
550
551 @begin E4X
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
564
565 %type <attribute_> AttributeIdentifier
566 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
567 %type <expression_> PropertyIdentifier
568 %type <expression_> XMLListInitialiser
569 %type <expression_> XMLInitialiser
570 @end
571 /* }}} */
572 /* Token Priorities {{{ */
573 %nonassoc ""
574 %left "++" "--"
575
576 %nonassoc "if"
577 %nonassoc "else"
578 /* }}} */
579
580 %start Script
581
582 %%
583
584 /* Lexer State {{{ */
585 LexPushInOn
586 : { driver.in_.push(true); }
587 ;
588
589 LexPushInOff
590 : { driver.in_.push(false); }
591 ;
592
593 LexPopIn
594 : { driver.in_.pop(); }
595 ;
596
597 LexSetRegExp
598 : { driver.SetCondition(CYDriver::RegExpCondition); }
599 ;
600
601 LexNewLine
602 : { if (!yyla.empty() && yyla.type_get() != yyeof_) error(@$, "unexpected lookahead"); driver.next_ = true; }
603 ;
604
605 LexNoBrace
606 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
607 ;
608
609 LexNoClass
610 : { CYMAP(_class__, _class_); }
611 ;
612
613 LexNoFunction
614 : { CYMAP(_function__, _function_); }
615 ;
616
617 LexSetStatement
618 : LexNoBrace LexNoClass LexNoFunction
619 ;
620 /* }}} */
621 /* Virtual Tokens {{{ */
622 BRACE
623 : "{"
624 | "\n{"
625 ;
626
627 Var_
628 : "var"
629 ;
630 /* }}} */
631
632 /* 11.6 Names and Keywords {{{ */
633 IdentifierName
634 : Word { $$ = $1; }
635 | "for" { $$ = CYNew CYWord("for"); }
636 | "in" { $$ = CYNew CYWord("in"); }
637 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
638 ;
639
640 Word
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"); }
678
679 // XXX: should be Identifier
680 | "let" { $$ = CYNew CYIdentifier("let"); }
681 ;
682
683 @begin ObjectiveC
684 WordOpt
685 : Word { $$ = $1; }
686 | { $$ = NULL; }
687 ;
688 @end
689 /* }}} */
690 /* 11.8.1 Null Literals {{{ */
691 NullLiteral
692 : "null" { $$ = CYNew CYNull(); }
693 ;
694 /* }}} */
695 /* 11.8.2 Boolean Literals {{{ */
696 BooleanLiteral
697 : "true" { $$ = CYNew CYTrue(); }
698 | "false" { $$ = CYNew CYFalse(); }
699 ;
700 /* }}} */
701
702 /* 11.9 Automatic Semicolon Insertion {{{ */
703 StrictSemi
704 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
705 ;
706
707 TerminatorSoft
708 : ";"
709 | "\n" StrictSemi
710 ;
711
712 Terminator
713 : ";"
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
715 ;
716
717 TerminatorOpt
718 : ";"
719 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
720 ;
721 /* }}} */
722
723 /* 12.1 Identifiers {{{ */
724 IdentifierReference
725 : Identifier { $$ = CYNew CYVariable($1); }
726 // XXX: | "yield"
727 ;
728
729 BindingIdentifier
730 : Identifier { $$ = $1; }
731 // XXX: | "yield"
732 ;
733
734 LabelIdentifier
735 : Identifier { $$ = $1; }
736 // XXX: | yield
737 ;
738
739 IdentifierType
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"); }
763 @begin ObjectiveC
764 | "bool" { $$ = CYNew CYIdentifier("bool"); }
765 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
766 | "id" { $$ = CYNew CYIdentifier("id"); }
767 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
768 @end
769 ;
770
771 Identifier
772 : IdentifierType
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"); }
779 @begin C
780 | "extern" { $$ = CYNew CYIdentifier("extern"); }
781 | "signed" { $$ = CYNew CYIdentifier("signed"); }
782 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
783 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
784 @end
785 @begin ObjectiveC
786 | "nil" { $$ = CYNew CYIdentifier("nil"); }
787 | "NO" { $$ = CYNew CYIdentifier("NO"); }
788 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
789 | "YES" { $$ = CYNew CYIdentifier("YES"); }
790 @end
791 ;
792
793 IdentifierOpt
794 : Identifier { $$ = $1; }
795 | { $$ = NULL; }
796 ;
797 /* }}} */
798 /* 12.2 Primary Expression {{{ */
799 PrimaryExpression
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; }
809 ;
810
811 CoverParenthesizedExpressionAndArrowParameterList
812 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
813 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
814 ;
815 /* }}} */
816 /* 12.2.4 Literals {{{ */
817 Literal
818 : NullLiteral { $$ = $1; }
819 | BooleanLiteral { $$ = $1; }
820 | NumericLiteral { $$ = $1; }
821 | StringLiteral { $$ = $1; }
822 ;
823 /* }}} */
824 /* 12.2.5 Array Initializer {{{ */
825 ArrayLiteral
826 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
827 ;
828
829 ElementList
830 : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
831 | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
832 | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
833 ;
834
835 ElementListOpt
836 : ElementList { $$ = $1; }
837 | LexSetRegExp { $$ = NULL; }
838 ;
839 /* }}} */
840 /* 12.2.6 Object Initializer {{{ */
841 ObjectLiteral
842 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
843 ;
844
845 PropertyDefinitionList_
846 : "," PropertyDefinitionList { $$ = $2; }
847 | "," LexSetRegExp { $$ = NULL; }
848 | { $$ = NULL; }
849 ;
850
851 PropertyDefinitionList
852 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
853 ;
854
855 PropertyDefinitionListOpt
856 : PropertyDefinitionList { $$ = $1; }
857 | LexSetRegExp { $$ = NULL; }
858 ;
859
860 PropertyDefinition
861 // XXX: this should be IdentifierName
862 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
863 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
864 //| MethodDefinition
865 ;
866
867 PropertyName_
868 : IdentifierName { $$ = $1; }
869 | StringLiteral { $$ = $1; }
870 | NumericLiteral { $$ = $1; }
871 ;
872
873 PropertyName
874 : LexSetRegExp PropertyName_ { $$ = $2; }
875 ;
876
877
878 Initializer
879 : "=" AssignmentExpression { $$ = $2; }
880 ;
881
882 InitializerOpt
883 : Initializer { $$ = $1; }
884 | { $$ = NULL; }
885 ;
886 /* }}} */
887 /* 12.2.9 Template Literals {{{ */
888 TemplateLiteral
889 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
890 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
891 ;
892
893 TemplateSpans
894 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
895 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
896 ;
897 /* }}} */
898
899 /* 12.3+ Left-Hand-Side Expressions {{{ */
900 MemberAccess
901 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
902 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
903 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
904 ;
905
906 MemberExpression_
907 : MemberExpression { $$ = $1; }
908 //| "super" { $$ = $1; }
909 ;
910
911 MemberExpression
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); }
916 ;
917
918 NewExpression
919 : MemberExpression { $$ = $1; }
920 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
921 ;
922
923 CallExpression_
924 : MemberExpression_
925 | CallExpression
926 ;
927
928 CallExpression
929 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
930 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
931 ;
932
933 Arguments
934 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
935 ;
936
937 ArgumentList_
938 : "," ArgumentList { $$ = $2; }
939 | { $$ = NULL; }
940 ;
941
942 ArgumentList
943 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
944 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
945 ;
946
947 ArgumentListOpt
948 : ArgumentList { $$ = $1; }
949 | LexSetRegExp { $$ = NULL; }
950 ;
951
952 LeftHandSideExpression
953 : NewExpression { $$ = $1; }
954 | CallExpression { $$ = $1; }
955 ;
956 /* }}} */
957 /* 12.4 Postfix Expressions {{{ */
958 PostfixExpression
959 : %prec "" LeftHandSideExpression { $$ = $1; }
960 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
961 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
962 ;
963 /* }}} */
964 /* 12.5 Unary Operators {{{ */
965 UnaryExpression_
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); }
977 ;
978
979 UnaryExpression
980 : PostfixExpression { $$ = $1; }
981 | LexSetRegExp UnaryExpression_ { $$ = $2; }
982 ;
983 /* }}} */
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); }
990 ;
991 /* }}} */
992 /* 12.7 Additive Operators {{{ */
993 AdditiveExpression
994 : MultiplicativeExpression { $$ = $1; }
995 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
996 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
997 ;
998 /* }}} */
999 /* 12.8 Bitwise Shift Operators {{{ */
1000 ShiftExpression
1001 : AdditiveExpression { $$ = $1; }
1002 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1003 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1004 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1005 ;
1006 /* }}} */
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); }
1016 ;
1017 /* }}} */
1018 /* 12.10 Equality Operators {{{ */
1019 EqualityExpression
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); }
1025 ;
1026 /* }}} */
1027 /* 12.11 Binary Bitwise Operators {{{ */
1028 BitwiseANDExpression
1029 : EqualityExpression { $$ = $1; }
1030 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1031 ;
1032
1033 BitwiseXORExpression
1034 : BitwiseANDExpression { $$ = $1; }
1035 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1036 ;
1037
1038 BitwiseORExpression
1039 : BitwiseXORExpression { $$ = $1; }
1040 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1041 ;
1042 /* }}} */
1043 /* 12.12 Binary Logical Operators {{{ */
1044 LogicalANDExpression
1045 : BitwiseORExpression { $$ = $1; }
1046 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1047 ;
1048
1049 LogicalORExpression
1050 : LogicalANDExpression { $$ = $1; }
1051 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1052 ;
1053 /* }}} */
1054 /* 12.13 Conditional Operator ( ? : ) {{{ */
1055 ConditionalExpression
1056 : LogicalORExpression { $$ = $1; }
1057 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1058 ;
1059 /* }}} */
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); }
1077 ;
1078
1079 AssignmentExpressionOpt
1080 : AssignmentExpression { $$ = $1; }
1081 | LexSetRegExp { $$ = NULL; }
1082 ;
1083 /* }}} */
1084 /* 12.15 Comma Operator ( , ) {{{ */
1085 Expression
1086 : AssignmentExpression { $$ = $1; }
1087 /* XXX: I have this backwards... */
1088 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1089 ;
1090
1091 ExpressionOpt
1092 : Expression { $$ = $1; }
1093 | LexSetRegExp { $$ = NULL; }
1094 ;
1095 /* }}} */
1096
1097 /* 13 Statements and Declarations {{{ */
1098 Statement__
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; }
1112 ;
1113
1114 Statement_
1115 : LexSetRegExp Statement__ { $$ = $2; }
1116 | ExpressionStatement { $$ = $1; }
1117 ;
1118
1119 Statement
1120 : LexSetStatement Statement_ { $$ = $2; }
1121 ;
1122
1123 Declaration__
1124 : HoistableDeclaration { $$ = $1; }
1125 // XXX: | ClassDeclaration { $$ = $1; }
1126 | LexicalDeclaration { $$ = $1; }
1127 ;
1128
1129 Declaration_
1130 : LexSetRegExp Declaration__ { $$ = $2; }
1131 ;
1132
1133 Declaration
1134 : LexSetStatement Declaration_ { $$ = $2; }
1135 ;
1136
1137 HoistableDeclaration
1138 : FunctionDeclaration
1139 // XXX: | GeneratorDeclaration
1140 ;
1141
1142 BreakableStatement
1143 : IterationStatement { $$ = $1; }
1144 | SwitchStatement { $$ = $1; }
1145 ;
1146 /* }}} */
1147 /* 13.2 Block {{{ */
1148 BlockStatement
1149 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1150 ;
1151
1152 Block
1153 : BRACE StatementListOpt "}" { $$ = $2; }
1154 ;
1155
1156 StatementList
1157 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1158 ;
1159
1160 StatementListOpt
1161 : StatementList { $$ = $1; }
1162 | LexSetStatement LexSetRegExp { $$ = NULL; }
1163 ;
1164
1165 StatementListItem
1166 : Statement { $$ = $1; }
1167 | Declaration { $$ = $1; }
1168 ;
1169 /* }}} */
1170 /* 13.3+ Let and Const Declarations {{{ */
1171 LexicalDeclaration
1172 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1173 ;
1174
1175 LetOrConst
1176 : "let"
1177 | "const"
1178 ;
1179
1180 Binding
1181 : BindingIdentifier
1182 ;
1183
1184 // XXX: lots of binding stuff
1185 /* }}} */
1186 /* 13.3.2+ Variable Statement {{{ */
1187 VariableStatement
1188 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1189 ;
1190
1191 VariableDeclarationList_
1192 : "," VariableDeclarationList { $$ = $2; }
1193 | { $$ = NULL; }
1194 ;
1195
1196 VariableDeclarationList
1197 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1198 ;
1199
1200 VariableDeclaration
1201 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1202 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1203 ;
1204 /* }}} */
1205 /* 13.3.3+ Destructuring Binding Patterns {{{ */
1206 // XXX: *
1207
1208 BindingElement
1209 : SingleNameBinding { $$ = $1; }
1210 ;
1211
1212 SingleNameBinding
1213 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1214 ;
1215 /* }}} */
1216 /* 13.4 Empty Statement {{{ */
1217 EmptyStatement
1218 : ";" { $$ = CYNew CYEmpty(); }
1219 ;
1220 /* }}} */
1221 /* 13.5 Expression Statement {{{ */
1222 ExpressionStatement
1223 : Expression Terminator { $$ = CYNew CYExpress($1); }
1224 ;
1225 /* }}} */
1226 /* 13.6 The if Statement {{{ */
1227 ElseStatementOpt
1228 : "else" Statement { $$ = $2; }
1229 | %prec "if" { $$ = NULL; }
1230 ;
1231
1232 IfStatement
1233 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1234 ;
1235 /* }}} */
1236 /* 13.7+ Iteration Statements {{{ */
1237 IterationStatement
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); }
1243 ;
1244
1245 ForStatementInitializer
1246 : ExpressionOpt { $$ = $1; }
1247 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1248 ;
1249
1250 ForInStatementInitializer
1251 : LeftHandSideExpression { $$ = $1; }
1252 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1253 ;
1254 /* }}} */
1255 /* 13.8 The continue Statement {{{ */
1256 Continue
1257 : "continue" LexNewLine
1258 ;
1259
1260 ContinueStatement
1261 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1262 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1263 ;
1264 /* }}} */
1265 /* 13.9 The break Statement {{{ */
1266 Break
1267 : "break" LexNewLine
1268 ;
1269
1270 BreakStatement
1271 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1272 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1273 ;
1274 /* }}} */
1275 /* 13.10 The return Statement {{{ */
1276 Return
1277 : "return" LexNewLine
1278 ;
1279
1280 ReturnStatement
1281 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1282 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1283 ;
1284 /* }}} */
1285 /* 13.11 The with Statement {{{ */
1286 WithStatement
1287 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1288 ;
1289 /* }}} */
1290 /* 13.12 The switch Statement {{{ */
1291 SwitchStatement
1292 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1293 ;
1294
1295 CaseBlock
1296 : BRACE CaseClausesOpt "}" { $$ = $2; }
1297 ;
1298
1299 CaseClause
1300 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1301 ;
1302
1303 CaseClausesOpt
1304 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1305 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1306 | { $$ = NULL; }
1307 ;
1308
1309 // XXX: the standard makes certain you can only have one of these
1310 DefaultClause
1311 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1312 ;
1313 /* }}} */
1314 /* 13.13 Labelled Statements {{{ */
1315 LabelledStatement
1316 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1317 ;
1318
1319 LabelledItem
1320 : Statement { $$ = $1; }
1321 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1322 ;
1323 /* }}} */
1324 /* 13.14 The throw Statement {{{ */
1325 Throw
1326 : "throw" LexNewLine
1327 ;
1328
1329 ThrowStatement
1330 : Throw LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1331 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1332 ;
1333 /* }}} */
1334 /* 13.15 The try Statement {{{ */
1335 TryStatement
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); }
1339 ;
1340
1341 Catch
1342 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1343 ;
1344
1345 Finally
1346 : "finally" Block { $$ = CYNew CYFinally($2); }
1347 ;
1348
1349 CatchParameter
1350 : BindingIdentifier { $$ = $1; }
1351 // XXX: BindingPattern
1352 ;
1353 /* }}} */
1354 /* 13.16 The debugger Statement {{{ */
1355 DebuggerStatement
1356 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1357 ;
1358 /* }}} */
1359
1360 /* 14.1+ Function Definitions {{{ */
1361 FunctionDeclaration
1362 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1363 ;
1364
1365 FunctionExpression
1366 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1367 ;
1368
1369 FormalParameterList_
1370 : "," FormalParameterList { $$ = $2; }
1371 | { $$ = NULL; }
1372 ;
1373
1374 FormalParameterList
1375 // XXX: : FunctionRestParameter { $$ = $1; }
1376 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1377 ;
1378
1379 FormalParameterListOpt
1380 : FormalParameterList
1381 | { $$ = NULL; }
1382 ;
1383
1384 /* XXX: FunctionRestParameter
1385 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1386 ;*/
1387
1388 FormalParameter
1389 : BindingElement { $$ = $1; }
1390 ;
1391
1392 FunctionBody
1393 : StatementListOpt { $$ = $1; }
1394 ;
1395 /* }}} */
1396 /* 14.2 Arrow Function Definitions {{{ */
1397 ArrowFunction
1398 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1399 ;
1400
1401 ArrowParameters
1402 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1403 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1404 ;
1405
1406 ConciseBody
1407 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1408 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1409 ;
1410 /* }}} */
1411 /* 14.3+ Method Definitions {{{ */
1412 /* }}} */
1413 /* 14.4+ Generator Function Definitions {{{ */
1414 /* }}} */
1415 /* 14.5+ Class Definitions {{{ */
1416 /* }}} */
1417
1418 /* 15.1 Scripts {{{ */
1419 Script
1420 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1421 ;
1422
1423 ScriptBody
1424 : StatementList { $$ = $1; }
1425 ;
1426
1427 ScriptBodyOpt
1428 : ScriptBody { $$ = $1; }
1429 | LexSetStatement LexSetRegExp { $$ = NULL; }
1430 ;
1431 /* }}} */
1432 /* 15.2+ Modules {{{ */
1433 /* }}} */
1434 /* 15.2.2+ Imports {{{ */
1435 /* }}} */
1436 /* 15.2.3+ Exports {{{ */
1437 /* }}} */
1438
1439 @begin C
1440 /* Cycript (C): Type Encoding {{{ */
1441 TypeSignifier
1442 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1443 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1444 ;
1445
1446 SuffixedType
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(@$); }
1453 ;
1454
1455 PrefixedType
1456 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1457 ;
1458
1459 TypeQualifierLeft
1460 : { $$ = NULL; }
1461 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1462 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1463 ;
1464
1465 TypeQualifierRight
1466 : PrefixedType { $$ = $1; }
1467 | SuffixedType { $$ = $1; }
1468 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1469 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1470 ;
1471
1472 IntegerType
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); }
1478 ;
1479
1480 IntegerTypeOpt
1481 : IntegerType { $$ = $1; }
1482 | { $$ = CYNew CYTypeVariable("int"); }
1483 ;
1484
1485 PrimitiveType
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")); }
1492 ;
1493
1494 TypedIdentifier
1495 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1496 ;
1497
1498 PrimaryExpression
1499 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1500 ;
1501 /* }}} */
1502 @end
1503
1504 @begin ObjectiveC
1505 /* Cycript (Objective-C): @class Declaration {{{ */
1506 ClassSuperOpt
1507 /* XXX: why the hell did I choose MemberExpression? */
1508 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1509 | { $$ = NULL; }
1510 ;
1511
1512 ClassFieldListOpt
1513 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1514 | LexSetRegExp { $$ = NULL; }
1515 ;
1516
1517 ClassFields
1518 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1519 ;
1520
1521 MessageScope
1522 : "+" { $$ = false; }
1523 | "-" { $$ = true; }
1524 ;
1525
1526 TypeOpt
1527 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1528 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1529 ;
1530
1531 MessageParameter
1532 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1533 ;
1534
1535 MessageParameterList
1536 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1537 ;
1538
1539 MessageParameterListOpt
1540 : MessageParameterList { $$ = $1; }
1541 | { $$ = NULL; }
1542 ;
1543
1544 MessageParameters
1545 : MessageParameterList { $$ = $1; }
1546 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1547 ;
1548
1549 ClassMessageDeclaration
1550 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1551 ;
1552
1553 ClassMessageDeclarationListOpt
1554 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1555 | { $$ = NULL; }
1556 ;
1557
1558 ClassName
1559 : Identifier { $$ = $1; }
1560 | "(" AssignmentExpression ")" { $$ = $2; }
1561 ;
1562
1563 // XXX: this should be AssignmentExpressionNoRight
1564 ClassProtocols
1565 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1566 ;
1567
1568 ClassProtocolsOpt
1569 : "," ClassProtocols { $$ = $2; }
1570 | { $$ = NULL; }
1571 ;
1572
1573 ClassProtocolListOpt
1574 : "<" ClassProtocols ">" { $$ = $2; }
1575 | { $$ = NULL; }
1576 ;
1577
1578 ClassStatement
1579 : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1580 ;
1581
1582 CategoryName
1583 : "(" WordOpt ")"
1584 ;
1585
1586 CategoryStatement
1587 : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1588 ;
1589
1590 Statement__
1591 : ClassStatement { $$ = $1; }
1592 | CategoryStatement { $$ = $1; }
1593 ;
1594 /* }}} */
1595 /* Cycript (Objective-C): Send Message {{{ */
1596 VariadicCall
1597 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1598 | { $$ = NULL; }
1599 ;
1600
1601 SelectorWordOpt
1602 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1603 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1604 ;
1605
1606 SelectorCall_
1607 : SelectorCall { $$ = $1; }
1608 | VariadicCall { $$ = $1; }
1609 ;
1610
1611 SelectorCall
1612 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1613 ;
1614
1615 SelectorList
1616 : SelectorCall { $$ = $1; }
1617 | Word { $$ = CYNew CYArgument($1, NULL); }
1618 ;
1619
1620 MessageExpression
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); }
1623 ;
1624
1625 SelectorExpression_
1626 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1627 ;
1628
1629 SelectorExpression
1630 : SelectorExpression_ { $$ = $1; }
1631 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1632 ;
1633
1634 SelectorExpressionOpt
1635 : SelectorExpression_ { $$ = $1; }
1636 | { $$ = NULL; }
1637 ;
1638
1639 PrimaryExpression
1640 : MessageExpression { $$ = $1; }
1641 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1642 ;
1643 /* }}} */
1644 @end
1645
1646 /* Cycript: @import Directive {{{ */
1647 Module
1648 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1649 | Word { $$ = CYNew CYModule($1); }
1650 ;
1651
1652 Declaration__
1653 : "@import" Module { $$ = CYNew CYImport($2); }
1654 ;
1655 /* }}} */
1656
1657 @begin ObjectiveC
1658 /* Cycript (Objective-C): Boxed Expressions {{{ */
1659 BoxableExpression
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(); }
1669 ;
1670
1671 PrimaryExpression
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()); }
1678 ;
1679 /* }}} */
1680 /* Cycript (Objective-C): Block Expressions {{{ */
1681 PrimaryExpression
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"); }
1683 ;
1684 /* }}} */
1685 /* Cycript (Objective-C): Instance Literals {{{ */
1686 PrimaryExpression
1687 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1688 ;
1689 /* }}} */
1690 @end
1691
1692 @begin C
1693 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1694 LeftHandSideExpression
1695 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1696 ;
1697
1698 UnaryExpression_
1699 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1700 ;
1701
1702 MemberAccess
1703 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1704 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1705 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1706 ;
1707 /* }}} */
1708 /* Cycript (C): auto Compatibility {{{ */
1709 Var_
1710 : "auto"
1711 ;
1712 /* }}} */
1713 /* Cycript (C): Lambda Expressions {{{ */
1714 TypedParameterList_
1715 : "," TypedParameterList { $$ = $2; }
1716 | { $$ = NULL; }
1717 ;
1718
1719 TypedParameterList
1720 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1721 ;
1722
1723 TypedParameterListOpt
1724 : TypedParameterList { $$ = $1; }
1725 | { $$ = NULL; }
1726 ;
1727
1728 PrimaryExpression
1729 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1730 ;
1731 /* }}} */
1732 /* Cycript (C): Type Definitions {{{ */
1733 Statement__
1734 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1735 ;
1736 /* }}} */
1737 /* Cycript (C): extern "C" {{{ */
1738 Statement__
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); }
1740 ;
1741 /* }}} */
1742
1743 @end
1744
1745 @begin E4X
1746 /* Lexer State {{{ */
1747 LexPushRegExp
1748 : { driver.PushCondition(CYDriver::RegExpCondition); }
1749 ;
1750
1751 LexPushXMLContent
1752 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1753 ;
1754
1755 LexPushXMLTag
1756 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1757 ;
1758
1759 LexPop
1760 : { driver.PopCondition(); }
1761 ;
1762
1763 LexSetXMLContent
1764 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1765 ;
1766
1767 LexSetXMLTag
1768 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1769 ;
1770 /* }}} */
1771 /* Virtual Tokens {{{ */
1772 XMLWhitespaceOpt
1773 : XMLWhitespace
1774 |
1775 ;
1776 /* }}} */
1777
1778 /* 8.1 Context Keywords {{{ */
1779 Identifier
1780 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1781 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1782 ;
1783 /* }}} */
1784 /* 8.3 XML Initializer Input Elements {{{ */
1785 XMLMarkup
1786 : XMLComment { $$ = $1; }
1787 | XMLCDATA { $$ = $1; }
1788 | XMLPI { $$ = $1; }
1789 ;
1790 /* }}} */
1791
1792 /* 11.1 Primary Expressions {{{ */
1793 PrimaryExpression
1794 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1795 | XMLInitialiser { $$ = $1; }
1796 | XMLListInitialiser { $$ = $1; }
1797 ;
1798
1799 PropertyIdentifier
1800 : AttributeIdentifier { $$ = $1; }
1801 | QualifiedIdentifier { $$ = $1; }
1802 | WildcardIdentifier { $$ = $1; }
1803 ;
1804 /* }}} */
1805 /* 11.1.1 Attribute Identifiers {{{ */
1806 AttributeIdentifier
1807 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1808 ;
1809
1810 PropertySelector_
1811 : PropertySelector { $$ = $1; }
1812 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1813 ;
1814
1815 PropertySelector
1816 : Identifier { $$ = CYNew CYSelector($1); }
1817 | WildcardIdentifier { $$ = $1; }
1818 ;
1819 /* }}} */
1820 /* 11.1.2 Qualified Identifiers {{{ */
1821 QualifiedIdentifier_
1822 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1823 | QualifiedIdentifier { $$ = $1; }
1824 ;
1825
1826 QualifiedIdentifier
1827 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1828 ;
1829 /* }}} */
1830 /* 11.1.3 Wildcard Identifiers {{{ */
1831 WildcardIdentifier
1832 : "*" { $$ = CYNew CYWildcard(); }
1833 ;
1834 /* }}} */
1835 /* 11.1.4 XML Initializer {{{ */
1836 XMLInitialiser
1837 : XMLMarkup { $$ = $1; }
1838 | XMLElement { $$ = $1; }
1839 ;
1840
1841 XMLElement
1842 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1843 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1844 ;
1845
1846 XMLTagContent
1847 : LexPushXMLTag XMLTagName XMLAttributes
1848 ;
1849
1850 XMLExpression
1851 : BRACE LexPushRegExp Expression LexPop "}"
1852 ;
1853
1854 XMLTagName
1855 : XMLExpression
1856 | XMLName
1857 ;
1858
1859 XMLAttributes_
1860 : XMLAttributes_ XMLAttribute
1861 |
1862 ;
1863
1864 XMLAttributes
1865 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1866 | XMLAttributes_ XMLWhitespaceOpt
1867 ;
1868
1869 XMLAttributeValue_
1870 : XMLExpression
1871 | XMLAttributeValue
1872 ;
1873
1874 XMLAttribute
1875 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1876 ;
1877
1878 XMLElementContent
1879 : XMLExpression XMLElementContentOpt
1880 | XMLMarkup XMLElementContentOpt
1881 | XMLText XMLElementContentOpt
1882 | XMLElement XMLElementContentOpt
1883 ;
1884
1885 XMLElementContentOpt
1886 : XMLElementContent
1887 |
1888 ;
1889 /* }}} */
1890 /* 11.1.5 XMLList Initializer {{{ */
1891 XMLListInitialiser
1892 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1893 ;
1894 /* }}} */
1895
1896 /* 11.2 Left-Hand-Side Expressions {{{ */
1897 PropertyIdentifier_
1898 : Identifier { $$ = $1; }
1899 | PropertyIdentifier { $$ = $1; }
1900 ;
1901
1902 MemberAccess
1903 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1904 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1905 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1906 ;
1907 /* }}} */
1908 /* 12.1 The default xml namespace Statement {{{ */
1909 /* XXX: DefaultXMLNamespaceStatement
1910 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1911 ;
1912
1913 Statement__
1914 : DefaultXMLNamespaceStatement { $$ = $1; }
1915 ; */
1916 /* }}} */
1917 @end
1918
1919 /* JavaScript FTL: Array Comprehensions {{{ */
1920 Comprehension
1921 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1922 ;
1923
1924 ComprehensionFor
1925 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1926 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1927 ;
1928 /* }}} */
1929 /* JavaScript FTL: for each {{{ */
1930 IterationStatement
1931 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1932 ;
1933 /* }}} */
1934 /* JavaScript FTL: let Statements {{{ */
1935 LetStatement
1936 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1937 ;
1938
1939 Statement__
1940 : LetStatement
1941 ;
1942 /* }}} */
1943
1944 /* JavaScript FTW: Array Comprehensions {{{ */
1945 PrimaryExpression
1946 : ArrayComprehension
1947 ;
1948
1949 ArrayComprehension
1950 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
1951 ;
1952
1953 Comprehension
1954 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
1955 ;
1956
1957 ComprehensionTail
1958 : { $$ = NULL; }
1959 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
1960 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
1961 ;
1962
1963 ComprehensionFor
1964 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
1965 ;
1966
1967 ComprehensionIf
1968 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
1969 ;
1970 /* }}} */
1971 /* JavaScript FTW: Coalesce Operator {{{ */
1972 ConditionalExpression
1973 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1974 ;
1975 /* }}} */
1976 /* JavaScript FTW: Ruby Blocks {{{ */
1977 RubyProcParameterList_
1978 : "," RubyProcParameterList { $$ = $2; }
1979 | { $$ = NULL; }
1980 ;
1981
1982 RubyProcParameterList
1983 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1984 | { $$ = NULL; }
1985 ;
1986
1987 RubyProcParameters
1988 : "|" RubyProcParameterList "|" { $$ = $2; }
1989 | "||" { $$ = NULL; }
1990 ;
1991
1992 RubyProcParametersOpt
1993 : RubyProcParameters
1994 | { $$ = NULL; }
1995 ;
1996
1997 RubyProcExpression
1998 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1999 ;
2000
2001 PrimaryExpression
2002 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2003 ;
2004
2005 CallExpression
2006 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
2007 ;
2008 /* }}} */
2009
2010 %%