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