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