]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
1ff67360afe30c12c004f7fafd0c051c8a3374e5
[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 #define CYERR(location, message) do { \
130 error(location, message); \
131 YYABORT; \
132 } while (false)
133
134 }
135
136 %name-prefix "cy"
137
138 %language "C++"
139
140 %initial-action {
141 @$.begin.filename = @$.end.filename = &driver.filename_;
142 };
143
144 %locations
145 %defines
146
147 %define api.location.type { CYLocation }
148
149 //%glr-parser
150 //%expect 1
151
152 %error-verbose
153
154 %parse-param { CYDriver &driver }
155 %lex-param { void *cyscanner }
156
157 /* Token Declarations {{{ */
158 @begin E4X
159 %token XMLCDATA
160 %token XMLComment
161 %token XMLPI
162
163 %token XMLAttributeValue
164 %token XMLName
165 %token XMLTagCharacters
166 %token XMLText
167 %token XMLWhitespace
168 @end
169
170 @begin E4X
171 %token LeftRight "<>"
172 %token LeftSlashRight "</>"
173
174 %token SlashRight "/>"
175 %token LeftSlash "</"
176
177 %token ColonColon "::"
178 %token PeriodPeriod ".."
179 @end
180
181 @begin E4X ObjectiveC
182 %token At "@"
183 %token Pound "#"
184 @end
185
186 %token Ampersand "&"
187 %token AmpersandAmpersand "&&"
188 %token AmpersandEqual "&="
189 %token Carrot "^"
190 %token CarrotEqual "^="
191 %token Equal "="
192 %token EqualEqual "=="
193 %token EqualEqualEqual "==="
194 %token EqualRight "=>"
195 %token EqualRight_ "\n=>"
196 %token Exclamation "!"
197 %token ExclamationEqual "!="
198 %token ExclamationEqualEqual "!=="
199 %token Hyphen "-"
200 %token HyphenEqual "-="
201 %token HyphenHyphen "--"
202 %token HyphenHyphen_ "\n--"
203 %token HyphenRight "->"
204 %token Left "<"
205 %token LeftEqual "<="
206 %token LeftLeft "<<"
207 %token LeftLeftEqual "<<="
208 %token Percent "%"
209 %token PercentEqual "%="
210 %token Period "."
211 %token PeriodPeriodPeriod "..."
212 %token Pipe "|"
213 %token PipeEqual "|="
214 %token PipePipe "||"
215 %token Plus "+"
216 %token PlusEqual "+="
217 %token PlusPlus "++"
218 %token PlusPlus_ "\n++"
219 %token Right ">"
220 %token RightEqual ">="
221 %token RightRight ">>"
222 %token RightRightEqual ">>="
223 %token RightRightRight ">>>"
224 %token RightRightRightEqual ">>>="
225 %token Slash "/"
226 %token SlashEqual "/="
227 %token Star "*"
228 %token StarEqual "*="
229 %token Tilde "~"
230
231 %token Colon ":"
232 %token Comma ","
233 %token Question "?"
234 %token SemiColon ";"
235 %token NewLine "\n"
236
237 %token Comment
238
239 %token OpenParen "("
240 %token CloseParen ")"
241
242 %token OpenBrace "{"
243 %token OpenBrace_ "\n{"
244 %token OpenBrace__ ";{"
245 %token CloseBrace "}"
246
247 %token OpenBracket "["
248 %token CloseBracket "]"
249
250 %token At_error_ "@error"
251
252 @begin Java
253 %token At_class_ "@class"
254 @end
255
256 @begin C
257 %token _typedef_ "typedef"
258 %token _unsigned_ "unsigned"
259 %token _signed_ "signed"
260 %token _extern_ "extern"
261 @end
262
263 @begin C
264 %token At_encode_ "@encode"
265 @end
266
267 @begin ObjectiveC
268 %token At_implementation_ "@implementation"
269 %token At_import_ "@import"
270 %token At_end_ "@end"
271 %token At_selector_ "@selector"
272 %token At_null_ "@null"
273 %token At_YES_ "@YES"
274 %token At_NO_ "@NO"
275 %token At_true_ "@true"
276 %token At_false_ "@false"
277 %token _YES_ "YES"
278 %token _NO_ "NO"
279 @end
280
281 %token _false_ "false"
282 %token _null_ "null"
283 %token _true_ "true"
284
285 %token _break_ "break"
286 %token _case_ "case"
287 %token _catch_ "catch"
288 %token _class_ "class"
289 %token _class__ "!class"
290 %token _const_ "const"
291 %token _continue_ "continue"
292 %token _debugger_ "debugger"
293 %token _default_ "default"
294 %token _delete_ "delete"
295 %token _do_ "do"
296 %token _else_ "else"
297 %token _enum_ "enum"
298 %token _export_ "export"
299 %token _extends_ "extends"
300 %token _finally_ "finally"
301 %token _for_ "for"
302 %token _function_ "function"
303 %token _function__ ";function"
304 %token _if_ "if"
305 %token _import_ "import"
306 %token _in_ "in"
307 %token _in__ "!in"
308 %token _instanceof_ "instanceof"
309 %token _new_ "new"
310 %token _return_ "return"
311 %token _super_ "super"
312 %token _switch_ "switch"
313 %token _this_ "this"
314 %token _throw_ "throw"
315 %token _try_ "try"
316 %token _typeof_ "typeof"
317 %token _var_ "var"
318 %token _void_ "void"
319 %token _while_ "while"
320 %token _with_ "with"
321
322 %token _abstract_ "abstract"
323 %token _await_ "await"
324 %token _boolean_ "boolean"
325 %token _byte_ "byte"
326 %token _char_ "char"
327 %token _double_ "double"
328 %token _final_ "final"
329 %token _float_ "float"
330 %token _goto_ "goto"
331 %token _implements_ "implements"
332 %token _int_ "int"
333 %token _interface_ "interface"
334 %token _let_ "let"
335 %token _long_ "long"
336 %token _native_ "native"
337 %token _package_ "package"
338 %token _private_ "private"
339 %token _protected_ "protected"
340 %token _public_ "public"
341 %token _short_ "short"
342 %token _static_ "static"
343 %token _synchronized_ "synchronized"
344 %token _throws_ "throws"
345 %token _transient_ "transient"
346 %token _volatile_ "volatile"
347 %token _yield_ "yield"
348
349 %token _undefined_ "undefined"
350
351 @begin ObjectiveC
352 %token _bool_ "bool"
353 %token _BOOL_ "BOOL"
354 %token _id_ "id"
355 %token _nil_ "nil"
356 %token _NULL_ "NULL"
357 %token _SEL_ "SEL"
358 @end
359
360 %token _auto_ "auto"
361 %token _each_ "each"
362 %token _of_ "of"
363
364 @begin E4X
365 %token _namespace_ "namespace"
366 %token _xml_ "xml"
367 @end
368
369 %token AutoComplete
370
371 %token <identifier_> Identifier_
372 %token <number_> NumericLiteral
373 %token <string_> StringLiteral
374 %token <literal_> RegularExpressionLiteral
375
376 %token <string_> NoSubstitutionTemplate
377 %token <string_> TemplateHead
378 %token <string_> TemplateMiddle
379 %token <string_> TemplateTail
380
381 %type <expression_> AdditiveExpression
382 %type <argument_> ArgumentList_
383 %type <argument_> ArgumentList
384 %type <argument_> ArgumentListOpt
385 %type <argument_> Arguments
386 %type <expression_> ArrayComprehension
387 %type <literal_> ArrayLiteral
388 %type <expression_> ArrowFunction
389 %type <functionParameter_> ArrowParameters
390 %type <expression_> AssignmentExpression
391 %type <expression_> AssignmentExpressionOpt
392 %type <identifier_> Binding
393 %type <identifier_> BindingIdentifier
394 %type <expression_> BitwiseANDExpression
395 %type <statement_> Block
396 %type <statement_> BlockStatement
397 %type <boolean_> BooleanLiteral
398 %type <declaration_> BindingElement
399 %type <expression_> BitwiseORExpression
400 %type <expression_> BitwiseXORExpression
401 %type <statement_> BreakStatement
402 %type <statement_> BreakableStatement
403 %type <expression_> CallExpression_
404 %type <expression_> CallExpression
405 %type <clause_> CaseBlock
406 %type <clause_> CaseClause
407 %type <clause_> CaseClausesOpt
408 %type <catch_> Catch
409 %type <identifier_> CatchParameter
410 %type <expression_> Comprehension
411 %type <comprehension_> ComprehensionFor
412 %type <comprehension_> ComprehensionIf
413 %type <comprehension_> ComprehensionTail
414 %type <expression_> ConditionalExpression
415 %type <statement_> ContinueStatement
416 %type <statement_> ConciseBody
417 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
418 %type <statement_> DebuggerStatement
419 %type <statement_> Declaration__
420 %type <statement_> Declaration_
421 %type <statement_> Declaration
422 %type <clause_> DefaultClause
423 %type <element_> ElementList
424 %type <element_> ElementListOpt
425 %type <statement_> ElseStatementOpt
426 %type <statement_> EmptyStatement
427 %type <expression_> EqualityExpression
428 %type <expression_> Expression
429 %type <expression_> ExpressionOpt
430 %type <statement_> ExpressionStatement
431 %type <finally_> Finally
432 %type <for_> ForStatementInitializer
433 %type <forin_> ForInStatementInitializer
434 %type <declaration_> FormalParameter
435 %type <functionParameter_> FormalParameterList_
436 %type <functionParameter_> FormalParameterList
437 %type <functionParameter_> FormalParameterListOpt
438 %type <statement_> FunctionBody
439 %type <statement_> FunctionDeclaration
440 %type <expression_> FunctionExpression
441 %type <statement_> HoistableDeclaration
442 %type <identifier_> Identifier
443 %type <identifier_> IdentifierOpt
444 %type <identifier_> IdentifierType
445 %type <word_> IdentifierName
446 %type <expression_> IdentifierReference
447 %type <statement_> IfStatement
448 %type <expression_> Initializer
449 %type <expression_> InitializerOpt
450 %type <statement_> IterationStatement
451 %type <identifier_> LabelIdentifier
452 %type <statement_> LabelledItem
453 %type <statement_> LabelledStatement
454 %type <expression_> LeftHandSideExpression
455 %type <statement_> LetStatement
456 %type <statement_> LexicalDeclaration
457 %type <literal_> Literal
458 %type <expression_> LogicalANDExpression
459 %type <expression_> LogicalORExpression
460 %type <member_> MemberAccess
461 %type <expression_> MemberExpression_
462 %type <expression_> MemberExpression
463 %type <module_> Module
464 %type <expression_> MultiplicativeExpression
465 %type <expression_> NewExpression
466 %type <null_> NullLiteral
467 %type <literal_> ObjectLiteral
468 %type <expression_> PostfixExpression
469 %type <expression_> PrimaryExpression
470 %type <propertyName_> PropertyName_
471 %type <propertyName_> PropertyName
472 %type <property_> PropertyDefinition
473 %type <property_> PropertyDefinitionList_
474 %type <property_> PropertyDefinitionList
475 %type <property_> PropertyDefinitionListOpt
476 %type <expression_> RelationalExpression
477 %type <statement_> ReturnStatement
478 %type <rubyProc_> RubyProcExpression
479 %type <functionParameter_> RubyProcParameterList_
480 %type <functionParameter_> RubyProcParameterList
481 %type <functionParameter_> RubyProcParameters
482 %type <functionParameter_> RubyProcParametersOpt
483 %type <statement_> Script
484 %type <statement_> ScriptBody
485 %type <statement_> ScriptBodyOpt
486 %type <expression_> ShiftExpression
487 %type <declaration_> SingleNameBinding
488 %type <statement_> Statement__
489 %type <statement_> Statement_
490 %type <statement_> Statement
491 %type <statement_> StatementList
492 %type <statement_> StatementListOpt
493 %type <statement_> StatementListItem
494 %type <statement_> SwitchStatement
495 %type <expression_> TemplateLiteral
496 %type <span_> TemplateSpans
497 %type <statement_> ThrowStatement
498 %type <statement_> TryStatement
499 %type <expression_> UnaryExpression_
500 %type <expression_> UnaryExpression
501 %type <declaration_> VariableDeclaration
502 %type <declarations_> VariableDeclarationList_
503 %type <declarations_> VariableDeclarationList
504 %type <statement_> VariableStatement
505 %type <statement_> WithStatement
506 %type <word_> Word
507 @begin ObjectiveC
508 %type <word_> WordOpt
509 @end
510
511 @begin C
512 %type <specifier_> IntegerType
513 %type <specifier_> IntegerTypeOpt
514 %type <typedIdentifier_> PrefixedType
515 %type <specifier_> PrimitiveType
516 %type <typedIdentifier_> SuffixedType
517 %type <typedIdentifier_> TypeSignifier
518 %type <modifier_> TypeQualifierLeft
519 %type <typedIdentifier_> TypeQualifierRight
520 %type <typedIdentifier_> TypedIdentifier
521 %type <typedParameter_> TypedParameterList_
522 %type <typedParameter_> TypedParameterList
523 %type <typedParameter_> TypedParameterListOpt
524 @end
525
526 @begin ObjectiveC
527 %type <expression_> BoxableExpression
528 %type <statement_> CategoryStatement
529 %type <classField_> ClassFieldListOpt
530 %type <classField_> ClassFields
531 %type <statement_> ClassStatement
532 %type <expression_> ClassSuperOpt
533 %type <message_> ClassMessageDeclaration
534 %type <message_> ClassMessageDeclarationListOpt
535 %type <className_> ClassName
536 %type <protocol_> ClassProtocolListOpt
537 %type <protocol_> ClassProtocols
538 %type <protocol_> ClassProtocolsOpt
539 %type <expression_> MessageExpression
540 %type <messageParameter_> MessageParameter
541 %type <messageParameter_> MessageParameters
542 %type <messageParameter_> MessageParameterList
543 %type <messageParameter_> MessageParameterListOpt
544 %type <bool_> MessageScope
545 %type <argument_> SelectorCall_
546 %type <argument_> SelectorCall
547 %type <selector_> SelectorExpression_
548 %type <selector_> SelectorExpression
549 %type <selector_> SelectorExpressionOpt
550 %type <argument_> SelectorList
551 %type <word_> SelectorWordOpt
552 %type <typedIdentifier_> TypeOpt
553 %type <argument_> VariadicCall
554 @end
555
556 @begin E4X
557 %type <propertyIdentifier_> PropertyIdentifier_
558 %type <selector_> PropertySelector_
559 %type <selector_> PropertySelector
560 %type <identifier_> QualifiedIdentifier_
561 %type <identifier_> QualifiedIdentifier
562 %type <identifier_> WildcardIdentifier
563 %type <identifier_> XMLComment
564 %type <identifier_> XMLCDATA
565 %type <identifier_> XMLElement
566 %type <identifier_> XMLElementContent
567 %type <identifier_> XMLMarkup
568 %type <identifier_> XMLPI
569
570 %type <attribute_> AttributeIdentifier
571 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
572 %type <expression_> PropertyIdentifier
573 %type <expression_> XMLListInitialiser
574 %type <expression_> XMLInitialiser
575 @end
576 /* }}} */
577 /* Token Priorities {{{ */
578 %nonassoc ""
579 %left "++" "--" "{"
580
581 %nonassoc "if"
582 %nonassoc "else"
583 /* }}} */
584
585 %start Script
586
587 %%
588
589 /* Lexer State {{{ */
590 LexPushInOn
591 : { driver.in_.push(true); }
592 ;
593
594 LexPushInOff
595 : { driver.in_.push(false); }
596 ;
597
598 LexPopIn
599 : { driver.in_.pop(); }
600 ;
601
602 LexSetRegExp
603 : { driver.SetCondition(CYDriver::RegExpCondition); }
604 ;
605
606 LexNewLine
607 : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
608 ;
609
610 LexNoBrace
611 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
612 ;
613
614 LexNoClass
615 : { CYMAP(_class__, _class_); }
616 ;
617
618 LexNoFunction
619 : { CYMAP(_function__, _function_); }
620 ;
621
622 LexSetStatement
623 : LexNoBrace LexNoClass LexNoFunction
624 ;
625 /* }}} */
626 /* Virtual Tokens {{{ */
627 BRACE
628 : "{"
629 | "\n{"
630 ;
631
632 Var_
633 : "var"
634 ;
635 /* }}} */
636
637 /* 11.6 Names and Keywords {{{ */
638 IdentifierName
639 : Word { $$ = $1; }
640 | "for" { $$ = CYNew CYWord("for"); }
641 | "in" { $$ = CYNew CYWord("in"); }
642 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
643 ;
644
645 Word
646 : Identifier { $$ = $1; }
647 | "auto" { $$ = CYNew CYWord("auto"); }
648 | "break" { $$ = CYNew CYWord("break"); }
649 | "case" { $$ = CYNew CYWord("case"); }
650 | "catch" { $$ = CYNew CYWord("catch"); }
651 | "class" { $$ = CYNew CYWord("class"); }
652 | "!class" { $$ = CYNew CYWord("class"); }
653 | "const" { $$ = CYNew CYWord("const"); }
654 | "continue" { $$ = CYNew CYWord("continue"); }
655 | "debugger" { $$ = CYNew CYWord("debugger"); }
656 | "default" { $$ = CYNew CYWord("default"); }
657 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
658 | "do" { $$ = CYNew CYWord("do"); }
659 | "else" { $$ = CYNew CYWord("else"); }
660 | "enum" { $$ = CYNew CYWord("enum"); }
661 | "export" { $$ = CYNew CYWord("export"); }
662 | "extends" { $$ = CYNew CYWord("extends"); }
663 | "false" { $$ = CYNew CYWord("false"); }
664 | "finally" { $$ = CYNew CYWord("finally"); }
665 | "function" { $$ = CYNew CYWord("function"); }
666 | "if" { $$ = CYNew CYWord("if"); }
667 | "import" { $$ = CYNew CYWord("import"); }
668 | "!in" { $$ = CYNew CYWord("in"); }
669 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
670 | "null" { $$ = CYNew CYWord("null"); }
671 | "return" { $$ = CYNew CYWord("return"); }
672 | "super" { $$ = CYNew CYWord("super"); }
673 | "switch" { $$ = CYNew CYWord("switch"); }
674 | "this" { $$ = CYNew CYWord("this"); }
675 | "throw" { $$ = CYNew CYWord("throw"); }
676 | "true" { $$ = CYNew CYWord("true"); }
677 | "try" { $$ = CYNew CYWord("try"); }
678 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
679 | "var" { $$ = CYNew CYWord("var"); }
680 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
681 | "while" { $$ = CYNew CYWord("while"); }
682 | "with" { $$ = CYNew CYWord("with"); }
683
684 // XXX: should be Identifier
685 | "let" { $$ = CYNew CYIdentifier("let"); }
686 ;
687
688 @begin ObjectiveC
689 WordOpt
690 : Word { $$ = $1; }
691 | { $$ = NULL; }
692 ;
693 @end
694 /* }}} */
695 /* 11.8.1 Null Literals {{{ */
696 NullLiteral
697 : "null" { $$ = CYNew CYNull(); }
698 ;
699 /* }}} */
700 /* 11.8.2 Boolean Literals {{{ */
701 BooleanLiteral
702 : "true" { $$ = CYNew CYTrue(); }
703 | "false" { $$ = CYNew CYFalse(); }
704 ;
705 /* }}} */
706
707 /* 11.9 Automatic Semicolon Insertion {{{ */
708 StrictSemi
709 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
710 ;
711
712 TerminatorSoft
713 : ";"
714 | "\n" StrictSemi
715 ;
716
717 Terminator
718 : ";"
719 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
720 ;
721
722 TerminatorOpt
723 : ";"
724 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
725 ;
726 /* }}} */
727
728 /* 12.1 Identifiers {{{ */
729 IdentifierReference
730 : Identifier { $$ = CYNew CYVariable($1); }
731 // XXX: | "yield"
732 ;
733
734 BindingIdentifier
735 : Identifier { $$ = $1; }
736 // XXX: | "yield"
737 ;
738
739 LabelIdentifier
740 : Identifier { $$ = $1; }
741 // XXX: | yield
742 ;
743
744 IdentifierType
745 : Identifier_ { $$ = $1; }
746 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
747 | "await" { $$ = CYNew CYIdentifier("await"); }
748 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
749 | "byte" { $$ = CYNew CYIdentifier("byte"); }
750 | "double" { $$ = CYNew CYIdentifier("double"); }
751 | "each" { $$ = CYNew CYIdentifier("each"); }
752 | "final" { $$ = CYNew CYIdentifier("final"); }
753 | "float" { $$ = CYNew CYIdentifier("float"); }
754 | "goto" { $$ = CYNew CYIdentifier("goto"); }
755 | "implements" { $$ = CYNew CYIdentifier("implements"); }
756 | "interface" { $$ = CYNew CYIdentifier("interface"); }
757 | "native" { $$ = CYNew CYIdentifier("native"); }
758 | "of" { $$ = CYNew CYIdentifier("of"); }
759 | "package" { $$ = CYNew CYIdentifier("package"); }
760 | "private" { $$ = CYNew CYIdentifier("private"); }
761 | "protected" { $$ = CYNew CYIdentifier("protected"); }
762 | "public" { $$ = CYNew CYIdentifier("public"); }
763 | "static" { $$ = CYNew CYIdentifier("static"); }
764 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
765 | "throws" { $$ = CYNew CYIdentifier("throws"); }
766 | "transient" { $$ = CYNew CYIdentifier("transient"); }
767 | "yield" { $$ = CYNew CYIdentifier("yield"); }
768 @begin ObjectiveC
769 | "bool" { $$ = CYNew CYIdentifier("bool"); }
770 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
771 | "id" { $$ = CYNew CYIdentifier("id"); }
772 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
773 @end
774 ;
775
776 Identifier
777 : IdentifierType
778 | "char" { $$ = CYNew CYIdentifier("char"); }
779 | "int" { $$ = CYNew CYIdentifier("int"); }
780 | "long" { $$ = CYNew CYIdentifier("long"); }
781 | "short" { $$ = CYNew CYIdentifier("short"); }
782 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
783 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
784 @begin C
785 | "extern" { $$ = CYNew CYIdentifier("extern"); }
786 | "signed" { $$ = CYNew CYIdentifier("signed"); }
787 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
788 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
789 @end
790 @begin ObjectiveC
791 | "nil" { $$ = CYNew CYIdentifier("nil"); }
792 | "NO" { $$ = CYNew CYIdentifier("NO"); }
793 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
794 | "YES" { $$ = CYNew CYIdentifier("YES"); }
795 @end
796 ;
797
798 IdentifierOpt
799 : Identifier { $$ = $1; }
800 | { $$ = NULL; }
801 ;
802 /* }}} */
803 /* 12.2 Primary Expression {{{ */
804 PrimaryExpression
805 : "this" { $$ = CYNew CYThis(); }
806 | IdentifierReference { $$ = $1; }
807 | Literal { $$ = $1; }
808 | ArrayLiteral { $$ = $1; }
809 | ObjectLiteral { $$ = $1; }
810 | RegularExpressionLiteral { $$ = $1; }
811 | TemplateLiteral { $$ = $1; }
812 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) CYERR(@1, "invalid parenthetical"); $$ = $1; }
813 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
814 ;
815
816 CoverParenthesizedExpressionAndArrowParameterList
817 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
818 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
819 ;
820 /* }}} */
821 /* 12.2.4 Literals {{{ */
822 Literal
823 : NullLiteral { $$ = $1; }
824 | BooleanLiteral { $$ = $1; }
825 | NumericLiteral { $$ = $1; }
826 | StringLiteral { $$ = $1; }
827 ;
828 /* }}} */
829 /* 12.2.5 Array Initializer {{{ */
830 ArrayLiteral
831 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
832 ;
833
834 ElementList
835 : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
836 | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
837 | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
838 ;
839
840 ElementListOpt
841 : ElementList { $$ = $1; }
842 | LexSetRegExp { $$ = NULL; }
843 ;
844 /* }}} */
845 /* 12.2.6 Object Initializer {{{ */
846 ObjectLiteral
847 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
848 ;
849
850 PropertyDefinitionList_
851 : "," PropertyDefinitionList { $$ = $2; }
852 | "," LexSetRegExp { $$ = NULL; }
853 | { $$ = NULL; }
854 ;
855
856 PropertyDefinitionList
857 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
858 ;
859
860 PropertyDefinitionListOpt
861 : PropertyDefinitionList { $$ = $1; }
862 | LexSetRegExp { $$ = NULL; }
863 ;
864
865 PropertyDefinition
866 // XXX: this should be IdentifierName
867 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
868 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
869 //| MethodDefinition
870 ;
871
872 PropertyName_
873 : IdentifierName { $$ = $1; }
874 | StringLiteral { $$ = $1; }
875 | NumericLiteral { $$ = $1; }
876 ;
877
878 PropertyName
879 : LexSetRegExp PropertyName_ { $$ = $2; }
880 ;
881
882
883 Initializer
884 : "=" AssignmentExpression { $$ = $2; }
885 ;
886
887 InitializerOpt
888 : Initializer { $$ = $1; }
889 | { $$ = NULL; }
890 ;
891 /* }}} */
892 /* 12.2.9 Template Literals {{{ */
893 TemplateLiteral
894 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
895 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
896 ;
897
898 TemplateSpans
899 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
900 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
901 ;
902 /* }}} */
903
904 /* 12.3+ Left-Hand-Side Expressions {{{ */
905 MemberAccess
906 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
907 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
908 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
909 ;
910
911 MemberExpression_
912 : MemberExpression { $$ = $1; }
913 //| "super" { $$ = $1; }
914 ;
915
916 MemberExpression
917 : LexSetRegExp PrimaryExpression { $$ = $2; }
918 | LexSetRegExp FunctionExpression { $$ = $2; }
919 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
920 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
921 ;
922
923 NewExpression
924 : MemberExpression { $$ = $1; }
925 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
926 ;
927
928 CallExpression_
929 : MemberExpression_
930 | CallExpression
931 ;
932
933 CallExpression
934 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
935 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
936 ;
937
938 Arguments
939 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
940 ;
941
942 ArgumentList_
943 : "," ArgumentList { $$ = $2; }
944 | { $$ = NULL; }
945 ;
946
947 ArgumentList
948 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
949 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
950 ;
951
952 ArgumentListOpt
953 : ArgumentList { $$ = $1; }
954 | LexSetRegExp { $$ = NULL; }
955 ;
956
957 LeftHandSideExpression
958 : NewExpression { $$ = $1; }
959 | CallExpression { $$ = $1; }
960 ;
961 /* }}} */
962 /* 12.4 Postfix Expressions {{{ */
963 PostfixExpression
964 : %prec "" LeftHandSideExpression { $$ = $1; }
965 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
966 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
967 ;
968 /* }}} */
969 /* 12.5 Unary Operators {{{ */
970 UnaryExpression_
971 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
972 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
973 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
974 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
975 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
976 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
977 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
978 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
979 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
980 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
981 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
982 ;
983
984 UnaryExpression
985 : PostfixExpression { $$ = $1; }
986 | LexSetRegExp UnaryExpression_ { $$ = $2; }
987 ;
988 /* }}} */
989 /* 12.6 Multiplicative Operators {{{ */
990 MultiplicativeExpression
991 : UnaryExpression { $$ = $1; }
992 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
993 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
994 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
995 ;
996 /* }}} */
997 /* 12.7 Additive Operators {{{ */
998 AdditiveExpression
999 : MultiplicativeExpression { $$ = $1; }
1000 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1001 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1002 ;
1003 /* }}} */
1004 /* 12.8 Bitwise Shift Operators {{{ */
1005 ShiftExpression
1006 : AdditiveExpression { $$ = $1; }
1007 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1008 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1009 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1010 ;
1011 /* }}} */
1012 /* 12.9 Relational Operators {{{ */
1013 RelationalExpression
1014 : ShiftExpression { $$ = $1; }
1015 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1016 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1017 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1018 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1019 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1020 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1021 ;
1022 /* }}} */
1023 /* 12.10 Equality Operators {{{ */
1024 EqualityExpression
1025 : RelationalExpression { $$ = $1; }
1026 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1027 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1028 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1029 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1030 ;
1031 /* }}} */
1032 /* 12.11 Binary Bitwise Operators {{{ */
1033 BitwiseANDExpression
1034 : EqualityExpression { $$ = $1; }
1035 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1036 ;
1037
1038 BitwiseXORExpression
1039 : BitwiseANDExpression { $$ = $1; }
1040 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1041 ;
1042
1043 BitwiseORExpression
1044 : BitwiseXORExpression { $$ = $1; }
1045 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1046 ;
1047 /* }}} */
1048 /* 12.12 Binary Logical Operators {{{ */
1049 LogicalANDExpression
1050 : BitwiseORExpression { $$ = $1; }
1051 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1052 ;
1053
1054 LogicalORExpression
1055 : LogicalANDExpression { $$ = $1; }
1056 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1057 ;
1058 /* }}} */
1059 /* 12.13 Conditional Operator ( ? : ) {{{ */
1060 ConditionalExpression
1061 : LogicalORExpression { $$ = $1; }
1062 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1063 ;
1064 /* }}} */
1065 /* 12.14 Assignment Operators {{{ */
1066 AssignmentExpression
1067 : ConditionalExpression { $$ = $1; }
1068 // XXX: | YieldExpression { $$ = $1; }
1069 | ArrowFunction { $$ = $1; }
1070 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1071 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1072 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1073 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1074 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1075 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1076 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1077 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1078 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1079 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1080 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1081 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1082 ;
1083
1084 AssignmentExpressionOpt
1085 : AssignmentExpression { $$ = $1; }
1086 | LexSetRegExp { $$ = NULL; }
1087 ;
1088 /* }}} */
1089 /* 12.15 Comma Operator ( , ) {{{ */
1090 Expression
1091 : AssignmentExpression { $$ = $1; }
1092 /* XXX: I have this backwards... */
1093 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1094 ;
1095
1096 ExpressionOpt
1097 : Expression { $$ = $1; }
1098 | LexSetRegExp { $$ = NULL; }
1099 ;
1100 /* }}} */
1101
1102 /* 13 Statements and Declarations {{{ */
1103 Statement__
1104 : BlockStatement { $$ = $1; }
1105 | VariableStatement { $$ = $1; }
1106 | EmptyStatement { $$ = $1; }
1107 | IfStatement { $$ = $1; }
1108 | BreakableStatement { $$ = $1; }
1109 | ContinueStatement { $$ = $1; }
1110 | BreakStatement { $$ = $1; }
1111 | ReturnStatement { $$ = $1; }
1112 | WithStatement { $$ = $1; }
1113 | LabelledStatement { $$ = $1; }
1114 | ThrowStatement { $$ = $1; }
1115 | TryStatement { $$ = $1; }
1116 | DebuggerStatement { $$ = $1; }
1117 ;
1118
1119 Statement_
1120 : LexSetRegExp Statement__ { $$ = $2; }
1121 | ExpressionStatement { $$ = $1; }
1122 ;
1123
1124 Statement
1125 : LexSetStatement Statement_ { $$ = $2; }
1126 ;
1127
1128 Declaration__
1129 : HoistableDeclaration { $$ = $1; }
1130 // XXX: | ClassDeclaration { $$ = $1; }
1131 | LexicalDeclaration { $$ = $1; }
1132 ;
1133
1134 Declaration_
1135 : LexSetRegExp Declaration__ { $$ = $2; }
1136 ;
1137
1138 Declaration
1139 : LexSetStatement Declaration_ { $$ = $2; }
1140 ;
1141
1142 HoistableDeclaration
1143 : FunctionDeclaration
1144 // XXX: | GeneratorDeclaration
1145 ;
1146
1147 BreakableStatement
1148 : IterationStatement { $$ = $1; }
1149 | SwitchStatement { $$ = $1; }
1150 ;
1151 /* }}} */
1152 /* 13.2 Block {{{ */
1153 BlockStatement
1154 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1155 ;
1156
1157 Block
1158 : BRACE StatementListOpt "}" { $$ = $2; }
1159 ;
1160
1161 StatementList
1162 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1163 ;
1164
1165 StatementListOpt
1166 : StatementList { $$ = $1; }
1167 | LexSetStatement LexSetRegExp { $$ = NULL; }
1168 ;
1169
1170 StatementListItem
1171 : Statement { $$ = $1; }
1172 | Declaration { $$ = $1; }
1173 ;
1174 /* }}} */
1175 /* 13.3+ Let and Const Declarations {{{ */
1176 LexicalDeclaration
1177 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1178 ;
1179
1180 LetOrConst
1181 : "let"
1182 | "const"
1183 ;
1184
1185 Binding
1186 : BindingIdentifier
1187 ;
1188
1189 // XXX: lots of binding stuff
1190 /* }}} */
1191 /* 13.3.2+ Variable Statement {{{ */
1192 VariableStatement
1193 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1194 ;
1195
1196 VariableDeclarationList_
1197 : "," VariableDeclarationList { $$ = $2; }
1198 | { $$ = NULL; }
1199 ;
1200
1201 VariableDeclarationList
1202 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1203 ;
1204
1205 VariableDeclaration
1206 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1207 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1208 ;
1209 /* }}} */
1210 /* 13.3.3+ Destructuring Binding Patterns {{{ */
1211 // XXX: *
1212
1213 BindingElement
1214 : SingleNameBinding { $$ = $1; }
1215 ;
1216
1217 SingleNameBinding
1218 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1219 ;
1220 /* }}} */
1221 /* 13.4 Empty Statement {{{ */
1222 EmptyStatement
1223 : ";" { $$ = CYNew CYEmpty(); }
1224 ;
1225 /* }}} */
1226 /* 13.5 Expression Statement {{{ */
1227 ExpressionStatement
1228 : Expression Terminator { $$ = CYNew CYExpress($1); }
1229 ;
1230 /* }}} */
1231 /* 13.6 The if Statement {{{ */
1232 ElseStatementOpt
1233 : "else" Statement { $$ = $2; }
1234 | %prec "if" { $$ = NULL; }
1235 ;
1236
1237 IfStatement
1238 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1239 ;
1240 /* }}} */
1241 /* 13.7+ Iteration Statements {{{ */
1242 IterationStatement
1243 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1244 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1245 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1246 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1247 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1248 ;
1249
1250 ForStatementInitializer
1251 : ExpressionOpt { $$ = $1; }
1252 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1253 ;
1254
1255 ForInStatementInitializer
1256 : LeftHandSideExpression { $$ = $1; }
1257 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1258 ;
1259 /* }}} */
1260 /* 13.8 The continue Statement {{{ */
1261 Continue
1262 : "continue" LexNewLine
1263 ;
1264
1265 ContinueStatement
1266 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1267 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1268 ;
1269 /* }}} */
1270 /* 13.9 The break Statement {{{ */
1271 Break
1272 : "break" LexNewLine
1273 ;
1274
1275 BreakStatement
1276 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1277 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1278 ;
1279 /* }}} */
1280 /* 13.10 The return Statement {{{ */
1281 Return
1282 : "return" LexNewLine
1283 ;
1284
1285 ReturnStatement
1286 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1287 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1288 ;
1289 /* }}} */
1290 /* 13.11 The with Statement {{{ */
1291 WithStatement
1292 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1293 ;
1294 /* }}} */
1295 /* 13.12 The switch Statement {{{ */
1296 SwitchStatement
1297 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1298 ;
1299
1300 CaseBlock
1301 : BRACE CaseClausesOpt "}" { $$ = $2; }
1302 ;
1303
1304 CaseClause
1305 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1306 ;
1307
1308 CaseClausesOpt
1309 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1310 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1311 | { $$ = NULL; }
1312 ;
1313
1314 // XXX: the standard makes certain you can only have one of these
1315 DefaultClause
1316 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1317 ;
1318 /* }}} */
1319 /* 13.13 Labelled Statements {{{ */
1320 LabelledStatement
1321 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1322 ;
1323
1324 LabelledItem
1325 : Statement { $$ = $1; }
1326 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1327 ;
1328 /* }}} */
1329 /* 13.14 The throw Statement {{{ */
1330 Throw
1331 : "throw" LexNewLine
1332 ;
1333
1334 ThrowStatement
1335 : Throw LexSetRegExp TerminatorSoft { CYERR(@1, "throw without exception"); }
1336 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1337 ;
1338 /* }}} */
1339 /* 13.15 The try Statement {{{ */
1340 TryStatement
1341 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1342 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1343 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1344 ;
1345
1346 Catch
1347 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1348 ;
1349
1350 Finally
1351 : "finally" Block { $$ = CYNew CYFinally($2); }
1352 ;
1353
1354 CatchParameter
1355 : BindingIdentifier { $$ = $1; }
1356 // XXX: BindingPattern
1357 ;
1358 /* }}} */
1359 /* 13.16 The debugger Statement {{{ */
1360 DebuggerStatement
1361 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1362 ;
1363 /* }}} */
1364
1365 /* 14.1+ Function Definitions {{{ */
1366 FunctionDeclaration
1367 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1368 ;
1369
1370 FunctionExpression
1371 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1372 ;
1373
1374 FormalParameterList_
1375 : "," FormalParameterList { $$ = $2; }
1376 | { $$ = NULL; }
1377 ;
1378
1379 FormalParameterList
1380 // XXX: : FunctionRestParameter { $$ = $1; }
1381 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1382 ;
1383
1384 FormalParameterListOpt
1385 : FormalParameterList
1386 | { $$ = NULL; }
1387 ;
1388
1389 /* XXX: FunctionRestParameter
1390 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1391 ;*/
1392
1393 FormalParameter
1394 : BindingElement { $$ = $1; }
1395 ;
1396
1397 FunctionBody
1398 : StatementListOpt { $$ = $1; }
1399 ;
1400 /* }}} */
1401 /* 14.2 Arrow Function Definitions {{{ */
1402 ArrowFunction
1403 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1404 ;
1405
1406 ArrowParameters
1407 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1408 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); }
1409 ;
1410
1411 ConciseBody
1412 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1413 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1414 ;
1415 /* }}} */
1416 /* 14.3+ Method Definitions {{{ */
1417 /* }}} */
1418 /* 14.4+ Generator Function Definitions {{{ */
1419 /* }}} */
1420 /* 14.5+ Class Definitions {{{ */
1421 /* }}} */
1422
1423 /* 15.1 Scripts {{{ */
1424 Script
1425 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1426 ;
1427
1428 ScriptBody
1429 : StatementList { $$ = $1; }
1430 ;
1431
1432 ScriptBodyOpt
1433 : ScriptBody { $$ = $1; }
1434 | LexSetStatement LexSetRegExp { $$ = NULL; }
1435 ;
1436 /* }}} */
1437 /* 15.2+ Modules {{{ */
1438 /* }}} */
1439 /* 15.2.2+ Imports {{{ */
1440 /* }}} */
1441 /* 15.2.3+ Exports {{{ */
1442 /* }}} */
1443
1444 @begin C
1445 /* Cycript (C): Type Encoding {{{ */
1446 TypeSignifier
1447 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1448 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1449 ;
1450
1451 SuffixedType
1452 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1453 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1454 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1455 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1456 | TypeSignifier { $$ = $1; }
1457 | { $$ = CYNew CYTypedIdentifier(@$); }
1458 ;
1459
1460 PrefixedType
1461 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1462 ;
1463
1464 TypeQualifierLeft
1465 : { $$ = NULL; }
1466 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1467 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1468 ;
1469
1470 TypeQualifierRight
1471 : PrefixedType { $$ = $1; }
1472 | SuffixedType { $$ = $1; }
1473 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1474 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1475 ;
1476
1477 IntegerType
1478 : "int" { $$ = CYNew CYTypeVariable("int"); }
1479 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1480 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1481 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1482 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1483 ;
1484
1485 IntegerTypeOpt
1486 : IntegerType { $$ = $1; }
1487 | { $$ = CYNew CYTypeVariable("int"); }
1488 ;
1489
1490 PrimitiveType
1491 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1492 | IntegerType { $$ = $1; }
1493 | "void" { $$ = CYNew CYTypeVoid(); }
1494 | "char" { $$ = CYNew CYTypeVariable("char"); }
1495 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1496 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1497 ;
1498
1499 TypedIdentifier
1500 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1501 ;
1502
1503 PrimaryExpression
1504 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1505 ;
1506 /* }}} */
1507 @end
1508
1509 @begin ObjectiveC
1510 /* Cycript (Objective-C): @class Declaration {{{ */
1511 ClassSuperOpt
1512 /* XXX: why the hell did I choose MemberExpression? */
1513 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1514 | { $$ = NULL; }
1515 ;
1516
1517 ClassFieldListOpt
1518 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1519 | LexSetRegExp { $$ = NULL; }
1520 ;
1521
1522 ClassFields
1523 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1524 ;
1525
1526 MessageScope
1527 : "+" { $$ = false; }
1528 | "-" { $$ = true; }
1529 ;
1530
1531 TypeOpt
1532 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) CYERR($3->location_, "unexpected identifier"); $$ = $3; }
1533 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1534 ;
1535
1536 MessageParameter
1537 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1538 ;
1539
1540 MessageParameterList
1541 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1542 ;
1543
1544 MessageParameterListOpt
1545 : MessageParameterList { $$ = $1; }
1546 | { $$ = NULL; }
1547 ;
1548
1549 MessageParameters
1550 : MessageParameterList { $$ = $1; }
1551 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1552 ;
1553
1554 ClassMessageDeclaration
1555 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1556 ;
1557
1558 ClassMessageDeclarationListOpt
1559 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1560 | { $$ = NULL; }
1561 ;
1562
1563 ClassName
1564 : Identifier { $$ = $1; }
1565 | "(" AssignmentExpression ")" { $$ = $2; }
1566 ;
1567
1568 // XXX: this should be AssignmentExpressionNoRight
1569 ClassProtocols
1570 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1571 ;
1572
1573 ClassProtocolsOpt
1574 : "," ClassProtocols { $$ = $2; }
1575 | { $$ = NULL; }
1576 ;
1577
1578 ClassProtocolListOpt
1579 : "<" ClassProtocols ">" { $$ = $2; }
1580 | { $$ = NULL; }
1581 ;
1582
1583 ClassStatement
1584 : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1585 ;
1586
1587 CategoryName
1588 : "(" WordOpt ")"
1589 ;
1590
1591 CategoryStatement
1592 : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1593 ;
1594
1595 Statement__
1596 : ClassStatement { $$ = $1; }
1597 | CategoryStatement { $$ = $1; }
1598 ;
1599 /* }}} */
1600 /* Cycript (Objective-C): Send Message {{{ */
1601 VariadicCall
1602 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1603 | { $$ = NULL; }
1604 ;
1605
1606 SelectorWordOpt
1607 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1608 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1609 ;
1610
1611 SelectorCall_
1612 : SelectorCall { $$ = $1; }
1613 | VariadicCall { $$ = $1; }
1614 ;
1615
1616 SelectorCall
1617 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1618 ;
1619
1620 SelectorList
1621 : SelectorCall { $$ = $1; }
1622 | Word { $$ = CYNew CYArgument($1, NULL); }
1623 ;
1624
1625 MessageExpression
1626 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1627 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1628 ;
1629
1630 SelectorExpression_
1631 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1632 ;
1633
1634 SelectorExpression
1635 : SelectorExpression_ { $$ = $1; }
1636 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1637 ;
1638
1639 SelectorExpressionOpt
1640 : SelectorExpression_ { $$ = $1; }
1641 | { $$ = NULL; }
1642 ;
1643
1644 PrimaryExpression
1645 : MessageExpression { $$ = $1; }
1646 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1647 ;
1648 /* }}} */
1649 @end
1650
1651 /* Cycript: @import Directive {{{ */
1652 Module
1653 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1654 | Word { $$ = CYNew CYModule($1); }
1655 ;
1656
1657 Declaration__
1658 : "@import" Module { $$ = CYNew CYImport($2); }
1659 ;
1660 /* }}} */
1661
1662 @begin ObjectiveC
1663 /* Cycript (Objective-C): Boxed Expressions {{{ */
1664 BoxableExpression
1665 : NullLiteral { $$ = $1; }
1666 | BooleanLiteral { $$ = $1; }
1667 | NumericLiteral { $$ = $1; }
1668 | StringLiteral { $$ = $1; }
1669 | ArrayLiteral { $$ = $1; }
1670 | ObjectLiteral { $$ = $1; }
1671 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
1672 | "YES" { $$ = CYNew CYTrue(); }
1673 | "NO" { $$ = CYNew CYFalse(); }
1674 ;
1675
1676 PrimaryExpression
1677 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1678 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1679 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1680 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1681 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1682 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1683 ;
1684 /* }}} */
1685 /* Cycript (Objective-C): Block Expressions {{{ */
1686 PrimaryExpression
1687 : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else CYERR($2->location_, "expected parameters"); }
1688 ;
1689 /* }}} */
1690 /* Cycript (Objective-C): Instance Literals {{{ */
1691 PrimaryExpression
1692 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1693 ;
1694 /* }}} */
1695 @end
1696
1697 @begin C
1698 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1699 LeftHandSideExpression
1700 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1701 ;
1702
1703 UnaryExpression_
1704 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1705 ;
1706
1707 MemberAccess
1708 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1709 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1710 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1711 ;
1712 /* }}} */
1713 /* Cycript (C): auto Compatibility {{{ */
1714 Var_
1715 : "auto"
1716 ;
1717 /* }}} */
1718 /* Cycript (C): Lambda Expressions {{{ */
1719 TypedParameterList_
1720 : "," TypedParameterList { $$ = $2; }
1721 | { $$ = NULL; }
1722 ;
1723
1724 TypedParameterList
1725 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1726 ;
1727
1728 TypedParameterListOpt
1729 : TypedParameterList { $$ = $1; }
1730 | { $$ = NULL; }
1731 ;
1732
1733 PrimaryExpression
1734 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1735 ;
1736 /* }}} */
1737 /* Cycript (C): Type Definitions {{{ */
1738 Statement__
1739 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) CYERR($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1740 ;
1741 /* }}} */
1742 /* Cycript (C): extern "C" {{{ */
1743 Statement__
1744 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) CYERR(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) CYERR($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
1745 ;
1746 /* }}} */
1747
1748 @end
1749
1750 @begin E4X
1751 /* Lexer State {{{ */
1752 LexPushRegExp
1753 : { driver.PushCondition(CYDriver::RegExpCondition); }
1754 ;
1755
1756 LexPushXMLContent
1757 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1758 ;
1759
1760 LexPushXMLTag
1761 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1762 ;
1763
1764 LexPop
1765 : { driver.PopCondition(); }
1766 ;
1767
1768 LexSetXMLContent
1769 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1770 ;
1771
1772 LexSetXMLTag
1773 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1774 ;
1775 /* }}} */
1776 /* Virtual Tokens {{{ */
1777 XMLWhitespaceOpt
1778 : XMLWhitespace
1779 |
1780 ;
1781 /* }}} */
1782
1783 /* 8.1 Context Keywords {{{ */
1784 Identifier
1785 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1786 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1787 ;
1788 /* }}} */
1789 /* 8.3 XML Initializer Input Elements {{{ */
1790 XMLMarkup
1791 : XMLComment { $$ = $1; }
1792 | XMLCDATA { $$ = $1; }
1793 | XMLPI { $$ = $1; }
1794 ;
1795 /* }}} */
1796
1797 /* 11.1 Primary Expressions {{{ */
1798 PrimaryExpression
1799 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1800 | XMLInitialiser { $$ = $1; }
1801 | XMLListInitialiser { $$ = $1; }
1802 ;
1803
1804 PropertyIdentifier
1805 : AttributeIdentifier { $$ = $1; }
1806 | QualifiedIdentifier { $$ = $1; }
1807 | WildcardIdentifier { $$ = $1; }
1808 ;
1809 /* }}} */
1810 /* 11.1.1 Attribute Identifiers {{{ */
1811 AttributeIdentifier
1812 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1813 ;
1814
1815 PropertySelector_
1816 : PropertySelector { $$ = $1; }
1817 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1818 ;
1819
1820 PropertySelector
1821 : Identifier { $$ = CYNew CYSelector($1); }
1822 | WildcardIdentifier { $$ = $1; }
1823 ;
1824 /* }}} */
1825 /* 11.1.2 Qualified Identifiers {{{ */
1826 QualifiedIdentifier_
1827 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1828 | QualifiedIdentifier { $$ = $1; }
1829 ;
1830
1831 QualifiedIdentifier
1832 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1833 ;
1834 /* }}} */
1835 /* 11.1.3 Wildcard Identifiers {{{ */
1836 WildcardIdentifier
1837 : "*" { $$ = CYNew CYWildcard(); }
1838 ;
1839 /* }}} */
1840 /* 11.1.4 XML Initializer {{{ */
1841 XMLInitialiser
1842 : XMLMarkup { $$ = $1; }
1843 | XMLElement { $$ = $1; }
1844 ;
1845
1846 XMLElement
1847 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1848 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1849 ;
1850
1851 XMLTagContent
1852 : LexPushXMLTag XMLTagName XMLAttributes
1853 ;
1854
1855 XMLExpression
1856 : BRACE LexPushRegExp Expression LexPop "}"
1857 ;
1858
1859 XMLTagName
1860 : XMLExpression
1861 | XMLName
1862 ;
1863
1864 XMLAttributes_
1865 : XMLAttributes_ XMLAttribute
1866 |
1867 ;
1868
1869 XMLAttributes
1870 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1871 | XMLAttributes_ XMLWhitespaceOpt
1872 ;
1873
1874 XMLAttributeValue_
1875 : XMLExpression
1876 | XMLAttributeValue
1877 ;
1878
1879 XMLAttribute
1880 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1881 ;
1882
1883 XMLElementContent
1884 : XMLExpression XMLElementContentOpt
1885 | XMLMarkup XMLElementContentOpt
1886 | XMLText XMLElementContentOpt
1887 | XMLElement XMLElementContentOpt
1888 ;
1889
1890 XMLElementContentOpt
1891 : XMLElementContent
1892 |
1893 ;
1894 /* }}} */
1895 /* 11.1.5 XMLList Initializer {{{ */
1896 XMLListInitialiser
1897 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1898 ;
1899 /* }}} */
1900
1901 /* 11.2 Left-Hand-Side Expressions {{{ */
1902 PropertyIdentifier_
1903 : Identifier { $$ = $1; }
1904 | PropertyIdentifier { $$ = $1; }
1905 ;
1906
1907 MemberAccess
1908 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1909 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1910 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1911 ;
1912 /* }}} */
1913 /* 12.1 The default xml namespace Statement {{{ */
1914 /* XXX: DefaultXMLNamespaceStatement
1915 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1916 ;
1917
1918 Statement__
1919 : DefaultXMLNamespaceStatement { $$ = $1; }
1920 ; */
1921 /* }}} */
1922 @end
1923
1924 /* JavaScript FTL: Array Comprehensions {{{ */
1925 Comprehension
1926 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1927 ;
1928
1929 ComprehensionFor
1930 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1931 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1932 ;
1933 /* }}} */
1934 /* JavaScript FTL: for each {{{ */
1935 IterationStatement
1936 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1937 ;
1938 /* }}} */
1939 /* JavaScript FTL: let Statements {{{ */
1940 LetStatement
1941 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1942 ;
1943
1944 Statement__
1945 : LetStatement
1946 ;
1947 /* }}} */
1948
1949 /* JavaScript FTW: Array Comprehensions {{{ */
1950 PrimaryExpression
1951 : ArrayComprehension
1952 ;
1953
1954 ArrayComprehension
1955 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
1956 ;
1957
1958 Comprehension
1959 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
1960 ;
1961
1962 ComprehensionTail
1963 : { $$ = NULL; }
1964 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
1965 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
1966 ;
1967
1968 ComprehensionFor
1969 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
1970 ;
1971
1972 ComprehensionIf
1973 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
1974 ;
1975 /* }}} */
1976 /* JavaScript FTW: Coalesce Operator {{{ */
1977 ConditionalExpression
1978 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1979 ;
1980 /* }}} */
1981 /* JavaScript FTW: Ruby Blocks {{{ */
1982 RubyProcParameterList_
1983 : "," RubyProcParameterList { $$ = $2; }
1984 | { $$ = NULL; }
1985 ;
1986
1987 RubyProcParameterList
1988 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1989 | { $$ = NULL; }
1990 ;
1991
1992 RubyProcParameters
1993 : LexSetRegExp "|" RubyProcParameterList "|" { $$ = $3; }
1994 | LexSetRegExp "||" { $$ = NULL; }
1995 ;
1996
1997 RubyProcParametersOpt
1998 : RubyProcParameters { $$ = $1; }
1999 | { $$ = NULL; }
2000 ;
2001
2002 RubyProcExpression
2003 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2004 ;
2005
2006 PrimaryExpression
2007 : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2008 ;
2009
2010 PostfixExpression
2011 : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
2012 ;
2013 /* }}} */
2014
2015 %%