]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
b656690195d385157fe71a51e8bdb20b6aa4ceb3
[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 | "for" { $$ = CYNew CYWord("for"); }
632 | "in" { $$ = CYNew CYWord("in"); }
633 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
634 ;
635
636 Word
637 : Identifier { $$ = $1; }
638 | "auto" { $$ = CYNew CYWord("auto"); }
639 | "break" { $$ = CYNew CYWord("break"); }
640 | "case" { $$ = CYNew CYWord("case"); }
641 | "catch" { $$ = CYNew CYWord("catch"); }
642 | "class" { $$ = CYNew CYWord("class"); }
643 | "!class" { $$ = CYNew CYWord("class"); }
644 | "const" { $$ = CYNew CYWord("const"); }
645 | "continue" { $$ = CYNew CYWord("continue"); }
646 | "debugger" { $$ = CYNew CYWord("debugger"); }
647 | "default" { $$ = CYNew CYWord("default"); }
648 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
649 | "do" { $$ = CYNew CYWord("do"); }
650 | "else" { $$ = CYNew CYWord("else"); }
651 | "enum" { $$ = CYNew CYWord("enum"); }
652 | "export" { $$ = CYNew CYWord("export"); }
653 | "extends" { $$ = CYNew CYWord("extends"); }
654 | "false" { $$ = CYNew CYWord("false"); }
655 | "finally" { $$ = CYNew CYWord("finally"); }
656 | "function" { $$ = CYNew CYWord("function"); }
657 | "if" { $$ = CYNew CYWord("if"); }
658 | "import" { $$ = CYNew CYWord("import"); }
659 | "!in" { $$ = CYNew CYWord("in"); }
660 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
661 | "null" { $$ = CYNew CYWord("null"); }
662 | "return" { $$ = CYNew CYWord("return"); }
663 | "super" { $$ = CYNew CYWord("super"); }
664 | "switch" { $$ = CYNew CYWord("switch"); }
665 | "this" { $$ = CYNew CYWord("this"); }
666 | "throw" { $$ = CYNew CYWord("throw"); }
667 | "true" { $$ = CYNew CYWord("true"); }
668 | "try" { $$ = CYNew CYWord("try"); }
669 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
670 | "var" { $$ = CYNew CYWord("var"); }
671 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
672 | "while" { $$ = CYNew CYWord("while"); }
673 | "with" { $$ = CYNew CYWord("with"); }
674
675 // XXX: should be Identifier
676 | "let" { $$ = CYNew CYIdentifier("let"); }
677 ;
678
679 @begin ObjectiveC
680 WordOpt
681 : Word { $$ = $1; }
682 | { $$ = NULL; }
683 ;
684 @end
685 /* }}} */
686 /* 11.8.1 Null Literals {{{ */
687 NullLiteral
688 : "null" { $$ = CYNew CYNull(); }
689 ;
690 /* }}} */
691 /* 11.8.2 Boolean Literals {{{ */
692 BooleanLiteral
693 : "true" { $$ = CYNew CYTrue(); }
694 | "false" { $$ = CYNew CYFalse(); }
695 ;
696 /* }}} */
697
698 /* 11.9 Automatic Semicolon Insertion {{{ */
699 StrictSemi
700 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
701 ;
702
703 TerminatorSoft
704 : ";"
705 | "\n" StrictSemi
706 ;
707
708 Terminator
709 : ";"
710 | 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
711 ;
712
713 TerminatorOpt
714 : ";"
715 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
716 ;
717 /* }}} */
718
719 /* 12.1 Identifiers {{{ */
720 IdentifierReference
721 : Identifier { $$ = CYNew CYVariable($1); }
722 // XXX: | "yield"
723 ;
724
725 BindingIdentifier
726 : Identifier { $$ = $1; }
727 // XXX: | "yield"
728 ;
729
730 LabelIdentifier
731 : Identifier { $$ = $1; }
732 // XXX: | yield
733 ;
734
735 IdentifierType
736 : Identifier_ { $$ = $1; }
737 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
738 | "await" { $$ = CYNew CYIdentifier("await"); }
739 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
740 | "byte" { $$ = CYNew CYIdentifier("byte"); }
741 | "double" { $$ = CYNew CYIdentifier("double"); }
742 | "each" { $$ = CYNew CYIdentifier("each"); }
743 | "final" { $$ = CYNew CYIdentifier("final"); }
744 | "float" { $$ = CYNew CYIdentifier("float"); }
745 | "goto" { $$ = CYNew CYIdentifier("goto"); }
746 | "implements" { $$ = CYNew CYIdentifier("implements"); }
747 | "interface" { $$ = CYNew CYIdentifier("interface"); }
748 | "native" { $$ = CYNew CYIdentifier("native"); }
749 | "of" { $$ = CYNew CYIdentifier("of"); }
750 | "package" { $$ = CYNew CYIdentifier("package"); }
751 | "private" { $$ = CYNew CYIdentifier("private"); }
752 | "protected" { $$ = CYNew CYIdentifier("protected"); }
753 | "public" { $$ = CYNew CYIdentifier("public"); }
754 | "static" { $$ = CYNew CYIdentifier("static"); }
755 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
756 | "throws" { $$ = CYNew CYIdentifier("throws"); }
757 | "transient" { $$ = CYNew CYIdentifier("transient"); }
758 | "yield" { $$ = CYNew CYIdentifier("yield"); }
759 @begin ObjectiveC
760 | "bool" { $$ = CYNew CYIdentifier("bool"); }
761 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
762 | "id" { $$ = CYNew CYIdentifier("id"); }
763 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
764 @end
765 ;
766
767 Identifier
768 : IdentifierType
769 | "char" { $$ = CYNew CYIdentifier("char"); }
770 | "int" { $$ = CYNew CYIdentifier("int"); }
771 | "long" { $$ = CYNew CYIdentifier("long"); }
772 | "short" { $$ = CYNew CYIdentifier("short"); }
773 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
774 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
775 @begin C
776 | "extern" { $$ = CYNew CYIdentifier("extern"); }
777 | "signed" { $$ = CYNew CYIdentifier("signed"); }
778 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
779 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
780 @end
781 @begin ObjectiveC
782 | "nil" { $$ = CYNew CYIdentifier("nil"); }
783 | "NO" { $$ = CYNew CYIdentifier("NO"); }
784 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
785 | "YES" { $$ = CYNew CYIdentifier("YES"); }
786 @end
787 ;
788
789 IdentifierOpt
790 : Identifier { $$ = $1; }
791 | { $$ = NULL; }
792 ;
793 /* }}} */
794 /* 12.2 Primary Expression {{{ */
795 PrimaryExpression
796 : "this" { $$ = CYNew CYThis(); }
797 | IdentifierReference { $$ = $1; }
798 | Literal { $$ = $1; }
799 | ArrayLiteral { $$ = $1; }
800 | ObjectLiteral { $$ = $1; }
801 | RegularExpressionLiteral { $$ = $1; }
802 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) error(@1, "invalid parenthetical"); $$ = $1; }
803 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
804 ;
805
806 CoverParenthesizedExpressionAndArrowParameterList
807 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
808 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
809 ;
810 /* }}} */
811 /* 12.2.4 Literals {{{ */
812 Literal
813 : NullLiteral { $$ = $1; }
814 | BooleanLiteral { $$ = $1; }
815 | NumericLiteral { $$ = $1; }
816 | StringLiteral { $$ = $1; }
817 ;
818 /* }}} */
819 /* 12.2.5 Array Initializer {{{ */
820 ArrayLiteral
821 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
822 ;
823
824 Element
825 : AssignmentExpression { $$ = $1; }
826 ;
827
828 ElementOpt
829 : Element { $$ = $1; }
830 | LexSetRegExp { $$ = NULL; }
831 ;
832
833 ElementList
834 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
835 | Element { $$ = CYNew CYElement($1, NULL); }
836 ;
837
838 ElementListOpt
839 : ElementList { $$ = $1; }
840 | LexSetRegExp { $$ = NULL; }
841 ;
842 /* }}} */
843 /* 12.2.6 Object Initializer {{{ */
844 ObjectLiteral
845 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
846 ;
847
848 PropertyDefinitionList_
849 : "," PropertyDefinitionList { $$ = $2; }
850 | "," LexSetRegExp { $$ = NULL; }
851 | { $$ = NULL; }
852 ;
853
854 PropertyDefinitionList
855 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
856 ;
857
858 PropertyDefinitionListOpt
859 : PropertyDefinitionList { $$ = $1; }
860 | LexSetRegExp { $$ = NULL; }
861 ;
862
863 PropertyDefinition
864 // XXX: this should be IdentifierName
865 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
866 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
867 //| MethodDefinition
868 ;
869
870 PropertyName_
871 : IdentifierName { $$ = $1; }
872 | StringLiteral { $$ = $1; }
873 | NumericLiteral { $$ = $1; }
874 ;
875
876 PropertyName
877 : LexSetRegExp PropertyName_ { $$ = $2; }
878 ;
879
880
881 Initializer
882 : "=" AssignmentExpression { $$ = $2; }
883 ;
884
885 InitializerOpt
886 : Initializer { $$ = $1; }
887 | { $$ = NULL; }
888 ;
889 /* }}} */
890 /* 12.2.9 Template Literals {{{ */
891 /* }}} */
892
893
894 /* 12.3+ Left-Hand-Side Expressions {{{ */
895 MemberAccess
896 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
897 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
898 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
899 ;
900
901 MemberExpression_
902 : MemberExpression { $$ = $1; }
903 //| "super" { $$ = $1; }
904 ;
905
906 MemberExpression
907 : LexSetRegExp PrimaryExpression { $$ = $2; }
908 | LexSetRegExp FunctionExpression { $$ = $2; }
909 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
910 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
911 ;
912
913 NewExpression
914 : MemberExpression { $$ = $1; }
915 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
916 ;
917
918 CallExpression_
919 : MemberExpression_
920 | CallExpression
921 ;
922
923 CallExpression
924 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
925 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
926 ;
927
928 Arguments
929 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
930 ;
931
932 ArgumentList_
933 : "," ArgumentList { $$ = $2; }
934 | { $$ = NULL; }
935 ;
936
937 ArgumentList
938 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
939 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
940 ;
941
942 ArgumentListOpt
943 : ArgumentList { $$ = $1; }
944 | LexSetRegExp { $$ = NULL; }
945 ;
946
947 LeftHandSideExpression
948 : NewExpression { $$ = $1; }
949 | CallExpression { $$ = $1; }
950 ;
951 /* }}} */
952 /* 12.4 Postfix Expressions {{{ */
953 PostfixExpression
954 : %prec "" LeftHandSideExpression { $$ = $1; }
955 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
956 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
957 ;
958 /* }}} */
959 /* 12.5 Unary Operators {{{ */
960 UnaryExpression_
961 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
962 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
963 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
964 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
965 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
966 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
967 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
968 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
969 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
970 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
971 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
972 ;
973
974 UnaryExpression
975 : PostfixExpression { $$ = $1; }
976 | LexSetRegExp UnaryExpression_ { $$ = $2; }
977 ;
978 /* }}} */
979 /* 12.6 Multiplicative Operators {{{ */
980 MultiplicativeExpression
981 : UnaryExpression { $$ = $1; }
982 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
983 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
984 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
985 ;
986 /* }}} */
987 /* 12.7 Additive Operators {{{ */
988 AdditiveExpression
989 : MultiplicativeExpression { $$ = $1; }
990 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
991 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
992 ;
993 /* }}} */
994 /* 12.8 Bitwise Shift Operators {{{ */
995 ShiftExpression
996 : AdditiveExpression { $$ = $1; }
997 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
998 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
999 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1000 ;
1001 /* }}} */
1002 /* 12.9 Relational Operators {{{ */
1003 RelationalExpression
1004 : ShiftExpression { $$ = $1; }
1005 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1006 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1007 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1008 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1009 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1010 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1011 ;
1012 /* }}} */
1013 /* 12.10 Equality Operators {{{ */
1014 EqualityExpression
1015 : RelationalExpression { $$ = $1; }
1016 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1017 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1018 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1019 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1020 ;
1021 /* }}} */
1022 /* 12.11 Binary Bitwise Operators {{{ */
1023 BitwiseANDExpression
1024 : EqualityExpression { $$ = $1; }
1025 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1026 ;
1027
1028 BitwiseXORExpression
1029 : BitwiseANDExpression { $$ = $1; }
1030 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1031 ;
1032
1033 BitwiseORExpression
1034 : BitwiseXORExpression { $$ = $1; }
1035 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1036 ;
1037 /* }}} */
1038 /* 12.12 Binary Logical Operators {{{ */
1039 LogicalANDExpression
1040 : BitwiseORExpression { $$ = $1; }
1041 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1042 ;
1043
1044 LogicalORExpression
1045 : LogicalANDExpression { $$ = $1; }
1046 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1047 ;
1048 /* }}} */
1049 /* 12.13 Conditional Operator ( ? : ) {{{ */
1050 ConditionalExpression
1051 : LogicalORExpression { $$ = $1; }
1052 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1053 ;
1054 /* }}} */
1055 /* 12.14 Assignment Operators {{{ */
1056 AssignmentExpression
1057 : ConditionalExpression { $$ = $1; }
1058 // XXX: | YieldExpression { $$ = $1; }
1059 | ArrowFunction { $$ = $1; }
1060 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1061 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1062 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1063 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1064 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1065 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1066 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1067 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1068 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1069 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1070 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1071 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1072 ;
1073 /* }}} */
1074 /* 12.15 Comma Operator ( , ) {{{ */
1075 Expression
1076 : AssignmentExpression { $$ = $1; }
1077 /* XXX: I have this backwards... */
1078 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1079 ;
1080
1081 ExpressionOpt
1082 : Expression { $$ = $1; }
1083 | LexSetRegExp { $$ = NULL; }
1084 ;
1085 /* }}} */
1086
1087 /* 13 Statements and Declarations {{{ */
1088 Statement__
1089 : BlockStatement { $$ = $1; }
1090 | VariableStatement { $$ = $1; }
1091 | EmptyStatement { $$ = $1; }
1092 | IfStatement { $$ = $1; }
1093 | BreakableStatement { $$ = $1; }
1094 | ContinueStatement { $$ = $1; }
1095 | BreakStatement { $$ = $1; }
1096 | ReturnStatement { $$ = $1; }
1097 | WithStatement { $$ = $1; }
1098 | LabelledStatement { $$ = $1; }
1099 | ThrowStatement { $$ = $1; }
1100 | TryStatement { $$ = $1; }
1101 | DebuggerStatement { $$ = $1; }
1102 ;
1103
1104 Statement_
1105 : LexSetRegExp Statement__ { $$ = $2; }
1106 | ExpressionStatement { $$ = $1; }
1107 ;
1108
1109 Statement
1110 : LexSetStatement Statement_ { $$ = $2; }
1111 ;
1112
1113 Declaration__
1114 : HoistableDeclaration { $$ = $1; }
1115 // XXX: | ClassDeclaration { $$ = $1; }
1116 | LexicalDeclaration { $$ = $1; }
1117 ;
1118
1119 Declaration_
1120 : LexSetRegExp Declaration__ { $$ = $2; }
1121 ;
1122
1123 Declaration
1124 : LexSetStatement Declaration_ { $$ = $2; }
1125 ;
1126
1127 HoistableDeclaration
1128 : FunctionDeclaration
1129 // XXX: | GeneratorDeclaration
1130 ;
1131
1132 BreakableStatement
1133 : IterationStatement { $$ = $1; }
1134 | SwitchStatement { $$ = $1; }
1135 ;
1136 /* }}} */
1137 /* 13.2 Block {{{ */
1138 BlockStatement
1139 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1140 ;
1141
1142 Block
1143 : BRACE StatementListOpt "}" { $$ = $2; }
1144 ;
1145
1146 StatementList
1147 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1148 ;
1149
1150 StatementListOpt
1151 : StatementList { $$ = $1; }
1152 | LexSetStatement LexSetRegExp { $$ = NULL; }
1153 ;
1154
1155 StatementListItem
1156 : Statement { $$ = $1; }
1157 | Declaration { $$ = $1; }
1158 ;
1159 /* }}} */
1160 /* 13.3+ Let and Const Declarations {{{ */
1161 LexicalDeclaration
1162 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1163 ;
1164
1165 LetOrConst
1166 : "let"
1167 | "const"
1168 ;
1169
1170 Binding
1171 : BindingIdentifier
1172 ;
1173
1174 // XXX: lots of binding stuff
1175 /* }}} */
1176 /* 13.3.2+ Variable Statement {{{ */
1177 VariableStatement
1178 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1179 ;
1180
1181 VariableDeclarationList_
1182 : "," VariableDeclarationList { $$ = $2; }
1183 | { $$ = NULL; }
1184 ;
1185
1186 VariableDeclarationList
1187 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1188 ;
1189
1190 VariableDeclaration
1191 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1192 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1193 ;
1194 /* }}} */
1195 /* 13.3.3+ Destructuring Binding Patterns {{{ */
1196 // XXX: *
1197
1198 BindingElement
1199 : SingleNameBinding { $$ = $1; }
1200 ;
1201
1202 SingleNameBinding
1203 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1204 ;
1205 /* }}} */
1206 /* 13.4 Empty Statement {{{ */
1207 EmptyStatement
1208 : ";" { $$ = CYNew CYEmpty(); }
1209 ;
1210 /* }}} */
1211 /* 13.5 Expression Statement {{{ */
1212 ExpressionStatement
1213 : Expression Terminator { $$ = CYNew CYExpress($1); }
1214 ;
1215 /* }}} */
1216 /* 13.6 The if Statement {{{ */
1217 ElseStatementOpt
1218 : "else" Statement { $$ = $2; }
1219 | %prec "if" { $$ = NULL; }
1220 ;
1221
1222 IfStatement
1223 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1224 ;
1225 /* }}} */
1226 /* 13.7+ Iteration Statements {{{ */
1227 IterationStatement
1228 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1229 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1230 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1231 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1232 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1233 ;
1234
1235 ForStatementInitializer
1236 : ExpressionOpt { $$ = $1; }
1237 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1238 ;
1239
1240 ForInStatementInitializer
1241 : LeftHandSideExpression { $$ = $1; }
1242 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1243 ;
1244 /* }}} */
1245 /* 13.8 The continue Statement {{{ */
1246 Continue
1247 : "continue" LexNoNewLine
1248 ;
1249
1250 ContinueStatement
1251 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1252 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1253 ;
1254 /* }}} */
1255 /* 13.9 The break Statement {{{ */
1256 Break
1257 : "break" LexNoNewLine
1258 ;
1259
1260 BreakStatement
1261 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1262 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1263 ;
1264 /* }}} */
1265 /* 13.10 The return Statement {{{ */
1266 Return
1267 : "return" LexNoNewLine
1268 ;
1269
1270 ReturnStatement
1271 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1272 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1273 ;
1274 /* }}} */
1275 /* 13.11 The with Statement {{{ */
1276 WithStatement
1277 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1278 ;
1279 /* }}} */
1280 /* 13.12 The switch Statement {{{ */
1281 SwitchStatement
1282 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1283 ;
1284
1285 CaseBlock
1286 : BRACE CaseClausesOpt "}" { $$ = $2; }
1287 ;
1288
1289 CaseClause
1290 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1291 ;
1292
1293 CaseClausesOpt
1294 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1295 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1296 | { $$ = NULL; }
1297 ;
1298
1299 // XXX: the standard makes certain you can only have one of these
1300 DefaultClause
1301 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1302 ;
1303 /* }}} */
1304 /* 13.13 Labelled Statements {{{ */
1305 LabelledStatement
1306 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1307 ;
1308
1309 LabelledItem
1310 : Statement { $$ = $1; }
1311 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1312 ;
1313 /* }}} */
1314 /* 13.14 The throw Statement {{{ */
1315 Throw
1316 : "throw" LexNoNewLine
1317 ;
1318
1319 ThrowStatement
1320 : Throw LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1321 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1322 ;
1323 /* }}} */
1324 /* 13.15 The try Statement {{{ */
1325 TryStatement
1326 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1327 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1328 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1329 ;
1330
1331 Catch
1332 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1333 ;
1334
1335 Finally
1336 : "finally" Block { $$ = CYNew CYFinally($2); }
1337 ;
1338
1339 CatchParameter
1340 : BindingIdentifier { $$ = $1; }
1341 // XXX: BindingPattern
1342 ;
1343 /* }}} */
1344 /* 13.16 The debugger Statement {{{ */
1345 DebuggerStatement
1346 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1347 ;
1348 /* }}} */
1349
1350 /* 14.1+ Function Definitions {{{ */
1351 FunctionDeclaration
1352 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1353 ;
1354
1355 FunctionExpression
1356 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1357 ;
1358
1359 FormalParameterList_
1360 : "," FormalParameterList { $$ = $2; }
1361 | { $$ = NULL; }
1362 ;
1363
1364 FormalParameterList
1365 // XXX: : FunctionRestParameter { $$ = $1; }
1366 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1367 ;
1368
1369 FormalParameterListOpt
1370 : FormalParameterList
1371 | { $$ = NULL; }
1372 ;
1373
1374 /* XXX: FunctionRestParameter
1375 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1376 ;*/
1377
1378 FormalParameter
1379 : BindingElement { $$ = $1; }
1380 ;
1381
1382 FunctionBody
1383 : StatementListOpt { $$ = $1; }
1384 ;
1385 /* }}} */
1386 /* 14.2 Arrow Function Definitions {{{ */
1387 ArrowFunction
1388 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1389 ;
1390
1391 ArrowParameters
1392 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1393 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1394 ;
1395
1396 ConciseBody
1397 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1398 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1399 ;
1400 /* }}} */
1401 /* 14.3+ Method Definitions {{{ */
1402 /* }}} */
1403 /* 14.4+ Generator Function Definitions {{{ */
1404 /* }}} */
1405 /* 14.5+ Class Definitions {{{ */
1406 /* }}} */
1407
1408 /* 15.1 Scripts {{{ */
1409 Script
1410 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1411 ;
1412
1413 ScriptBody
1414 : StatementList { $$ = $1; }
1415 ;
1416
1417 ScriptBodyOpt
1418 : ScriptBody { $$ = $1; }
1419 | LexSetStatement LexSetRegExp { $$ = NULL; }
1420 ;
1421 /* }}} */
1422 /* 15.2+ Modules {{{ */
1423 /* }}} */
1424 /* 15.2.2+ Imports {{{ */
1425 /* }}} */
1426 /* 15.2.3+ Exports {{{ */
1427 /* }}} */
1428
1429 @begin C
1430 /* Cycript (C): Type Encoding {{{ */
1431 TypeSignifier
1432 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1433 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1434 ;
1435
1436 SuffixedType
1437 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1438 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1439 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1440 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1441 | TypeSignifier { $$ = $1; }
1442 | { $$ = CYNew CYTypedIdentifier(@$); }
1443 ;
1444
1445 PrefixedType
1446 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1447 ;
1448
1449 TypeQualifierLeft
1450 : { $$ = NULL; }
1451 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1452 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1453 ;
1454
1455 TypeQualifierRight
1456 : PrefixedType { $$ = $1; }
1457 | SuffixedType { $$ = $1; }
1458 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1459 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1460 ;
1461
1462 IntegerType
1463 : "int" { $$ = CYNew CYTypeVariable("int"); }
1464 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1465 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1466 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1467 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1468 ;
1469
1470 IntegerTypeOpt
1471 : IntegerType { $$ = $1; }
1472 | { $$ = CYNew CYTypeVariable("int"); }
1473 ;
1474
1475 PrimitiveType
1476 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1477 | IntegerType { $$ = $1; }
1478 | "void" { $$ = CYNew CYTypeVoid(); }
1479 | "char" { $$ = CYNew CYTypeVariable("char"); }
1480 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1481 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1482 ;
1483
1484 TypedIdentifier
1485 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1486 ;
1487
1488 PrimaryExpression
1489 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1490 ;
1491 /* }}} */
1492 @end
1493
1494 @begin ObjectiveC
1495 /* Cycript (Objective-C): @class Declaration {{{ */
1496 ClassSuperOpt
1497 /* XXX: why the hell did I choose MemberExpression? */
1498 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1499 | { $$ = NULL; }
1500 ;
1501
1502 ClassFieldListOpt
1503 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1504 | LexSetRegExp { $$ = NULL; }
1505 ;
1506
1507 ClassFields
1508 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1509 ;
1510
1511 MessageScope
1512 : "+" { $$ = false; }
1513 | "-" { $$ = true; }
1514 ;
1515
1516 TypeOpt
1517 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1518 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1519 ;
1520
1521 MessageParameter
1522 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1523 ;
1524
1525 MessageParameterList
1526 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1527 ;
1528
1529 MessageParameterListOpt
1530 : MessageParameterList { $$ = $1; }
1531 | { $$ = NULL; }
1532 ;
1533
1534 MessageParameters
1535 : MessageParameterList { $$ = $1; }
1536 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1537 ;
1538
1539 ClassMessageDeclaration
1540 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1541 ;
1542
1543 ClassMessageDeclarationListOpt
1544 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1545 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1546 | { $$ = NULL; }
1547 ;
1548
1549 ClassName
1550 : Identifier { $$ = $1; }
1551 | "(" AssignmentExpression ")" { $$ = $2; }
1552 ;
1553
1554 ClassNameOpt
1555 : ClassName { $$ = $1; }
1556 | { $$ = NULL; }
1557 ;
1558
1559 // XXX: this should be AssignmentExpressionNoRight
1560 ClassProtocols
1561 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1562 ;
1563
1564 ClassProtocolsOpt
1565 : "," ClassProtocols { $$ = $2; }
1566 | { $$ = NULL; }
1567 ;
1568
1569 ClassProtocolListOpt
1570 : "<" ClassProtocols ">" { $$ = $2; }
1571 | { $$ = NULL; }
1572 ;
1573
1574 ClassExpression
1575 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1576 ;
1577
1578 ClassStatement
1579 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1580 ;
1581
1582 CategoryName
1583 : "(" WordOpt ")"
1584 ;
1585
1586 CategoryStatement
1587 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1588 ;
1589
1590 PrimaryExpression
1591 : ClassExpression { $$ = $1; }
1592 ;
1593
1594 Statement__
1595 : ClassStatement { $$ = $1; }
1596 | CategoryStatement { $$ = $1; }
1597 ;
1598 /* }}} */
1599 /* Cycript (Objective-C): Send Message {{{ */
1600 VariadicCall
1601 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1602 | { $$ = NULL; }
1603 ;
1604
1605 SelectorWordOpt
1606 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1607 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1608 ;
1609
1610 SelectorCall_
1611 : SelectorCall { $$ = $1; }
1612 | VariadicCall { $$ = $1; }
1613 ;
1614
1615 SelectorCall
1616 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1617 ;
1618
1619 SelectorList
1620 : SelectorCall { $$ = $1; }
1621 | Word { $$ = CYNew CYArgument($1, NULL); }
1622 ;
1623
1624 MessageExpression
1625 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1626 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1627 ;
1628
1629 SelectorExpression_
1630 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1631 ;
1632
1633 SelectorExpression
1634 : SelectorExpression_ { $$ = $1; }
1635 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1636 ;
1637
1638 SelectorExpressionOpt
1639 : SelectorExpression_ { $$ = $1; }
1640 | { $$ = NULL; }
1641 ;
1642
1643 PrimaryExpression
1644 : MessageExpression { $$ = $1; }
1645 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1646 ;
1647 /* }}} */
1648 @end
1649
1650 /* Cycript: @import Directive {{{ */
1651 Module
1652 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1653 | Word { $$ = CYNew CYModule($1); }
1654 ;
1655
1656 Declaration__
1657 : "@import" Module { $$ = CYNew CYImport($2); }
1658 ;
1659 /* }}} */
1660
1661 @begin ObjectiveC
1662 /* Cycript (Objective-C): Boxed Expressions {{{ */
1663 BoxableExpression
1664 : NullLiteral { $$ = $1; }
1665 | BooleanLiteral { $$ = $1; }
1666 | NumericLiteral { $$ = $1; }
1667 | StringLiteral { $$ = $1; }
1668 | ArrayLiteral { $$ = $1; }
1669 | ObjectLiteral { $$ = $1; }
1670 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
1671 | "YES" { $$ = CYNew CYTrue(); }
1672 | "NO" { $$ = CYNew CYFalse(); }
1673 ;
1674
1675 PrimaryExpression
1676 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1677 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1678 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1679 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1680 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1681 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1682 ;
1683 /* }}} */
1684 /* Cycript (Objective-C): Block Expressions {{{ */
1685 PrimaryExpression
1686 : "^" 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"); }
1687 ;
1688 /* }}} */
1689 /* Cycript (Objective-C): Instance Literals {{{ */
1690 PrimaryExpression
1691 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1692 ;
1693 /* }}} */
1694 @end
1695
1696 @begin C
1697 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1698 LeftHandSideExpression
1699 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1700 ;
1701
1702 UnaryExpression_
1703 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1704 ;
1705
1706 MemberAccess
1707 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1708 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1709 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1710 ;
1711 /* }}} */
1712 /* Cycript (C): auto Compatibility {{{ */
1713 Var_
1714 : "auto"
1715 ;
1716 /* }}} */
1717 /* Cycript (C): Lambda Expressions {{{ */
1718 TypedParameterList_
1719 : "," TypedParameterList { $$ = $2; }
1720 | { $$ = NULL; }
1721 ;
1722
1723 TypedParameterList
1724 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1725 ;
1726
1727 TypedParameterListOpt
1728 : TypedParameterList { $$ = $1; }
1729 | { $$ = NULL; }
1730 ;
1731
1732 PrimaryExpression
1733 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1734 ;
1735 /* }}} */
1736 /* Cycript (C): Type Definitions {{{ */
1737 Statement__
1738 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1739 ;
1740 /* }}} */
1741 /* Cycript (C): extern "C" {{{ */
1742 Statement__
1743 : "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); }
1744 ;
1745 /* }}} */
1746
1747 @end
1748
1749 /* YUI: Documentation Comments {{{ */
1750 Statement__
1751 : Comment { $$ = $1; }
1752 ;
1753 /* }}} */
1754
1755 @begin E4X
1756 /* Lexer State {{{ */
1757 LexPushRegExp
1758 : { driver.PushCondition(CYDriver::RegExpCondition); }
1759 ;
1760
1761 LexPushXMLContent
1762 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1763 ;
1764
1765 LexPushXMLTag
1766 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1767 ;
1768
1769 LexPop
1770 : { driver.PopCondition(); }
1771 ;
1772
1773 LexSetXMLContent
1774 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1775 ;
1776
1777 LexSetXMLTag
1778 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1779 ;
1780 /* }}} */
1781 /* Virtual Tokens {{{ */
1782 XMLWhitespaceOpt
1783 : XMLWhitespace
1784 |
1785 ;
1786 /* }}} */
1787
1788 /* 8.1 Context Keywords {{{ */
1789 Identifier
1790 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1791 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1792 ;
1793 /* }}} */
1794 /* 8.3 XML Initializer Input Elements {{{ */
1795 XMLMarkup
1796 : XMLComment { $$ = $1; }
1797 | XMLCDATA { $$ = $1; }
1798 | XMLPI { $$ = $1; }
1799 ;
1800 /* }}} */
1801
1802 /* 11.1 Primary Expressions {{{ */
1803 PrimaryExpression
1804 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1805 | XMLInitialiser { $$ = $1; }
1806 | XMLListInitialiser { $$ = $1; }
1807 ;
1808
1809 PropertyIdentifier
1810 : AttributeIdentifier { $$ = $1; }
1811 | QualifiedIdentifier { $$ = $1; }
1812 | WildcardIdentifier { $$ = $1; }
1813 ;
1814 /* }}} */
1815 /* 11.1.1 Attribute Identifiers {{{ */
1816 AttributeIdentifier
1817 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1818 ;
1819
1820 PropertySelector_
1821 : PropertySelector { $$ = $1; }
1822 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1823 ;
1824
1825 PropertySelector
1826 : Identifier { $$ = CYNew CYSelector($1); }
1827 | WildcardIdentifier { $$ = $1; }
1828 ;
1829 /* }}} */
1830 /* 11.1.2 Qualified Identifiers {{{ */
1831 QualifiedIdentifier_
1832 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1833 | QualifiedIdentifier { $$ = $1; }
1834 ;
1835
1836 QualifiedIdentifier
1837 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1838 ;
1839 /* }}} */
1840 /* 11.1.3 Wildcard Identifiers {{{ */
1841 WildcardIdentifier
1842 : "*" { $$ = CYNew CYWildcard(); }
1843 ;
1844 /* }}} */
1845 /* 11.1.4 XML Initializer {{{ */
1846 XMLInitialiser
1847 : XMLMarkup { $$ = $1; }
1848 | XMLElement { $$ = $1; }
1849 ;
1850
1851 XMLElement
1852 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1853 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1854 ;
1855
1856 XMLTagContent
1857 : LexPushXMLTag XMLTagName XMLAttributes
1858 ;
1859
1860 XMLExpression
1861 : BRACE LexPushRegExp Expression LexPop "}"
1862 ;
1863
1864 XMLTagName
1865 : XMLExpression
1866 | XMLName
1867 ;
1868
1869 XMLAttributes_
1870 : XMLAttributes_ XMLAttribute
1871 |
1872 ;
1873
1874 XMLAttributes
1875 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1876 | XMLAttributes_ XMLWhitespaceOpt
1877 ;
1878
1879 XMLAttributeValue_
1880 : XMLExpression
1881 | XMLAttributeValue
1882 ;
1883
1884 XMLAttribute
1885 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1886 ;
1887
1888 XMLElementContent
1889 : XMLExpression XMLElementContentOpt
1890 | XMLMarkup XMLElementContentOpt
1891 | XMLText XMLElementContentOpt
1892 | XMLElement XMLElementContentOpt
1893 ;
1894
1895 XMLElementContentOpt
1896 : XMLElementContent
1897 |
1898 ;
1899 /* }}} */
1900 /* 11.1.5 XMLList Initializer {{{ */
1901 XMLListInitialiser
1902 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1903 ;
1904 /* }}} */
1905
1906 /* 11.2 Left-Hand-Side Expressions {{{ */
1907 PropertyIdentifier_
1908 : Identifier { $$ = $1; }
1909 | PropertyIdentifier { $$ = $1; }
1910 ;
1911
1912 MemberAccess
1913 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1914 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1915 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1916 ;
1917 /* }}} */
1918 /* 12.1 The default xml namespace Statement {{{ */
1919 /* XXX: DefaultXMLNamespaceStatement
1920 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1921 ;
1922
1923 Statement__
1924 : DefaultXMLNamespaceStatement { $$ = $1; }
1925 ; */
1926 /* }}} */
1927 @end
1928
1929 /* JavaScript FTL: Array Comprehensions {{{ */
1930 Comprehension
1931 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1932 ;
1933
1934 ComprehensionFor
1935 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1936 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1937 ;
1938 /* }}} */
1939 /* JavaScript FTL: for each {{{ */
1940 IterationStatement
1941 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1942 ;
1943 /* }}} */
1944 /* JavaScript FTL: let Statements {{{ */
1945 LetStatement
1946 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1947 ;
1948
1949 Statement__
1950 : LetStatement
1951 ;
1952 /* }}} */
1953
1954 /* JavaScript FTW: Array Comprehensions {{{ */
1955 PrimaryExpression
1956 : ArrayComprehension
1957 ;
1958
1959 ArrayComprehension
1960 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
1961 ;
1962
1963 Comprehension
1964 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
1965 ;
1966
1967 ComprehensionTail
1968 : { $$ = NULL; }
1969 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
1970 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
1971 ;
1972
1973 ComprehensionFor
1974 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
1975 ;
1976
1977 ComprehensionIf
1978 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
1979 ;
1980 /* }}} */
1981 /* JavaScript FTW: Coalesce Operator {{{ */
1982 ConditionalExpression
1983 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1984 ;
1985 /* }}} */
1986 /* JavaScript FTW: Ruby Blocks {{{ */
1987 RubyProcParameterList_
1988 : "," RubyProcParameterList { $$ = $2; }
1989 | { $$ = NULL; }
1990 ;
1991
1992 RubyProcParameterList
1993 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1994 | { $$ = NULL; }
1995 ;
1996
1997 RubyProcParameters
1998 : "|" RubyProcParameterList "|" { $$ = $2; }
1999 | "||" { $$ = NULL; }
2000 ;
2001
2002 RubyProcParametersOpt
2003 : RubyProcParameters
2004 | { $$ = NULL; }
2005 ;
2006
2007 RubyProcExpression
2008 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2009 ;
2010
2011 PrimaryExpression
2012 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2013 ;
2014
2015 CallExpression
2016 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
2017 ;
2018 /* }}} */
2019
2020 %%