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