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