]> git.saurik.com Git - cycript.git/blob - Parser.ypp.in
Parse array binding patterns (I skipped these :/).
[cycript.git] / Parser.ypp.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 YYSTACKEXPANDABLE 1
24 }
25
26 %code requires {
27 #include "Driver.hpp"
28 #include "Parser.hpp"
29 #include "Stack.hpp"
30 #define CYNew new(driver.pool_)
31
32 @begin ObjectiveC
33 #include "ObjectiveC/Syntax.hpp"
34 @end
35
36 @begin E4X
37 #include "E4X/Syntax.hpp"
38 @end
39
40 #include "Highlight.hpp"
41 }
42
43 %union { bool bool_; }
44
45 %union { CYMember *access_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBinding *binding_; }
49 %union { CYBindings *bindings_; }
50 %union { CYBoolean *boolean_; }
51 %union { CYClause *clause_; }
52 %union { cy::Syntax::Catch *catch_; }
53 %union { CYClassTail *classTail_; }
54 %union { CYComprehension *comprehension_; }
55 %union { CYElement *element_; }
56 %union { CYExpression *expression_; }
57 %union { CYFalse *false_; }
58 %union { CYVariable *variable_; }
59 %union { CYFinally *finally_; }
60 %union { CYForInitializer *for_; }
61 %union { CYForInInitializer *forin_; }
62 %union { CYFunctionParameter *functionParameter_; }
63 %union { CYIdentifier *identifier_; }
64 %union { CYInfix *infix_; }
65 %union { CYLiteral *literal_; }
66 %union { CYMethod *method_; }
67 %union { CYModule *module_; }
68 %union { CYNull *null_; }
69 %union { CYNumber *number_; }
70 %union { CYParenthetical *parenthetical_; }
71 %union { CYProperty *property_; }
72 %union { CYPropertyName *propertyName_; }
73 %union { CYRubyProc *rubyProc_; }
74 %union { CYSpan *span_; }
75 %union { CYStatement *statement_; }
76 %union { CYString *string_; }
77 %union { CYTarget *target_; }
78 %union { CYThis *this_; }
79 %union { CYTrue *true_; }
80 %union { CYWord *word_; }
81
82 @begin C
83 %union { CYTypeModifier *modifier_; }
84 %union { CYTypeSpecifier *specifier_; }
85 %union { CYTypedIdentifier *typedIdentifier_; }
86 %union { CYTypedParameter *typedParameter_; }
87 @end
88
89 @begin ObjectiveC
90 %union { CYMessage *message_; }
91 %union { CYMessageParameter *messageParameter_; }
92 %union { CYImplementationField *implementationField_; }
93 %union { CYProtocol *protocol_; }
94 %union { CYSelectorPart *selector_; }
95 @end
96
97 @begin E4X
98 %union { CYAttribute *attribute_; }
99 %union { CYPropertyIdentifier *propertyIdentifier_; }
100 %union { CYSelector *selector_; }
101 @end
102
103 %code provides {
104
105 struct YYSTYPE {
106 cy::parser::semantic_type semantic_;
107 hi::Value highlight_;
108 };
109
110 int cylex(YYSTYPE *, CYLocation *, void *);
111
112 }
113
114 %code {
115
116 #undef yylex
117
118 typedef cy::parser::token tk;
119
120 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
121 driver.newline_ = false;
122 lex:
123 YYSTYPE data;
124 int token(cylex(&data, location, driver.scanner_));
125 *semantic = data.semantic_;
126
127 switch (token) {
128 case tk::OpenBrace:
129 case tk::OpenBracket:
130 case tk::OpenParen:
131 driver.in_.push(false);
132 break;
133
134 case tk::_in_:
135 if (driver.in_.top())
136 token = tk::_in__;
137 break;
138
139 case tk::CloseBrace:
140 case tk::CloseBracket:
141 case tk::CloseParen:
142 driver.in_.pop();
143 break;
144
145
146 case tk::_yield_:
147 if (driver.yield_.top())
148 token = tk::_yield__;
149 break;
150
151 case tk::NewLine:
152 driver.newline_ = true;
153 goto lex;
154 break;
155 }
156
157 return token;
158 }
159
160 #define yylex_(semantic, location, driver) ({ \
161 int type; \
162 if (driver.hold_ == cy::parser::empty_symbol) \
163 type = yytranslate_(cylex_(semantic, location, driver)); \
164 else { \
165 type = driver.hold_; \
166 driver.hold_ = cy::parser::empty_symbol; \
167 } \
168 type; })
169
170 #define CYLEX() do if (yyla.empty()) { \
171 YYCDEBUG << "Mapping a token: "; \
172 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
173 YY_SYMBOL_PRINT("Next token is", yyla); \
174 } while (false)
175
176 #define CYMAP(to, from) do { \
177 CYLEX(); \
178 if (yyla.type == yytranslate_(token::from)) \
179 yyla.type = yytranslate_(token::to); \
180 } while (false)
181
182 #define CYERR(location, message) do { \
183 error(location, message); \
184 YYABORT; \
185 } while (false)
186
187 #define CYEOK() do { \
188 yyerrok; \
189 driver.errors_.pop_back(); \
190 } while (false)
191
192 #define CYNOT(location) \
193 CYERR(location, "unimplemented feature")
194
195 #define CYMPT(location) do { \
196 if (!yyla.empty() && yyla.type_get() != yyeof_) \
197 CYERR(location, "unexpected lookahead"); \
198 } while (false)
199
200 }
201
202 %name-prefix "cy"
203
204 %language "C++"
205
206 %initial-action {
207 @$.begin.filename = @$.end.filename = &driver.filename_;
208
209 switch (driver.mark_) {
210 case CYMarkScript:
211 driver.hold_ = yytranslate_(token::MarkScript);
212 break;
213 case CYMarkModule:
214 driver.hold_ = yytranslate_(token::MarkModule);
215 break;
216 }
217 };
218
219 %locations
220 %defines
221
222 %define api.location.type { CYLocation }
223
224 //%glr-parser
225 //%expect 1
226
227 %error-verbose
228
229 %param { CYDriver &driver }
230
231 /* Token Declarations {{{ */
232 @begin E4X
233 %token XMLCDATA
234 %token XMLComment
235 %token XMLPI
236
237 %token XMLAttributeValue
238 %token XMLName
239 %token XMLTagCharacters
240 %token XMLText
241 %token XMLWhitespace
242 @end
243
244 @begin E4X
245 %token LeftRight "<>"
246 %token LeftSlashRight "</>"
247
248 %token SlashRight "/>"
249 %token LeftSlash "</"
250
251 %token ColonColon "::"
252 %token PeriodPeriod ".."
253 @end
254
255 @begin E4X ObjectiveC
256 %token At "@"
257 %token Pound "#"
258 @end
259
260 %token Ampersand "&"
261 %token AmpersandAmpersand "&&"
262 %token AmpersandEqual "&="
263 %token Carrot "^"
264 %token CarrotEqual "^="
265 %token Equal "="
266 %token EqualEqual "=="
267 %token EqualEqualEqual "==="
268 %token EqualRight "=>"
269 %token Exclamation "!"
270 %token ExclamationEqual "!="
271 %token ExclamationEqualEqual "!=="
272 %token Hyphen "-"
273 %token HyphenEqual "-="
274 %token HyphenHyphen "--"
275 %token HyphenRight "->"
276 %token Left "<"
277 %token LeftEqual "<="
278 %token LeftLeft "<<"
279 %token LeftLeftEqual "<<="
280 %token Percent "%"
281 %token PercentEqual "%="
282 %token Period "."
283 %token PeriodPeriodPeriod "..."
284 %token Pipe "|"
285 %token PipeEqual "|="
286 %token PipePipe "||"
287 %token Plus "+"
288 %token PlusEqual "+="
289 %token PlusPlus "++"
290 %token Right ">"
291 %token RightEqual ">="
292 %token RightRight ">>"
293 %token RightRightEqual ">>="
294 %token RightRightRight ">>>"
295 %token RightRightRightEqual ">>>="
296 %token Slash "/"
297 %token SlashEqual "/="
298 %token Star "*"
299 %token StarEqual "*="
300 %token Tilde "~"
301
302 %token Colon ":"
303 %token Comma ","
304 %token Question "?"
305 %token SemiColon ";"
306 %token NewLine "\n"
307
308 %token Comment
309
310 %token OpenParen "("
311 %token CloseParen ")"
312
313 %token OpenBrace "{"
314 %token OpenBrace_ ";{"
315 %token OpenBrace_let "let {"
316 %token CloseBrace "}"
317
318 %token OpenBracket "["
319 %token OpenBracket_let "let ["
320 %token CloseBracket "]"
321
322 %token At_error_ "@error"
323
324 @begin Java
325 %token At_class_ "@class"
326 @end
327
328 @begin C
329 %token _typedef_ "typedef"
330 %token _unsigned_ "unsigned"
331 %token _signed_ "signed"
332 %token _extern_ "extern"
333 @end
334
335 @begin C
336 %token At_encode_ "@encode"
337 @end
338
339 @begin ObjectiveC
340 %token At_implementation_ "@implementation"
341 %token At_import_ "@import"
342 %token At_end_ "@end"
343 %token At_selector_ "@selector"
344 %token At_null_ "@null"
345 %token At_YES_ "@YES"
346 %token At_NO_ "@NO"
347 %token At_true_ "@true"
348 %token At_false_ "@false"
349 %token _YES_ "YES"
350 %token _NO_ "NO"
351 @end
352
353 %token _false_ "false"
354 %token _null_ "null"
355 %token _true_ "true"
356
357 %token _break_ "break"
358 %token _case_ "case"
359 %token _catch_ "catch"
360 %token _class_ "class"
361 %token _class__ ";class"
362 %token _const_ "const"
363 %token _continue_ "continue"
364 %token _debugger_ "debugger"
365 %token _default_ "default"
366 %token _delete_ "delete"
367 %token _do_ "do"
368 %token _else_ "else"
369 %token _enum_ "enum"
370 %token _export_ "export"
371 %token _extends_ "extends"
372 %token _finally_ "finally"
373 %token _for_ "for"
374 %token _function_ "function"
375 %token _function__ ";function"
376 %token _if_ "if"
377 %token _import_ "import"
378 %token _in_ "in"
379 %token _in__ "!in"
380 %token _Infinity_ "Infinity"
381 %token _instanceof_ "instanceof"
382 %token _new_ "new"
383 %token _return_ "return"
384 %token _super_ "super"
385 %token _switch_ "switch"
386 %token _target_ "target"
387 %token _this_ "this"
388 %token _throw_ "throw"
389 %token _try_ "try"
390 %token _typeof_ "typeof"
391 %token _var_ "var"
392 %token _void_ "void"
393 %token _while_ "while"
394 %token _with_ "with"
395
396 %token _abstract_ "abstract"
397 %token _await_ "await"
398 %token _boolean_ "boolean"
399 %token _byte_ "byte"
400 %token _char_ "char"
401 %token _constructor_ "constructor"
402 %token _double_ "double"
403 %token _eval_ "eval"
404 %token _final_ "final"
405 %token _float_ "float"
406 %token _from_ "from"
407 %token _get_ "get"
408 %token _goto_ "goto"
409 %token _implements_ "implements"
410 %token _int_ "int"
411 %token _interface_ "interface"
412 %token _let_ "let"
413 %token _let__ "!let"
414 %token _long_ "long"
415 %token _native_ "native"
416 %token _package_ "package"
417 %token _private_ "private"
418 %token _protected_ "protected"
419 %token _prototype_ "prototype"
420 %token _public_ "public"
421 %token _set_ "set"
422 %token _short_ "short"
423 %token _static_ "static"
424 %token _synchronized_ "synchronized"
425 %token _throws_ "throws"
426 %token _transient_ "transient"
427 %token _volatile_ "volatile"
428 %token _yield_ "yield"
429 %token _yield__ "!yield"
430
431 %token _undefined_ "undefined"
432
433 @begin ObjectiveC
434 %token _bool_ "bool"
435 %token _BOOL_ "BOOL"
436 %token _id_ "id"
437 %token _nil_ "nil"
438 %token _NULL_ "NULL"
439 %token _SEL_ "SEL"
440 @end
441
442 %token _auto_ "auto"
443 %token _each_ "each"
444 %token _of_ "of"
445 %token _of__ "!of"
446
447 @begin E4X
448 %token _namespace_ "namespace"
449 %token _xml_ "xml"
450 @end
451
452 %token AutoComplete
453 %token YieldStar
454
455 %token <identifier_> Identifier_
456 %token <number_> NumericLiteral
457 %token <string_> StringLiteral
458 %token <literal_> RegularExpressionLiteral_
459
460 %token <string_> NoSubstitutionTemplate
461 %token <string_> TemplateHead
462 %token <string_> TemplateMiddle
463 %token <string_> TemplateTail
464
465 %type <target_> AccessExpression
466 %type <expression_> AdditiveExpression
467 %type <argument_> ArgumentList_
468 %type <argument_> ArgumentList
469 %type <argument_> ArgumentListOpt
470 %type <argument_> Arguments
471 %type <target_> ArrayComprehension
472 %type <literal_> ArrayLiteral
473 %type <expression_> ArrowFunction
474 %type <functionParameter_> ArrowParameters
475 %type <expression_> AssignmentExpression
476 %type <expression_> AssignmentExpressionOpt
477 %type <identifier_> BindingIdentifier
478 %type <identifier_> BindingIdentifierOpt
479 %type <bindings_> BindingList_
480 %type <bindings_> BindingList
481 %type <expression_> BitwiseANDExpression
482 %type <statement_> Block
483 %type <statement_> BlockStatement
484 %type <boolean_> BooleanLiteral
485 %type <binding_> BindingElement
486 %type <expression_> BitwiseORExpression
487 %type <expression_> BitwiseXORExpression
488 %type <statement_> BreakStatement
489 %type <statement_> BreakableStatement
490 %type <expression_> CallExpression_
491 %type <target_> CallExpression
492 %type <clause_> CaseBlock
493 %type <clause_> CaseClause
494 %type <clause_> CaseClausesOpt
495 %type <catch_> Catch
496 %type <identifier_> CatchParameter
497 %type <statement_> ClassDeclaration
498 %type <target_> ClassExpression
499 %type <classTail_> ClassHeritage
500 %type <classTail_> ClassHeritageOpt
501 %type <classTail_> ClassTail
502 %type <target_> Comprehension
503 %type <comprehension_> ComprehensionFor
504 %type <comprehension_> ComprehensionIf
505 %type <comprehension_> ComprehensionTail
506 %type <propertyName_> ComputedPropertyName
507 %type <expression_> ConditionalExpression
508 %type <statement_> ContinueStatement
509 %type <statement_> ConciseBody
510 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
511 %type <statement_> DebuggerStatement
512 %type <statement_> Declaration_
513 %type <statement_> Declaration
514 %type <clause_> DefaultClause
515 %type <element_> ElementList
516 %type <element_> ElementListOpt
517 %type <statement_> ElseStatementOpt
518 %type <for_> EmptyStatement
519 %type <expression_> EqualityExpression
520 %type <expression_> Expression
521 %type <expression_> ExpressionOpt
522 %type <for_> ExpressionStatement_
523 %type <statement_> ExpressionStatement
524 %type <finally_> Finally
525 %type <binding_> ForBinding
526 %type <forin_> ForDeclaration
527 %type <forin_> ForInStatementInitializer
528 %type <for_> ForStatementInitializer
529 %type <binding_> FormalParameter
530 %type <functionParameter_> FormalParameterList_
531 %type <functionParameter_> FormalParameterList
532 %type <functionParameter_> FormalParameters
533 %type <statement_> FunctionBody
534 %type <statement_> FunctionDeclaration
535 %type <target_> FunctionExpression
536 %type <statement_> FunctionStatementList
537 %type <statement_> GeneratorBody
538 %type <statement_> GeneratorDeclaration
539 %type <target_> GeneratorExpression
540 %type <method_> GeneratorMethod
541 %type <statement_> HoistableDeclaration
542 %type <identifier_> Identifier
543 %type <identifier_> IdentifierNoOf
544 %type <identifier_> IdentifierType
545 %type <identifier_> IdentifierTypeNoOf
546 %type <word_> IdentifierName
547 %type <variable_> IdentifierReference
548 %type <statement_> IfStatement
549 %type <target_> IndirectExpression
550 %type <expression_> Initializer
551 %type <expression_> InitializerOpt
552 %type <statement_> IterationStatement
553 %type <identifier_> LabelIdentifier
554 %type <statement_> LabelledItem
555 %type <statement_> LabelledStatement
556 %type <assignment_> LeftHandSideAssignment
557 %type <target_> LeftHandSideExpression
558 %type <bool_> LetOrConst
559 %type <binding_> LexicalBinding
560 %type <for_> LexicalDeclaration_
561 %type <statement_> LexicalDeclaration
562 %type <literal_> Literal
563 %type <propertyName_> LiteralPropertyName
564 %type <expression_> LogicalANDExpression
565 %type <expression_> LogicalORExpression
566 %type <access_> MemberAccess
567 %type <target_> MemberExpression
568 %type <method_> MethodDefinition
569 %type <module_> ModulePath
570 %type <expression_> MultiplicativeExpression
571 %type <target_> NewExpression
572 %type <null_> NullLiteral
573 %type <literal_> ObjectLiteral
574 %type <expression_> PostfixExpression
575 %type <target_> PrimaryExpression
576 %type <propertyName_> PropertyName
577 %type <property_> PropertyDefinition
578 %type <property_> PropertyDefinitionList_
579 %type <property_> PropertyDefinitionList
580 %type <property_> PropertyDefinitionListOpt
581 %type <functionParameter_> PropertySetParameterList
582 %type <literal_> RegularExpressionLiteral
583 %type <bool_> RegularExpressionSlash
584 %type <expression_> RelationalExpression
585 %type <statement_> ReturnStatement
586 %type <rubyProc_> RubyProcExpression
587 %type <functionParameter_> RubyProcParameterList_
588 %type <functionParameter_> RubyProcParameterList
589 %type <functionParameter_> RubyProcParameters
590 %type <functionParameter_> RubyProcParametersOpt
591 %type <statement_> Script
592 %type <statement_> ScriptBody
593 %type <statement_> ScriptBodyOpt
594 %type <expression_> ShiftExpression
595 %type <binding_> SingleNameBinding
596 %type <statement_> Statement__
597 %type <statement_> Statement_
598 %type <statement_> Statement
599 %type <statement_> StatementList
600 %type <statement_> StatementListOpt
601 %type <statement_> StatementListItem
602 %type <functionParameter_> StrictFormalParameters
603 %type <target_> SuperCall
604 %type <target_> SuperProperty
605 %type <statement_> SwitchStatement
606 %type <target_> TemplateLiteral
607 %type <span_> TemplateSpans
608 %type <statement_> ThrowStatement
609 %type <statement_> TryStatement
610 %type <expression_> UnaryExpression_
611 %type <expression_> UnaryExpression
612 %type <binding_> VariableDeclaration
613 %type <bindings_> VariableDeclarationList_
614 %type <bindings_> VariableDeclarationList
615 %type <for_> VariableStatement_
616 %type <statement_> VariableStatement
617 %type <statement_> WithStatement
618 %type <word_> Word
619 @begin ObjectiveC
620 %type <word_> WordOpt
621 @end
622 %type <expression_> YieldExpression
623
624 @begin C
625 %type <specifier_> IntegerType
626 %type <specifier_> IntegerTypeOpt
627 %type <typedIdentifier_> PrefixedType
628 %type <specifier_> PrimitiveType
629 %type <typedIdentifier_> SuffixedType
630 %type <typedIdentifier_> TypeSignifier
631 %type <modifier_> TypeQualifierLeft
632 %type <typedIdentifier_> TypeQualifierRight
633 %type <typedIdentifier_> TypedIdentifier
634 %type <typedParameter_> TypedParameterList_
635 %type <typedParameter_> TypedParameterList
636 %type <typedParameter_> TypedParameterListOpt
637 @end
638
639 @begin ObjectiveC
640 %type <expression_> AssignmentExpressionClassic
641 %type <expression_> BoxableExpression
642 %type <statement_> CategoryStatement
643 %type <expression_> ClassSuperOpt
644 %type <expression_> ConditionalExpressionClassic
645 %type <implementationField_> ImplementationFieldListOpt
646 %type <implementationField_> ImplementationFields
647 %type <message_> ClassMessageDeclaration
648 %type <message_> ClassMessageDeclarationListOpt
649 %type <protocol_> ClassProtocolListOpt
650 %type <protocol_> ClassProtocols
651 %type <protocol_> ClassProtocolsOpt
652 %type <statement_> ImplementationStatement
653 %type <target_> MessageExpression
654 %type <messageParameter_> MessageParameter
655 %type <messageParameter_> MessageParameters
656 %type <messageParameter_> MessageParameterList
657 %type <messageParameter_> MessageParameterListOpt
658 %type <bool_> MessageScope
659 %type <argument_> SelectorCall_
660 %type <argument_> SelectorCall
661 %type <selector_> SelectorExpression_
662 %type <selector_> SelectorExpression
663 %type <selector_> SelectorExpressionOpt
664 %type <argument_> SelectorList
665 %type <word_> SelectorWordOpt
666 %type <typedIdentifier_> TypeOpt
667 %type <argument_> VariadicCall
668 @end
669
670 @begin E4X
671 %type <propertyIdentifier_> PropertyIdentifier_
672 %type <selector_> PropertySelector_
673 %type <selector_> PropertySelector
674 %type <identifier_> QualifiedIdentifier_
675 %type <identifier_> QualifiedIdentifier
676 %type <identifier_> WildcardIdentifier
677 %type <identifier_> XMLComment
678 %type <identifier_> XMLCDATA
679 %type <identifier_> XMLElement
680 %type <identifier_> XMLElementContent
681 %type <identifier_> XMLMarkup
682 %type <identifier_> XMLPI
683
684 %type <attribute_> AttributeIdentifier
685 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
686 %type <expression_> PropertyIdentifier
687 %type <expression_> XMLListInitilizer
688 %type <expression_> XMLInitilizer
689 @end
690 /* }}} */
691 /* Token Priorities {{{ */
692 %nonassoc "if"
693 %nonassoc "else"
694 /* }}} */
695
696 %start Program
697 %token MarkModule
698 %token MarkScript
699
700 %%
701
702 Program
703 : MarkScript Script
704 | MarkModule Module
705 ;
706
707 /* Lexer State {{{ */
708 LexPushInOn: { driver.in_.push(true); };
709 LexPushInOff: { driver.in_.push(false); };
710 LexPopIn: { driver.in_.pop(); };
711
712 LexPushReturnOn: { driver.return_.push(true); };
713 LexPopReturn: { driver.return_.pop(); };
714
715 LexPushSuperOn: { driver.super_.push(true); };
716 LexPushSuperOff: { driver.super_.push(false); };
717 LexPopSuper: { driver.super_.pop(); };
718
719 LexPushYieldOn: { driver.yield_.push(true); };
720 LexPushYieldOff: { driver.yield_.push(false); };
721 LexPopYield: { driver.yield_.pop(); };
722
723 LexNewLine
724 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
725 ;
726
727 LexNoStar
728 : { CYMAP(YieldStar, Star); }
729 ;
730
731 LexNoBrace
732 : { CYMAP(OpenBrace_, OpenBrace); }
733 ;
734
735 LexNoClass
736 : { CYMAP(_class__, _class_); }
737 ;
738
739 LexNoFunction
740 : { CYMAP(_function__, _function_); }
741 ;
742
743 LexSetStatement
744 : LexNoBrace LexNoClass LexNoFunction
745 ;
746 /* }}} */
747 /* Virtual Tokens {{{ */
748 Var_
749 : "var"
750 ;
751 /* }}} */
752
753 /* 11.6 Names and Keywords {{{ */
754 IdentifierName
755 : Word[pass] { $$ = $pass; }
756 | "for" { $$ = CYNew CYWord("for"); }
757 | "in" { $$ = CYNew CYWord("in"); }
758 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
759 ;
760
761 Word
762 : IdentifierNoOf[pass] { $$ = $pass; }
763 | "auto" { $$ = CYNew CYWord("auto"); }
764 | "break" { $$ = CYNew CYWord("break"); }
765 | "case" { $$ = CYNew CYWord("case"); }
766 | "catch" { $$ = CYNew CYWord("catch"); }
767 | "class" LexOf { $$ = CYNew CYWord("class"); }
768 | ";class" { $$ = CYNew CYWord("class"); }
769 | "const" { $$ = CYNew CYWord("const"); }
770 | "continue" { $$ = CYNew CYWord("continue"); }
771 | "debugger" { $$ = CYNew CYWord("debugger"); }
772 | "default" { $$ = CYNew CYWord("default"); }
773 | "delete" { $$ = CYNew CYWord("delete"); }
774 | "do" { $$ = CYNew CYWord("do"); }
775 | "else" { $$ = CYNew CYWord("else"); }
776 | "enum" { $$ = CYNew CYWord("enum"); }
777 | "export" { $$ = CYNew CYWord("export"); }
778 | "extends" { $$ = CYNew CYWord("extends"); }
779 | "false" { $$ = CYNew CYWord("false"); }
780 | "finally" { $$ = CYNew CYWord("finally"); }
781 | "function" LexOf { $$ = CYNew CYWord("function"); }
782 | "if" { $$ = CYNew CYWord("if"); }
783 | "import" { $$ = CYNew CYWord("import"); }
784 | "!in" { $$ = CYNew CYWord("in"); }
785 | "!of" { $$ = CYNew CYWord("of"); }
786 | "new" { $$ = CYNew CYWord("new"); }
787 | "null" { $$ = CYNew CYWord("null"); }
788 | "return" { $$ = CYNew CYWord("return"); }
789 | "super" { $$ = CYNew CYWord("super"); }
790 | "switch" { $$ = CYNew CYWord("switch"); }
791 | "this" { $$ = CYNew CYWord("this"); }
792 | "throw" { $$ = CYNew CYWord("throw"); }
793 | "true" { $$ = CYNew CYWord("true"); }
794 | "try" { $$ = CYNew CYWord("try"); }
795 | "typeof" { $$ = CYNew CYWord("typeof"); }
796 | "var" { $$ = CYNew CYWord("var"); }
797 | "void" { $$ = CYNew CYWord("void"); }
798 | "while" { $$ = CYNew CYWord("while"); }
799 | "with" { $$ = CYNew CYWord("with"); }
800 | "yield" { $$ = CYNew CYIdentifier("yield"); }
801 ;
802
803 @begin ObjectiveC
804 WordOpt
805 : Word[pass] { $$ = $pass; }
806 | { $$ = NULL; }
807 ;
808 @end
809 /* }}} */
810 /* 11.8.1 Null Literals {{{ */
811 NullLiteral
812 : "null" { $$ = CYNew CYNull(); }
813 ;
814 /* }}} */
815 /* 11.8.2 Boolean Literals {{{ */
816 BooleanLiteral
817 : "true" { $$ = CYNew CYTrue(); }
818 | "false" { $$ = CYNew CYFalse(); }
819 ;
820 /* }}} */
821 /* 11.8.5 Regular Expression Literals {{{ */
822 RegularExpressionSlash
823 : "/" { $$ = false; }
824 | "/=" { $$ = true; }
825 ;
826
827 RegularExpressionLiteral
828 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
829 ;
830 /* }}} */
831
832 /* 11.9 Automatic Semicolon Insertion {{{ */
833 StrictSemi
834 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
835 ;
836
837 TerminatorSoft
838 : ";"
839 | "\n" StrictSemi
840 ;
841
842 Terminator
843 : ";"
844 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
845 ;
846
847 TerminatorOpt
848 : ";"
849 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
850 ;
851 /* }}} */
852
853 /* 12.1 Identifiers {{{ */
854 IdentifierReference
855 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
856 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
857 ;
858
859 BindingIdentifier
860 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
861 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
862 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
863 ;
864
865 BindingIdentifierOpt
866 : BindingIdentifier[pass] { $$ = $pass; }
867 | LexOf { $$ = NULL; }
868 ;
869
870 LabelIdentifier
871 : Identifier[pass] { $$ = $pass; }
872 | "yield" { $$ = CYNew CYIdentifier("yield"); }
873 ;
874
875 IdentifierTypeNoOf
876 : Identifier_[pass] { $$ = $pass; }
877 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
878 | "await" { $$ = CYNew CYIdentifier("await"); }
879 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
880 | "byte" { $$ = CYNew CYIdentifier("byte"); }
881 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
882 | "double" { $$ = CYNew CYIdentifier("double"); }
883 | "each" { $$ = CYNew CYIdentifier("each"); }
884 | "eval" { $$ = CYNew CYIdentifier("eval"); }
885 | "final" { $$ = CYNew CYIdentifier("final"); }
886 | "float" { $$ = CYNew CYIdentifier("float"); }
887 | "from" { $$ = CYNew CYIdentifier("from"); }
888 | "get" { $$ = CYNew CYIdentifier("get"); }
889 | "goto" { $$ = CYNew CYIdentifier("goto"); }
890 | "implements" { $$ = CYNew CYIdentifier("implements"); }
891 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
892 | "interface" { $$ = CYNew CYIdentifier("interface"); }
893 | "let" { $$ = CYNew CYIdentifier("let"); }
894 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
895 | "native" { $$ = CYNew CYIdentifier("native"); }
896 | "package" { $$ = CYNew CYIdentifier("package"); }
897 | "private" { $$ = CYNew CYIdentifier("private"); }
898 | "protected" { $$ = CYNew CYIdentifier("protected"); }
899 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
900 | "public" { $$ = CYNew CYIdentifier("public"); }
901 | "set" { $$ = CYNew CYIdentifier("set"); }
902 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
903 | "target" { $$ = CYNew CYIdentifier("target"); }
904 | "throws" { $$ = CYNew CYIdentifier("throws"); }
905 | "transient" { $$ = CYNew CYIdentifier("transient"); }
906 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
907 @begin ObjectiveC
908 | "bool" { $$ = CYNew CYIdentifier("bool"); }
909 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
910 | "id" { $$ = CYNew CYIdentifier("id"); }
911 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
912 @end
913 ;
914
915 IdentifierType
916 : IdentifierTypeNoOf[pass] { $$ = $pass; }
917 | "of" { $$ = CYNew CYIdentifier("of"); }
918 ;
919
920 IdentifierNoOf
921 : IdentifierTypeNoOf
922 | "char" { $$ = CYNew CYIdentifier("char"); }
923 | "int" { $$ = CYNew CYIdentifier("int"); }
924 | "long" { $$ = CYNew CYIdentifier("long"); }
925 | "short" { $$ = CYNew CYIdentifier("short"); }
926 | "static" { $$ = CYNew CYIdentifier("static"); }
927 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
928 @begin C
929 | "extern" { $$ = CYNew CYIdentifier("extern"); }
930 | "signed" { $$ = CYNew CYIdentifier("signed"); }
931 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
932 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
933 @end
934 @begin ObjectiveC
935 | "nil" { $$ = CYNew CYIdentifier("nil"); }
936 | "NO" { $$ = CYNew CYIdentifier("NO"); }
937 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
938 | "YES" { $$ = CYNew CYIdentifier("YES"); }
939 @end
940 ;
941
942 Identifier
943 : IdentifierNoOf[pass] { $$ = $pass; }
944 | "of" { $$ = CYNew CYIdentifier("of"); }
945 | "!of" { $$ = CYNew CYIdentifier("of"); }
946 ;
947 /* }}} */
948 /* 12.2 Primary Expression {{{ */
949 PrimaryExpression
950 : "this" { $$ = CYNew CYThis(); }
951 | IdentifierReference[pass] { $$ = $pass; }
952 | Literal[pass] { $$ = $pass; }
953 | ArrayLiteral[pass] { $$ = $pass; }
954 | ObjectLiteral[pass] { $$ = $pass; }
955 | FunctionExpression[pass] { $$ = $pass; }
956 | ClassExpression[pass] { $$ = $pass; }
957 | GeneratorExpression[pass] { $$ = $pass; }
958 | RegularExpressionLiteral[pass] { $$ = $pass; }
959 | TemplateLiteral[pass] { $$ = $pass; }
960 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
961 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
962 ;
963
964 CoverParenthesizedExpressionAndArrowParameterList
965 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
966 | "(" LexOf ")" { $$ = NULL; }
967 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
968 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
969 ;
970 /* }}} */
971 /* 12.2.4 Literals {{{ */
972 Literal
973 : NullLiteral[pass] { $$ = $pass; }
974 | BooleanLiteral[pass] { $$ = $pass; }
975 | NumericLiteral[pass] { $$ = $pass; }
976 | StringLiteral[pass] { $$ = $pass; }
977 ;
978 /* }}} */
979 /* 12.2.5 Array Initializer {{{ */
980 ArrayLiteral
981 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
982 ;
983
984 ElementList
985 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
986 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
987 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
988 ;
989
990 ElementListOpt
991 : ElementList[pass] { $$ = $pass; }
992 | LexOf { $$ = NULL; }
993 ;
994 /* }}} */
995 /* 12.2.6 Object Initializer {{{ */
996 ObjectLiteral
997 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
998 ;
999
1000 PropertyDefinitionList_
1001 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1002 | { $$ = NULL; }
1003 ;
1004
1005 PropertyDefinitionList
1006 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1007 ;
1008
1009 PropertyDefinitionListOpt
1010 : PropertyDefinitionList[properties] { $$ = $properties; }
1011 | { $$ = NULL; }
1012 ;
1013
1014 PropertyDefinition
1015 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1016 | CoverInitializedName[name] { CYNOT(@$); }
1017 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1018 | MethodDefinition[pass] { $$ = $pass; }
1019 ;
1020
1021 PropertyName
1022 : LiteralPropertyName[pass] { $$ = $pass; }
1023 | ComputedPropertyName[pass] { $$ = $pass; }
1024 ;
1025
1026 LiteralPropertyName
1027 : IdentifierName[pass] { $$ = $pass; }
1028 | StringLiteral[pass] { $$ = $pass; }
1029 | NumericLiteral[pass] { $$ = $pass; }
1030 ;
1031
1032 ComputedPropertyName
1033 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1034 ;
1035
1036 CoverInitializedName
1037 : IdentifierReference Initializer
1038 ;
1039
1040 Initializer
1041 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1042 ;
1043
1044 InitializerOpt
1045 : Initializer[pass] { $$ = $pass; }
1046 | { $$ = NULL; }
1047 ;
1048 /* }}} */
1049 /* 12.2.9 Template Literals {{{ */
1050 TemplateLiteral
1051 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1052 | TemplateHead[string] TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1053 ;
1054
1055 TemplateSpans
1056 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1057 | Expression[value] TemplateTail[string] { $$ = CYNew CYSpan($value, $string, NULL); }
1058 ;
1059 /* }}} */
1060
1061 /* 12.3 Left-Hand-Side Expressions {{{ */
1062 MemberAccess
1063 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1064 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1065 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1066 | TemplateLiteral { CYNOT(@$); }
1067 ;
1068
1069 MemberExpression
1070 : PrimaryExpression[pass] { $$ = $pass; }
1071 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1072 | SuperProperty[pass] { $$ = $pass; }
1073 | MetaProperty { CYNOT(@$); }
1074 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1075 ;
1076
1077 SuperProperty
1078 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1079 | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1080 ;
1081
1082 MetaProperty
1083 : NewTarget
1084 ;
1085
1086 NewTarget
1087 : "new" "." "target"
1088 ;
1089
1090 NewExpression
1091 : MemberExpression[pass] { $$ = $pass; }
1092 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1093 ;
1094
1095 CallExpression_
1096 : MemberExpression[pass] { $$ = $pass; }
1097 | CallExpression[pass] { $$ = $pass; }
1098 ;
1099
1100 CallExpression
1101 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1102 | SuperCall[pass] { $$ = $pass; }
1103 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1104 ;
1105
1106 SuperCall
1107 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1108 ;
1109
1110 Arguments
1111 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1112 ;
1113
1114 ArgumentList_
1115 : "," ArgumentList[arguments] { $$ = $arguments; }
1116 | { $$ = NULL; }
1117 ;
1118
1119 ArgumentList
1120 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1121 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1122 ;
1123
1124 ArgumentListOpt
1125 : ArgumentList[pass] { $$ = $pass; }
1126 | LexOf { $$ = NULL; }
1127 ;
1128
1129 AccessExpression
1130 : NewExpression[pass] { $$ = $pass; }
1131 | CallExpression[pass] { $$ = $pass; }
1132 ;
1133
1134 LeftHandSideExpression
1135 : AccessExpression[pass] LexNewLine { $$ = $pass; }
1136 | IndirectExpression[pass] { $$ = $pass; }
1137 ;
1138 /* }}} */
1139 /* 12.4 Postfix Expressions {{{ */
1140 PostfixExpression
1141 : AccessExpression[lhs] LexNewLine { $$ = $lhs; }
1142 | AccessExpression[lhs] LexNewLine "++" { $$ = CYNew CYPostIncrement($lhs); }
1143 | AccessExpression[lhs] LexNewLine "--" { $$ = CYNew CYPostDecrement($lhs); }
1144 ;
1145 /* }}} */
1146 /* 12.5 Unary Operators {{{ */
1147 UnaryExpression_
1148 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1149 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1150 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1151 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1152 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1153 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1154 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1155 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1156 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1157 ;
1158
1159 UnaryExpression
1160 : PostfixExpression[expression] { $$ = $expression; }
1161 | PostfixExpression[expression] "\n" { $$ = $expression; }
1162 | UnaryExpression_[pass] { $$ = $pass; }
1163 ;
1164 /* }}} */
1165 /* 12.6 Multiplicative Operators {{{ */
1166 MultiplicativeExpression
1167 : UnaryExpression[pass] { $$ = $pass; }
1168 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1169 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1170 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1171 ;
1172 /* }}} */
1173 /* 12.7 Additive Operators {{{ */
1174 AdditiveExpression
1175 : MultiplicativeExpression[pass] { $$ = $pass; }
1176 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1177 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1178 ;
1179 /* }}} */
1180 /* 12.8 Bitwise Shift Operators {{{ */
1181 ShiftExpression
1182 : AdditiveExpression[pass] { $$ = $pass; }
1183 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1184 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1185 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1186 ;
1187 /* }}} */
1188 /* 12.9 Relational Operators {{{ */
1189 RelationalExpression
1190 : ShiftExpression[pass] { $$ = $pass; }
1191 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1192 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1193 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1194 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1195 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1196 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1197 ;
1198 /* }}} */
1199 /* 12.10 Equality Operators {{{ */
1200 EqualityExpression
1201 : RelationalExpression[pass] { $$ = $pass; }
1202 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1203 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1204 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1205 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1206 ;
1207 /* }}} */
1208 /* 12.11 Binary Bitwise Operators {{{ */
1209 BitwiseANDExpression
1210 : EqualityExpression[pass] { $$ = $pass; }
1211 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1212 ;
1213
1214 BitwiseXORExpression
1215 : BitwiseANDExpression[pass] { $$ = $pass; }
1216 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1217 ;
1218
1219 BitwiseORExpression
1220 : BitwiseXORExpression[pass] { $$ = $pass; }
1221 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1222 ;
1223 /* }}} */
1224 /* 12.12 Binary Logical Operators {{{ */
1225 LogicalANDExpression
1226 : BitwiseORExpression[pass] { $$ = $pass; }
1227 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1228 ;
1229
1230 LogicalORExpression
1231 : LogicalANDExpression[pass] { $$ = $pass; }
1232 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1233 ;
1234 /* }}} */
1235 /* 12.13 Conditional Operator ( ? : ) {{{ */
1236 @begin ObjectiveC
1237 ConditionalExpressionClassic
1238 : LogicalORExpression[pass] { $$ = $pass; }
1239 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1240 ;
1241 @end
1242
1243 ConditionalExpression
1244 : LogicalORExpression[pass] { $$ = $pass; }
1245 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1246 ;
1247 /* }}} */
1248 /* 12.14 Assignment Operators {{{ */
1249 LeftHandSideAssignment
1250 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1251 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1252 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1253 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1254 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1255 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1256 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1257 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1258 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1259 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1260 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1261 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1262 ;
1263
1264 @begin ObjectiveC
1265 AssignmentExpressionClassic
1266 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1267 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1268 ;
1269 @end
1270
1271 AssignmentExpression
1272 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1273 | LexOf YieldExpression[pass] { $$ = $pass; }
1274 | ArrowFunction[pass] { $$ = $pass; }
1275 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1276 ;
1277
1278 AssignmentExpressionOpt
1279 : AssignmentExpression[pass] { $$ = $pass; }
1280 | LexOf { $$ = NULL; }
1281 ;
1282 /* }}} */
1283 /* 12.15 Comma Operator ( , ) {{{ */
1284 Expression
1285 : AssignmentExpression[pass] { $$ = $pass; }
1286 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1287 ;
1288
1289 ExpressionOpt
1290 : Expression[pass] { $$ = $pass; }
1291 | LexOf { $$ = NULL; }
1292 ;
1293 /* }}} */
1294
1295 /* 13 Statements and Declarations {{{ */
1296 Statement__
1297 : BlockStatement[pass] { $$ = $pass; }
1298 | VariableStatement[pass] { $$ = $pass; }
1299 | EmptyStatement[pass] { $$ = $pass; }
1300 | IfStatement[pass] { $$ = $pass; }
1301 | BreakableStatement[pass] { $$ = $pass; }
1302 | ContinueStatement[pass] { $$ = $pass; }
1303 | BreakStatement[pass] { $$ = $pass; }
1304 | ReturnStatement[pass] { $$ = $pass; }
1305 | WithStatement[pass] { $$ = $pass; }
1306 | LabelledStatement[pass] { $$ = $pass; }
1307 | ThrowStatement[pass] { $$ = $pass; }
1308 | TryStatement[pass] { $$ = $pass; }
1309 | DebuggerStatement[pass] { $$ = $pass; }
1310 ;
1311
1312 Statement_
1313 : LexOf Statement__[pass] { $$ = $pass; }
1314 | ExpressionStatement[pass] { $$ = $pass; }
1315 ;
1316
1317 Statement
1318 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1319 ;
1320
1321 Declaration_
1322 : HoistableDeclaration[pass] { $$ = $pass; }
1323 | ClassDeclaration[pass] { $$ = $pass; }
1324 ;
1325
1326 Declaration
1327 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1328 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1329 ;
1330
1331 HoistableDeclaration
1332 : FunctionDeclaration[pass] { $$ = $pass; }
1333 | GeneratorDeclaration[pass] { $$ = $pass; }
1334 ;
1335
1336 BreakableStatement
1337 : IterationStatement[pass] { $$ = $pass; }
1338 | SwitchStatement[pass] { $$ = $pass; }
1339 ;
1340 /* }}} */
1341 /* 13.2 Block {{{ */
1342 BlockStatement
1343 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1344 ;
1345
1346 Block
1347 : "{" StatementListOpt[code] "}" { $$ = $code; }
1348 ;
1349
1350 StatementList
1351 : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
1352 ;
1353
1354 StatementListOpt
1355 : StatementList[pass] { $$ = $pass; }
1356 | LexSetStatement LexLet LexOf { $$ = NULL; }
1357 ;
1358
1359 StatementListItem
1360 : Statement[pass] { $$ = $pass; }
1361 | Declaration[pass] { $$ = $pass; }
1362 ;
1363 /* }}} */
1364 /* 13.3 Let and Const Declarations {{{ */
1365 LexicalDeclaration_
1366 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1367 ;
1368
1369 LexicalDeclaration
1370 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1371 ;
1372
1373 LexLet
1374 : { CYMAP(_let__, _let_); }
1375 ;
1376
1377 LexOf
1378 : { CYMAP(_of__, _of_); }
1379 ;
1380
1381 LexBind
1382 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1383 ;
1384
1385 LetOrConst
1386 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1387 | LexLet LexOf "const" { $$ = true; }
1388 ;
1389
1390 BindingList_
1391 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1392 | { $$ = NULL; }
1393 ;
1394
1395 BindingList
1396 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1397 ;
1398
1399 LexicalBinding
1400 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1401 | LexOf BindingPattern Initializer { CYNOT(@$); }
1402 ;
1403 /* }}} */
1404 /* 13.3.2 Variable Statement {{{ */
1405 VariableStatement_
1406 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1407 ;
1408
1409 VariableStatement
1410 : VariableStatement_[statement] Terminator { $$ = $statement; }
1411 ;
1412
1413 VariableDeclarationList_
1414 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1415 | { $$ = NULL; }
1416 ;
1417
1418 VariableDeclarationList
1419 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1420 ;
1421
1422 VariableDeclaration
1423 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1424 | LexOf BindingPattern Initializer { CYNOT(@$); }
1425 ;
1426 /* }}} */
1427 /* 13.3.3 Destructuring Binding Patterns {{{ */
1428 BindingPattern
1429 : ObjectBindingPattern
1430 | ArrayBindingPattern
1431 ;
1432
1433 ObjectBindingPattern
1434 : "let {" BindingPropertyListOpt "}"
1435 ;
1436
1437 ArrayBindingPattern
1438 : "let [" BindingElementListOpt "]"
1439 ;
1440
1441 BindingPropertyList_
1442 : "," BindingPropertyListOpt
1443 |
1444 ;
1445
1446 BindingPropertyList
1447 : BindingProperty BindingPropertyList_
1448 ;
1449
1450 BindingPropertyListOpt
1451 : BindingPropertyList
1452 | LexOf
1453 ;
1454
1455 BindingElementList
1456 : BindingElementOpt[element] "," BindingElementListOpt[next]
1457 | BindingRestElement[element]
1458 | BindingElement[element]
1459 ;
1460
1461 BindingElementListOpt
1462 : BindingElementList[pass]
1463 | LexBind LexOf
1464 ;
1465
1466 BindingProperty
1467 : SingleNameBinding
1468 | LexOf PropertyName ":" BindingElement
1469 ;
1470
1471 BindingElement
1472 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1473 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1474 ;
1475
1476 BindingElementOpt
1477 : BindingElement[pass]
1478 | LexBind LexOf
1479 ;
1480
1481 SingleNameBinding
1482 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1483 ;
1484
1485 BindingRestElement
1486 : LexBind LexOf "..." BindingIdentifier
1487 ;
1488 /* }}} */
1489 /* 13.4 Empty Statement {{{ */
1490 EmptyStatement
1491 : ";" { $$ = CYNew CYEmpty(); }
1492 ;
1493 /* }}} */
1494 /* 13.5 Expression Statement {{{ */
1495 ExpressionStatement_
1496 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1497
1498 ExpressionStatement
1499 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1500 ;
1501 /* }}} */
1502 /* 13.6 The if Statement {{{ */
1503 ElseStatementOpt
1504 : "else" Statement[false] { $$ = $false; }
1505 | %prec "if" { $$ = NULL; }
1506 ;
1507
1508 IfStatement
1509 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1510 ;
1511 /* }}} */
1512 /* 13.7 Iteration Statements {{{ */
1513 IterationStatement
1514 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1515 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1516 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1517 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1518 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1519 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1520 ;
1521
1522 ForStatementInitializer
1523 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1524 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1525 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1526 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1527 ;
1528
1529 ForInStatementInitializer
1530 : LexLet LexOf AccessExpression[pass] LexNewLine { $$ = $pass; }
1531 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1532 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1533 | ForDeclaration[pass] { $$ = $pass; }
1534 ;
1535
1536 ForDeclaration
1537 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1538 ;
1539
1540 ForBinding
1541 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1542 | LexOf BindingPattern { CYNOT(@$); }
1543 ;
1544 /* }}} */
1545 /* 13.8 The continue Statement {{{ */
1546 ContinueStatement
1547 : "continue" LexNewLine TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1548 | "continue" LexNewLine Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1549 ;
1550 /* }}} */
1551 /* 13.9 The break Statement {{{ */
1552 BreakStatement
1553 : "break" LexNewLine TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1554 | "break" LexNewLine Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1555 ;
1556 /* }}} */
1557 /* 13.10 The return Statement {{{ */
1558 Return
1559 : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
1560 ;
1561
1562 ReturnStatement
1563 : Return LexNewLine LexOf TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1564 | Return LexNewLine Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1565 ;
1566 /* }}} */
1567 /* 13.11 The with Statement {{{ */
1568 WithStatement
1569 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1570 ;
1571 /* }}} */
1572 /* 13.12 The switch Statement {{{ */
1573 SwitchStatement
1574 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1575 ;
1576
1577 CaseBlock
1578 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1579 ;
1580
1581 CaseClause
1582 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1583 ;
1584
1585 CaseClausesOpt
1586 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1587 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1588 | { $$ = NULL; }
1589 ;
1590
1591 // XXX: the standard makes certain you can only have one of these
1592 DefaultClause
1593 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1594 ;
1595 /* }}} */
1596 /* 13.13 Labelled Statements {{{ */
1597 LabelledStatement
1598 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1599 ;
1600
1601 LabelledItem
1602 : Statement[pass] { $$ = $pass; }
1603 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1604 ;
1605 /* }}} */
1606 /* 13.14 The throw Statement {{{ */
1607 ThrowStatement
1608 : "throw"[throw] LexNewLine LexOf TerminatorSoft { CYERR(@throw, "throw without exception"); }
1609 | "throw" LexNewLine Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1610 ;
1611 /* }}} */
1612 /* 13.15 The try Statement {{{ */
1613 TryStatement
1614 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1615 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1616 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1617 ;
1618
1619 Catch
1620 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1621 ;
1622
1623 Finally
1624 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1625 ;
1626
1627 CatchParameter
1628 : BindingIdentifier[pass] { $$ = $pass; }
1629 | LexOf BindingPattern { CYNOT(@$); }
1630 ;
1631 /* }}} */
1632 /* 13.16 The debugger Statement {{{ */
1633 DebuggerStatement
1634 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1635 ;
1636 /* }}} */
1637
1638 /* 14.1 Function Definitions {{{ */
1639 FunctionDeclaration
1640 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1641 ;
1642
1643 FunctionExpression
1644 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1645 ;
1646
1647 StrictFormalParameters
1648 : FormalParameters[pass] { $$ = $pass; }
1649 ;
1650
1651 FormalParameters
1652 : LexBind LexOf { $$ = NULL; }
1653 | FormalParameterList
1654 ;
1655
1656 FormalParameterList_
1657 : "," FormalParameterList[parameters] { $$ = $parameters; }
1658 | { $$ = NULL; }
1659 ;
1660
1661 FormalParameterList
1662 : FunctionRestParameter { CYNOT(@$); }
1663 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1664 ;
1665
1666 FunctionRestParameter
1667 : BindingRestElement
1668 ;
1669
1670 FormalParameter
1671 : BindingElement[pass] { $$ = $pass; }
1672 ;
1673
1674 FunctionBody
1675 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1676 ;
1677
1678 FunctionStatementList
1679 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1680 ;
1681 /* }}} */
1682 /* 14.2 Arrow Function Definitions {{{ */
1683 ArrowFunction
1684 : ArrowParameters[parameters] LexNewLine "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1685 ;
1686
1687 ArrowParameters
1688 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1689 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1690 ;
1691
1692 ConciseBody
1693 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1694 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1695 ;
1696 /* }}} */
1697 /* 14.3 Method Definitions {{{ */
1698 MethodDefinition
1699 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1700 | GeneratorMethod[pass] { $$ = $pass; }
1701 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1702 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1703 ;
1704
1705 PropertySetParameterList
1706 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1707 ;
1708 /* }}} */
1709 /* 14.4 Generator Function Definitions {{{ */
1710 GeneratorMethod
1711 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1712 ;
1713
1714 GeneratorDeclaration
1715 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1716 ;
1717
1718 GeneratorExpression
1719 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1720 ;
1721
1722 GeneratorBody
1723 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1724 ;
1725
1726 Yield
1727 : "!yield" LexNewLine LexNoStar
1728 ;
1729
1730 YieldExpression
1731 : Yield LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1732 | Yield LexOf "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1733 | Yield AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1734 | Yield LexOf YieldStar AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1735 ;
1736 /* }}} */
1737 /* 14.5 Class Definitions {{{ */
1738 ClassDeclaration
1739 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1740 ;
1741
1742 ClassExpression
1743 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1744 ;
1745
1746 ClassTail
1747 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1748 ;
1749
1750 ClassHeritage
1751 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1752 ;
1753
1754 ClassHeritageOpt
1755 : ClassHeritage[pass] { $$ = $pass; }
1756 | { $$ = CYNew CYClassTail(NULL); }
1757 ;
1758
1759 ClassBody
1760 : ClassElementList
1761 ;
1762
1763 ClassBodyOpt
1764 : ClassBody
1765 |
1766 ;
1767
1768 ClassElementList
1769 : ClassElementListOpt ClassElement
1770 ;
1771
1772 ClassElementListOpt
1773 : ClassElementList
1774 |
1775 ;
1776
1777 ClassElement
1778 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1779 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1780 | ";"
1781 ;
1782 /* }}} */
1783
1784 /* 15.1 Scripts {{{ */
1785 Script
1786 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1787 ;
1788
1789 ScriptBody
1790 : StatementList[pass] { $$ = $pass; }
1791 ;
1792
1793 ScriptBodyOpt
1794 : ScriptBody[pass] { $$ = $pass; }
1795 | LexSetStatement LexLet LexOf { $$ = NULL; }
1796 ;
1797 /* }}} */
1798 /* 15.2 Modules {{{ */
1799 Module
1800 : ModuleBodyOpt
1801 ;
1802
1803 ModuleBody
1804 : ModuleItemList
1805 ;
1806
1807 ModuleBodyOpt
1808 : ModuleBody
1809 |
1810 ;
1811
1812 ModuleItemList
1813 : ModuleItemListOpt ModuleItem
1814 ;
1815
1816 ModuleItemListOpt
1817 : ModuleItemList
1818 |
1819 ;
1820
1821 ModuleItem
1822 : LexSetStatement LexLet LexOf ImportDeclaration
1823 | LexSetStatement LexLet LexOf ExportDeclaration
1824 | StatementListItem
1825 ;
1826 /* }}} */
1827 /* 15.2.2 Imports {{{ */
1828 ImportDeclaration
1829 : "import" ImportClause FromClause Terminator
1830 | "import" LexOf ModuleSpecifier Terminator
1831 ;
1832
1833 ImportClause
1834 : ImportedDefaultBinding
1835 | LexOf NameSpaceImport
1836 | LexOf NamedImports
1837 | ImportedDefaultBinding "," NameSpaceImport
1838 | ImportedDefaultBinding "," NamedImports
1839 ;
1840
1841 ImportedDefaultBinding
1842 : ImportedBinding
1843 ;
1844
1845 NameSpaceImport
1846 : "*" "as" ImportedBinding
1847 ;
1848
1849 NamedImports
1850 : "{" ImportsListOpt "}"
1851 ;
1852
1853 FromClause
1854 : "from" ModuleSpecifier
1855 ;
1856
1857 ImportsList_
1858 : "," ImportsListOpt
1859 |
1860 ;
1861
1862 ImportsList
1863 : ImportSpecifier ImportsList_
1864 ;
1865
1866 ImportsListOpt
1867 : ImportsList
1868 | LexOf
1869 ;
1870
1871 ImportSpecifier
1872 : ImportedBinding
1873 | LexOf IdentifierName "as" ImportedBinding
1874 ;
1875
1876 ModuleSpecifier
1877 : StringLiteral
1878 ;
1879
1880 ImportedBinding
1881 : BindingIdentifier
1882 ;
1883 /* }}} */
1884 /* 15.2.3 Exports {{{ */
1885 ExportDeclaration_
1886 : "*" FromClause Terminator
1887 | ExportClause FromClause Terminator
1888 | ExportClause Terminator
1889 | VariableStatement
1890 | "default" LexSetStatement LexOf HoistableDeclaration
1891 | "default" LexSetStatement LexOf ClassDeclaration
1892 | "default" LexSetStatement AssignmentExpression Terminator
1893 ;
1894
1895 ExportDeclaration
1896 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1897 | "export" Declaration
1898 ;
1899
1900 ExportClause
1901 : ";{" ExportsListOpt "}"
1902 ;
1903
1904 ExportsList_
1905 : "," ExportsListOpt
1906 |
1907 ;
1908
1909 ExportsList
1910 : ExportSpecifier ExportsList_
1911 ;
1912
1913 ExportsListOpt
1914 : ExportsList
1915 |
1916 ;
1917
1918 ExportSpecifier
1919 : IdentifierName
1920 | IdentifierName "as" IdentifierName
1921 ;
1922 /* }}} */
1923
1924 @begin C
1925 /* Cycript (C): Type Encoding {{{ */
1926 TypeSignifier
1927 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1928 | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; }
1929 ;
1930
1931 SuffixedType
1932 : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1933 | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1934 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1935 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1936 | TypeSignifier[pass] { $$ = $pass; }
1937 | { $$ = CYNew CYTypedIdentifier(@$); }
1938 ;
1939
1940 PrefixedType
1941 : "*" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1942 ;
1943
1944 TypeQualifierLeft
1945 : { $$ = NULL; }
1946 | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1947 | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1948 ;
1949
1950 TypeQualifierRight
1951 : PrefixedType[pass] { $$ = $pass; }
1952 | SuffixedType[pass] { $$ = $pass; }
1953 | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1954 | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1955 ;
1956
1957 IntegerType
1958 : "int" { $$ = CYNew CYTypeVariable("int"); }
1959 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
1960 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
1961 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
1962 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
1963 ;
1964
1965 IntegerTypeOpt
1966 : IntegerType[pass] { $$ = $pass; }
1967 | { $$ = CYNew CYTypeVariable("int"); }
1968 ;
1969
1970 PrimitiveType
1971 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
1972 | IntegerType[pass] { $$ = $pass; }
1973 | "void" { $$ = CYNew CYTypeVoid(); }
1974 | "char" { $$ = CYNew CYTypeVariable("char"); }
1975 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1976 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1977 ;
1978
1979 TypedIdentifier
1980 : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
1981 ;
1982
1983 PrimaryExpression
1984 : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
1985 ;
1986 /* }}} */
1987 @end
1988
1989 @begin ObjectiveC
1990 /* Cycript (Objective-C): @class Declaration {{{ */
1991 ClassSuperOpt
1992 /* XXX: why the hell did I choose MemberExpression? */
1993 : ":" MemberExpression[extends] { $$ = $extends; }
1994 | { $$ = NULL; }
1995 ;
1996
1997 ImplementationFieldListOpt
1998 : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
1999 | { $$ = NULL; }
2000 ;
2001
2002 ImplementationFields
2003 : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
2004 ;
2005
2006 MessageScope
2007 : "+" { $$ = false; }
2008 | "-" { $$ = true; }
2009 ;
2010
2011 TypeOpt
2012 : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
2013 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2014 ;
2015
2016 MessageParameter
2017 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2018 ;
2019
2020 MessageParameterList
2021 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2022 ;
2023
2024 MessageParameterListOpt
2025 : MessageParameterList[pass] { $$ = $pass; }
2026 | { $$ = NULL; }
2027 ;
2028
2029 MessageParameters
2030 : MessageParameterList[pass] { $$ = $pass; }
2031 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2032 ;
2033
2034 ClassMessageDeclaration
2035 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2036 ;
2037
2038 ClassMessageDeclarationListOpt
2039 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2040 | { $$ = NULL; }
2041 ;
2042
2043 // XXX: this should be AssignmentExpressionNoRight
2044 ClassProtocols
2045 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2046 ;
2047
2048 ClassProtocolsOpt
2049 : "," ClassProtocols[protocols] { $$ = $protocols; }
2050 | { $$ = NULL; }
2051 ;
2052
2053 ClassProtocolListOpt
2054 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2055 | { $$ = NULL; }
2056 ;
2057
2058 ImplementationStatement
2059 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2060 ;
2061
2062 CategoryName
2063 : "(" WordOpt ")"
2064 ;
2065
2066 CategoryStatement
2067 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2068 ;
2069
2070 Statement__
2071 : ImplementationStatement[pass] { $$ = $pass; }
2072 | CategoryStatement[pass] { $$ = $pass; }
2073 ;
2074 /* }}} */
2075 /* Cycript (Objective-C): Send Message {{{ */
2076 VariadicCall
2077 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2078 | { $$ = NULL; }
2079 ;
2080
2081 SelectorWordOpt
2082 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2083 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2084 ;
2085
2086 SelectorCall_
2087 : SelectorCall[pass] { $$ = $pass; }
2088 | VariadicCall[pass] { $$ = $pass; }
2089 ;
2090
2091 SelectorCall
2092 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2093 ;
2094
2095 SelectorList
2096 : SelectorCall[pass] { $$ = $pass; }
2097 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2098 ;
2099
2100 MessageExpression
2101 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2102 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2103 ;
2104
2105 SelectorExpression_
2106 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2107 ;
2108
2109 SelectorExpression
2110 : SelectorExpression_[pass] { $$ = $pass; }
2111 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2112 ;
2113
2114 SelectorExpressionOpt
2115 : SelectorExpression_[pass] { $$ = $pass; }
2116 | { $$ = NULL; }
2117 ;
2118
2119 PrimaryExpression
2120 : MessageExpression[pass] { $$ = $pass; }
2121 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2122 ;
2123 /* }}} */
2124 @end
2125
2126 /* Cycript: @import Directive {{{ */
2127 ModulePath
2128 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2129 | Word[part] { $$ = CYNew CYModule($part); }
2130 ;
2131
2132 Declaration_
2133 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2134 ;
2135 /* }}} */
2136
2137 @begin ObjectiveC
2138 /* Cycript (Objective-C): Boxed Expressions {{{ */
2139 BoxableExpression
2140 : NullLiteral[pass] { $$ = $pass; }
2141 | BooleanLiteral[pass] { $$ = $pass; }
2142 | NumericLiteral[pass] { $$ = $pass; }
2143 | StringLiteral[pass] { $$ = $pass; }
2144 | ArrayLiteral[pass] { $$ = $pass; }
2145 | ObjectLiteral[pass] { $$ = $pass; }
2146 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2147 | "YES" { $$ = CYNew CYTrue(); }
2148 | "NO" { $$ = CYNew CYFalse(); }
2149 ;
2150
2151 PrimaryExpression
2152 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2153 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2154 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2155 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2156 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2157 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2158 ;
2159 /* }}} */
2160 /* Cycript (Objective-C): Block Expressions {{{ */
2161 PrimaryExpression
2162 : "^" TypedIdentifier[type] { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); } "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2163 ;
2164 /* }}} */
2165 /* Cycript (Objective-C): Instance Literals {{{ */
2166 PrimaryExpression
2167 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2168 ;
2169 /* }}} */
2170 @end
2171
2172 @begin C
2173 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2174 UnaryExpression_
2175 : IndirectExpression[pass] { $$ = $pass; }
2176 ;
2177
2178 IndirectExpression
2179 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2180 ;
2181
2182 UnaryExpression_
2183 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2184 ;
2185
2186 MemberAccess
2187 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2188 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2189 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2190 ;
2191 /* }}} */
2192 /* Cycript (C): auto Compatibility {{{ */
2193 Var_
2194 : "auto"
2195 ;
2196 /* }}} */
2197 /* Cycript (C): Lambda Expressions {{{ */
2198 TypedParameterList_
2199 : "," TypedParameterList[parameters] { $$ = $parameters; }
2200 | { $$ = NULL; }
2201 ;
2202
2203 TypedParameterList
2204 : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2205 ;
2206
2207 TypedParameterListOpt
2208 : TypedParameterList[pass] { $$ = $pass; }
2209 | { $$ = NULL; }
2210 ;
2211
2212 PrimaryExpression
2213 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2214 ;
2215 /* }}} */
2216 /* Cycript (C): Type Definitions {{{ */
2217 Statement__
2218 : "typedef" TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
2219 ;
2220 /* }}} */
2221 /* Cycript (C): extern "C" {{{ */
2222 Statement__
2223 : "extern" StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($abi, $typed); }
2224 ;
2225 /* }}} */
2226
2227 @end
2228
2229 @begin E4X
2230 /* Lexer State {{{ */
2231 LexPushRegExp
2232 : { driver.PushCondition(CYDriver::RegExpCondition); }
2233 ;
2234
2235 LexPushXMLContent
2236 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2237 ;
2238
2239 LexPushXMLTag
2240 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2241 ;
2242
2243 LexPop
2244 : { driver.PopCondition(); }
2245 ;
2246
2247 LexSetXMLContent
2248 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2249 ;
2250
2251 LexSetXMLTag
2252 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2253 ;
2254 /* }}} */
2255 /* Virtual Tokens {{{ */
2256 XMLWhitespaceOpt
2257 : XMLWhitespace
2258 |
2259 ;
2260 /* }}} */
2261
2262 /* 8.1 Context Keywords {{{ */
2263 Identifier
2264 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2265 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2266 ;
2267 /* }}} */
2268 /* 8.3 XML Initializer Input Elements {{{ */
2269 XMLMarkup
2270 : XMLComment { $$ = $1; }
2271 | XMLCDATA { $$ = $1; }
2272 | XMLPI { $$ = $1; }
2273 ;
2274 /* }}} */
2275
2276 /* 11.1 Primary Expressions {{{ */
2277 PrimaryExpression
2278 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2279 | XMLInitilizer { $$ = $1; }
2280 | XMLListInitilizer { $$ = $1; }
2281 ;
2282
2283 PropertyIdentifier
2284 : AttributeIdentifier { $$ = $1; }
2285 | QualifiedIdentifier { $$ = $1; }
2286 | WildcardIdentifier { $$ = $1; }
2287 ;
2288 /* }}} */
2289 /* 11.1.1 Attribute Identifiers {{{ */
2290 AttributeIdentifier
2291 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2292 ;
2293
2294 PropertySelector_
2295 : PropertySelector { $$ = $1; }
2296 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2297 ;
2298
2299 PropertySelector
2300 : Identifier { $$ = CYNew CYSelector($1); }
2301 | WildcardIdentifier { $$ = $1; }
2302 ;
2303 /* }}} */
2304 /* 11.1.2 Qualified Identifiers {{{ */
2305 QualifiedIdentifier_
2306 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2307 | QualifiedIdentifier { $$ = $1; }
2308 ;
2309
2310 QualifiedIdentifier
2311 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2312 ;
2313 /* }}} */
2314 /* 11.1.3 Wildcard Identifiers {{{ */
2315 WildcardIdentifier
2316 : "*" { $$ = CYNew CYWildcard(); }
2317 ;
2318 /* }}} */
2319 /* 11.1.4 XML Initializer {{{ */
2320 XMLInitilizer
2321 : XMLMarkup { $$ = $1; }
2322 | XMLElement { $$ = $1; }
2323 ;
2324
2325 XMLElement
2326 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2327 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2328 ;
2329
2330 XMLTagContent
2331 : LexPushXMLTag XMLTagName XMLAttributes
2332 ;
2333
2334 XMLExpression
2335 : "{" LexPushRegExp Expression LexPop "}"
2336 ;
2337
2338 XMLTagName
2339 : XMLExpression
2340 | XMLName
2341 ;
2342
2343 XMLAttributes_
2344 : XMLAttributes_ XMLAttribute
2345 |
2346 ;
2347
2348 XMLAttributes
2349 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2350 | XMLAttributes_ XMLWhitespaceOpt
2351 ;
2352
2353 XMLAttributeValue_
2354 : XMLExpression
2355 | XMLAttributeValue
2356 ;
2357
2358 XMLAttribute
2359 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2360 ;
2361
2362 XMLElementContent
2363 : XMLExpression XMLElementContentOpt
2364 | XMLMarkup XMLElementContentOpt
2365 | XMLText XMLElementContentOpt
2366 | XMLElement XMLElementContentOpt
2367 ;
2368
2369 XMLElementContentOpt
2370 : XMLElementContent
2371 |
2372 ;
2373 /* }}} */
2374 /* 11.1.5 XMLList Initializer {{{ */
2375 XMLListInitilizer
2376 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2377 ;
2378 /* }}} */
2379
2380 /* 11.2 Left-Hand-Side Expressions {{{ */
2381 PropertyIdentifier_
2382 : Identifier { $$ = $1; }
2383 | PropertyIdentifier { $$ = $1; }
2384 ;
2385
2386 MemberAccess
2387 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2388 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2389 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2390 ;
2391 /* }}} */
2392 /* 12.1 The default xml namespace Statement {{{ */
2393 /* XXX: DefaultXMLNamespaceStatement
2394 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2395 ;
2396
2397 Statement__
2398 : DefaultXMLNamespaceStatement { $$ = $1; }
2399 ; */
2400 /* }}} */
2401 @end
2402
2403 /* JavaScript FTL: Array Comprehensions {{{ */
2404 Comprehension
2405 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2406 ;
2407
2408 ComprehensionFor
2409 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2410 ;
2411 /* }}} */
2412 /* JavaScript FTL: for each {{{ */
2413 IterationStatement
2414 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2415 ;
2416 /* }}} */
2417
2418 /* JavaScript FTW: Array Comprehensions {{{ */
2419 PrimaryExpression
2420 : ArrayComprehension
2421 ;
2422
2423 ArrayComprehension
2424 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2425 ;
2426
2427 Comprehension
2428 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2429 ;
2430
2431 ComprehensionTail
2432 : { $$ = NULL; }
2433 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2434 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2435 ;
2436
2437 ComprehensionFor
2438 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2439 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2440 ;
2441
2442 ComprehensionIf
2443 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2444 ;
2445 /* }}} */
2446 /* JavaScript FTW: Coalesce Operator {{{ */
2447 ConditionalExpression
2448 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2449 ;
2450 /* }}} */
2451 /* JavaScript FTW: Named Arguments {{{ */
2452 ArgumentList
2453 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2454 ;
2455 /* }}} */
2456 /* JavaScript FTW: Ruby Blocks {{{ */
2457 RubyProcParameterList_
2458 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2459 | { $$ = NULL; }
2460 ;
2461
2462 RubyProcParameterList
2463 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2464 | LexOf { $$ = NULL; }
2465 ;
2466
2467 RubyProcParameters
2468 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2469 | "||" { $$ = NULL; }
2470 ;
2471
2472 RubyProcParametersOpt
2473 : RubyProcParameters[pass] { $$ = $pass; }
2474 | { $$ = NULL; }
2475 ;
2476
2477 RubyProcExpression
2478 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2479 ;
2480
2481 PrimaryExpression
2482 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2483 ;
2484
2485 PostfixExpression
2486 : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLine { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2487 ;
2488 /* }}} */
2489
2490 %%
2491
2492 bool CYDriver::Parse(CYMark mark) {
2493 mark_ = mark;
2494 CYLocal<CYPool> local(&pool_);
2495 cy::parser parser(*this);
2496 #ifdef YYDEBUG
2497 parser.set_debug_level(debug_);
2498 #endif
2499 return parser.parse() != 0;
2500 }
2501
2502 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2503 if (!strict_)
2504 return;
2505
2506 CYDriver::Error error;
2507 error.warning_ = true;
2508 error.location_ = location;
2509 error.message_ = message;
2510 errors_.push_back(error);
2511 }
2512
2513 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2514 CYDriver::Error error;
2515 error.warning_ = false;
2516 error.location_ = location;
2517 error.message_ = message;
2518 driver.errors_.push_back(error);
2519 }