]> git.saurik.com Git - cycript.git/blob - Parser.ypp.in
50cacb3ed1add2d47a19283e0437adde8ce8a839
[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 %token __ ""
308
309 %token Comment
310
311 %token OpenParen "("
312 %token CloseParen ")"
313
314 %token OpenBrace "{"
315 %token OpenBrace_ ";{"
316 %token OpenBrace_let "let {"
317 %token CloseBrace "}"
318
319 %token OpenBracket "["
320 %token OpenBracket_let "let ["
321 %token CloseBracket "]"
322
323 %token At_error_ "@error"
324
325 @begin Java
326 %token At_class_ "@class"
327 @end
328
329 @begin C
330 %token _typedef_ "typedef"
331 %token _unsigned_ "unsigned"
332 %token _signed_ "signed"
333 %token _extern_ "extern"
334 @end
335
336 @begin C
337 %token At_encode_ "@encode"
338 @end
339
340 @begin ObjectiveC
341 %token At_implementation_ "@implementation"
342 %token At_import_ "@import"
343 %token At_end_ "@end"
344 %token At_selector_ "@selector"
345 %token At_null_ "@null"
346 %token At_YES_ "@YES"
347 %token At_NO_ "@NO"
348 %token At_true_ "@true"
349 %token At_false_ "@false"
350 %token _YES_ "YES"
351 %token _NO_ "NO"
352 @end
353
354 %token _false_ "false"
355 %token _null_ "null"
356 %token _true_ "true"
357
358 %token _break_ "break"
359 %token _case_ "case"
360 %token _catch_ "catch"
361 %token _class_ "class"
362 %token _class__ ";class"
363 %token _const_ "const"
364 %token _continue_ "continue"
365 %token _debugger_ "debugger"
366 %token _default_ "default"
367 %token _delete_ "delete"
368 %token _do_ "do"
369 %token _else_ "else"
370 %token _enum_ "enum"
371 %token _export_ "export"
372 %token _extends_ "extends"
373 %token _finally_ "finally"
374 %token _for_ "for"
375 %token _function_ "function"
376 %token _function__ ";function"
377 %token _if_ "if"
378 %token _import_ "import"
379 %token _in_ "in"
380 %token _in__ "!in"
381 %token _Infinity_ "Infinity"
382 %token _instanceof_ "instanceof"
383 %token _new_ "new"
384 %token _return_ "return"
385 %token _super_ "super"
386 %token _switch_ "switch"
387 %token _target_ "target"
388 %token _this_ "this"
389 %token _throw_ "throw"
390 %token _try_ "try"
391 %token _typeof_ "typeof"
392 %token _var_ "var"
393 %token _void_ "void"
394 %token _while_ "while"
395 %token _with_ "with"
396
397 %token _abstract_ "abstract"
398 %token _await_ "await"
399 %token _boolean_ "boolean"
400 %token _byte_ "byte"
401 %token _char_ "char"
402 %token _constructor_ "constructor"
403 %token _double_ "double"
404 %token _eval_ "eval"
405 %token _final_ "final"
406 %token _float_ "float"
407 %token _from_ "from"
408 %token _get_ "get"
409 %token _goto_ "goto"
410 %token _implements_ "implements"
411 %token _int_ "int"
412 %token _interface_ "interface"
413 %token _let_ "let"
414 %token _let__ "!let"
415 %token _long_ "long"
416 %token _native_ "native"
417 %token _package_ "package"
418 %token _private_ "private"
419 %token _protected_ "protected"
420 %token _prototype_ "prototype"
421 %token _public_ "public"
422 %token _set_ "set"
423 %token _short_ "short"
424 %token _static_ "static"
425 %token _synchronized_ "synchronized"
426 %token _throws_ "throws"
427 %token _transient_ "transient"
428 %token _volatile_ "volatile"
429 %token _yield_ "yield"
430 %token _yield__ "!yield"
431
432 %token _undefined_ "undefined"
433
434 @begin ObjectiveC
435 %token _bool_ "bool"
436 %token _BOOL_ "BOOL"
437 %token _id_ "id"
438 %token _nil_ "nil"
439 %token _NULL_ "NULL"
440 %token _SEL_ "SEL"
441 @end
442
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 "yield *"
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 LexNewLineOrOpt
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 LexNewLineOrNot
728 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
729 ;
730
731 LexNoStar
732 : { CYMAP(YieldStar, Star); }
733 ;
734
735 LexNoBrace
736 : { CYMAP(OpenBrace_, OpenBrace); }
737 ;
738
739 LexNoClass
740 : { CYMAP(_class__, _class_); }
741 ;
742
743 LexNoFunction
744 : { CYMAP(_function__, _function_); }
745 ;
746
747 LexSetStatement
748 : LexNoBrace LexNoClass LexNoFunction
749 ;
750 /* }}} */
751 /* Virtual Tokens {{{ */
752 Var_
753 : "var"
754 ;
755 /* }}} */
756
757 /* 11.6 Names and Keywords {{{ */
758 IdentifierName
759 : Word[pass] { $$ = $pass; }
760 | "for" { $$ = CYNew CYWord("for"); }
761 | "in" { $$ = CYNew CYWord("in"); }
762 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
763 ;
764
765 Word
766 : IdentifierNoOf[pass] { $$ = $pass; }
767 | "break" { $$ = CYNew CYWord("break"); }
768 | "case" { $$ = CYNew CYWord("case"); }
769 | "catch" { $$ = CYNew CYWord("catch"); }
770 | "class" LexOf { $$ = CYNew CYWord("class"); }
771 | ";class" { $$ = CYNew CYWord("class"); }
772 | "const" { $$ = CYNew CYWord("const"); }
773 | "continue" { $$ = CYNew CYWord("continue"); }
774 | "debugger" { $$ = CYNew CYWord("debugger"); }
775 | "default" { $$ = CYNew CYWord("default"); }
776 | "delete" { $$ = CYNew CYWord("delete"); }
777 | "do" { $$ = CYNew CYWord("do"); }
778 | "else" { $$ = CYNew CYWord("else"); }
779 | "enum" { $$ = CYNew CYWord("enum"); }
780 | "export" { $$ = CYNew CYWord("export"); }
781 | "extends" { $$ = CYNew CYWord("extends"); }
782 | "false" { $$ = CYNew CYWord("false"); }
783 | "finally" { $$ = CYNew CYWord("finally"); }
784 | "function" LexOf { $$ = CYNew CYWord("function"); }
785 | "if" { $$ = CYNew CYWord("if"); }
786 | "import" { $$ = CYNew CYWord("import"); }
787 | "!in" { $$ = CYNew CYWord("in"); }
788 | "!of" { $$ = CYNew CYWord("of"); }
789 | "new" { $$ = CYNew CYWord("new"); }
790 | "null" { $$ = CYNew CYWord("null"); }
791 | "return" { $$ = CYNew CYWord("return"); }
792 | "super" { $$ = CYNew CYWord("super"); }
793 | "switch" { $$ = CYNew CYWord("switch"); }
794 | "this" { $$ = CYNew CYWord("this"); }
795 | "throw" { $$ = CYNew CYWord("throw"); }
796 | "true" { $$ = CYNew CYWord("true"); }
797 | "try" { $$ = CYNew CYWord("try"); }
798 | "typeof" { $$ = CYNew CYWord("typeof"); }
799 | "var" { $$ = CYNew CYWord("var"); }
800 | "void" { $$ = CYNew CYWord("void"); }
801 | "while" { $$ = CYNew CYWord("while"); }
802 | "with" { $$ = CYNew CYWord("with"); }
803 | "yield" { $$ = CYNew CYIdentifier("yield"); }
804 ;
805
806 @begin ObjectiveC
807 WordOpt
808 : Word[pass] { $$ = $pass; }
809 | { $$ = NULL; }
810 ;
811 @end
812 /* }}} */
813 /* 11.8.1 Null Literals {{{ */
814 NullLiteral
815 : "null" { $$ = CYNew CYNull(); }
816 ;
817 /* }}} */
818 /* 11.8.2 Boolean Literals {{{ */
819 BooleanLiteral
820 : "true" { $$ = CYNew CYTrue(); }
821 | "false" { $$ = CYNew CYFalse(); }
822 ;
823 /* }}} */
824 /* 11.8.5 Regular Expression Literals {{{ */
825 RegularExpressionSlash
826 : "/" { $$ = false; }
827 | "/=" { $$ = true; }
828 ;
829
830 RegularExpressionLiteral
831 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
832 ;
833 /* }}} */
834
835 /* 11.9 Automatic Semicolon Insertion {{{ */
836 StrictSemi
837 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
838 ;
839
840 NewLineNot
841 : LexNewLineOrNot ""
842 ;
843
844 NewLineOpt
845 : LexNewLineOrNot "\n"
846 | NewLineNot
847 ;
848
849 TerminatorSoft
850 : LexNewLineOrNot "\n" StrictSemi
851 | NewLineNot LexOf Terminator
852 ;
853
854 Terminator
855 : ";"
856 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
857 ;
858
859 TerminatorOpt
860 : ";"
861 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
862 ;
863 /* }}} */
864
865 /* 12.1 Identifiers {{{ */
866 IdentifierReference
867 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
868 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
869 ;
870
871 BindingIdentifier
872 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
873 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
874 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
875 ;
876
877 BindingIdentifierOpt
878 : BindingIdentifier[pass] { $$ = $pass; }
879 | LexOf { $$ = NULL; }
880 ;
881
882 LabelIdentifier
883 : Identifier[pass] { $$ = $pass; }
884 | "yield" { $$ = CYNew CYIdentifier("yield"); }
885 ;
886
887 IdentifierTypeNoOf
888 : Identifier_[pass] { $$ = $pass; }
889 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
890 | "await" { $$ = CYNew CYIdentifier("await"); }
891 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
892 | "byte" { $$ = CYNew CYIdentifier("byte"); }
893 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
894 | "double" { $$ = CYNew CYIdentifier("double"); }
895 | "each" { $$ = CYNew CYIdentifier("each"); }
896 | "eval" { $$ = CYNew CYIdentifier("eval"); }
897 | "final" { $$ = CYNew CYIdentifier("final"); }
898 | "float" { $$ = CYNew CYIdentifier("float"); }
899 | "from" { $$ = CYNew CYIdentifier("from"); }
900 | "get" { $$ = CYNew CYIdentifier("get"); }
901 | "goto" { $$ = CYNew CYIdentifier("goto"); }
902 | "implements" { $$ = CYNew CYIdentifier("implements"); }
903 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
904 | "interface" { $$ = CYNew CYIdentifier("interface"); }
905 | "let" { $$ = CYNew CYIdentifier("let"); }
906 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
907 | "native" { $$ = CYNew CYIdentifier("native"); }
908 | "package" { $$ = CYNew CYIdentifier("package"); }
909 | "private" { $$ = CYNew CYIdentifier("private"); }
910 | "protected" { $$ = CYNew CYIdentifier("protected"); }
911 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
912 | "public" { $$ = CYNew CYIdentifier("public"); }
913 | "set" { $$ = CYNew CYIdentifier("set"); }
914 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
915 | "target" { $$ = CYNew CYIdentifier("target"); }
916 | "throws" { $$ = CYNew CYIdentifier("throws"); }
917 | "transient" { $$ = CYNew CYIdentifier("transient"); }
918 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
919 @begin ObjectiveC
920 | "bool" { $$ = CYNew CYIdentifier("bool"); }
921 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
922 | "id" { $$ = CYNew CYIdentifier("id"); }
923 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
924 @end
925 ;
926
927 IdentifierType
928 : IdentifierTypeNoOf[pass] { $$ = $pass; }
929 | "of" { $$ = CYNew CYIdentifier("of"); }
930 ;
931
932 IdentifierNoOf
933 : IdentifierTypeNoOf
934 | "char" { $$ = CYNew CYIdentifier("char"); }
935 | "int" { $$ = CYNew CYIdentifier("int"); }
936 | "long" { $$ = CYNew CYIdentifier("long"); }
937 | "short" { $$ = CYNew CYIdentifier("short"); }
938 | "static" { $$ = CYNew CYIdentifier("static"); }
939 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
940 @begin C
941 | "signed" { $$ = CYNew CYIdentifier("signed"); }
942 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
943 @end
944 @begin ObjectiveC
945 | "nil" { $$ = CYNew CYIdentifier("nil"); }
946 | "NO" { $$ = CYNew CYIdentifier("NO"); }
947 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
948 | "YES" { $$ = CYNew CYIdentifier("YES"); }
949 @end
950 ;
951
952 Identifier
953 : IdentifierNoOf[pass] { $$ = $pass; }
954 | "of" { $$ = CYNew CYIdentifier("of"); }
955 | "!of" { $$ = CYNew CYIdentifier("of"); }
956 ;
957 /* }}} */
958 /* 12.2 Primary Expression {{{ */
959 PrimaryExpression
960 : "this" { $$ = CYNew CYThis(); }
961 | IdentifierReference[pass] { $$ = $pass; }
962 | Literal[pass] { $$ = $pass; }
963 | ArrayLiteral[pass] { $$ = $pass; }
964 | ObjectLiteral[pass] { $$ = $pass; }
965 | FunctionExpression[pass] { $$ = $pass; }
966 | ClassExpression[pass] { $$ = $pass; }
967 | GeneratorExpression[pass] { $$ = $pass; }
968 | RegularExpressionLiteral[pass] { $$ = $pass; }
969 | TemplateLiteral[pass] { $$ = $pass; }
970 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
971 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
972 ;
973
974 CoverParenthesizedExpressionAndArrowParameterList
975 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
976 | "(" LexOf ")" { $$ = NULL; }
977 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
978 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
979 ;
980 /* }}} */
981 /* 12.2.4 Literals {{{ */
982 Literal
983 : NullLiteral[pass] { $$ = $pass; }
984 | BooleanLiteral[pass] { $$ = $pass; }
985 | NumericLiteral[pass] { $$ = $pass; }
986 | StringLiteral[pass] { $$ = $pass; }
987 ;
988 /* }}} */
989 /* 12.2.5 Array Initializer {{{ */
990 ArrayLiteral
991 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
992 ;
993
994 ElementList
995 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
996 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
997 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
998 ;
999
1000 ElementListOpt
1001 : ElementList[pass] { $$ = $pass; }
1002 | LexOf { $$ = NULL; }
1003 ;
1004 /* }}} */
1005 /* 12.2.6 Object Initializer {{{ */
1006 ObjectLiteral
1007 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1008 ;
1009
1010 PropertyDefinitionList_
1011 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1012 | { $$ = NULL; }
1013 ;
1014
1015 PropertyDefinitionList
1016 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1017 ;
1018
1019 PropertyDefinitionListOpt
1020 : PropertyDefinitionList[properties] { $$ = $properties; }
1021 | { $$ = NULL; }
1022 ;
1023
1024 PropertyDefinition
1025 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1026 | CoverInitializedName[name] { CYNOT(@$); }
1027 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1028 | MethodDefinition[pass] { $$ = $pass; }
1029 ;
1030
1031 PropertyName
1032 : LiteralPropertyName[pass] { $$ = $pass; }
1033 | ComputedPropertyName[pass] { $$ = $pass; }
1034 ;
1035
1036 LiteralPropertyName
1037 : IdentifierName[pass] { $$ = $pass; }
1038 | StringLiteral[pass] { $$ = $pass; }
1039 | NumericLiteral[pass] { $$ = $pass; }
1040 ;
1041
1042 ComputedPropertyName
1043 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1044 ;
1045
1046 CoverInitializedName
1047 : IdentifierReference Initializer
1048 ;
1049
1050 Initializer
1051 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1052 ;
1053
1054 InitializerOpt
1055 : Initializer[pass] { $$ = $pass; }
1056 | { $$ = NULL; }
1057 ;
1058 /* }}} */
1059 /* 12.2.9 Template Literals {{{ */
1060 TemplateLiteral
1061 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1062 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1063 ;
1064
1065 TemplateSpans
1066 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1067 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1068 ;
1069 /* }}} */
1070
1071 /* 12.3 Left-Hand-Side Expressions {{{ */
1072 MemberAccess
1073 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1074 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1075 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1076 | TemplateLiteral { CYNOT(@$); }
1077 ;
1078
1079 MemberExpression
1080 : PrimaryExpression[pass] { $$ = $pass; }
1081 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1082 | SuperProperty[pass] { $$ = $pass; }
1083 | MetaProperty { CYNOT(@$); }
1084 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1085 ;
1086
1087 SuperProperty
1088 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1089 | "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1090 ;
1091
1092 MetaProperty
1093 : NewTarget
1094 ;
1095
1096 NewTarget
1097 : "new" "." "target"
1098 ;
1099
1100 NewExpression
1101 : MemberExpression[pass] { $$ = $pass; }
1102 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1103 ;
1104
1105 CallExpression_
1106 : MemberExpression[pass] { $$ = $pass; }
1107 | CallExpression[pass] { $$ = $pass; }
1108 ;
1109
1110 CallExpression
1111 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1112 | SuperCall[pass] { $$ = $pass; }
1113 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1114 ;
1115
1116 SuperCall
1117 : "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); } Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1118 ;
1119
1120 Arguments
1121 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1122 ;
1123
1124 ArgumentList_
1125 : "," ArgumentList[arguments] { $$ = $arguments; }
1126 | { $$ = NULL; }
1127 ;
1128
1129 ArgumentList
1130 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1131 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1132 ;
1133
1134 ArgumentListOpt
1135 : ArgumentList[pass] { $$ = $pass; }
1136 | LexOf { $$ = NULL; }
1137 ;
1138
1139 AccessExpression
1140 : NewExpression[pass] { $$ = $pass; }
1141 | CallExpression[pass] { $$ = $pass; }
1142 ;
1143
1144 LeftHandSideExpression
1145 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
1146 | IndirectExpression[pass] { $$ = $pass; }
1147 ;
1148 /* }}} */
1149 /* 12.4 Postfix Expressions {{{ */
1150 PostfixExpression
1151 : AccessExpression[lhs] LexNewLineOrOpt { $$ = $lhs; }
1152 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1153 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1154 ;
1155 /* }}} */
1156 /* 12.5 Unary Operators {{{ */
1157 UnaryExpression_
1158 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1159 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1160 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1161 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1162 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1163 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1164 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1165 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1166 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1167 ;
1168
1169 UnaryExpression
1170 : PostfixExpression[expression] { $$ = $expression; }
1171 | PostfixExpression[expression] "\n" { $$ = $expression; }
1172 | UnaryExpression_[pass] { $$ = $pass; }
1173 ;
1174 /* }}} */
1175 /* 12.6 Multiplicative Operators {{{ */
1176 MultiplicativeExpression
1177 : UnaryExpression[pass] { $$ = $pass; }
1178 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1179 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1180 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1181 ;
1182 /* }}} */
1183 /* 12.7 Additive Operators {{{ */
1184 AdditiveExpression
1185 : MultiplicativeExpression[pass] { $$ = $pass; }
1186 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1187 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1188 ;
1189 /* }}} */
1190 /* 12.8 Bitwise Shift Operators {{{ */
1191 ShiftExpression
1192 : AdditiveExpression[pass] { $$ = $pass; }
1193 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1194 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1195 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1196 ;
1197 /* }}} */
1198 /* 12.9 Relational Operators {{{ */
1199 RelationalExpression
1200 : ShiftExpression[pass] { $$ = $pass; }
1201 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1202 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1203 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1204 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1205 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1206 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1207 ;
1208 /* }}} */
1209 /* 12.10 Equality Operators {{{ */
1210 EqualityExpression
1211 : RelationalExpression[pass] { $$ = $pass; }
1212 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1213 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1214 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1215 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1216 ;
1217 /* }}} */
1218 /* 12.11 Binary Bitwise Operators {{{ */
1219 BitwiseANDExpression
1220 : EqualityExpression[pass] { $$ = $pass; }
1221 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1222 ;
1223
1224 BitwiseXORExpression
1225 : BitwiseANDExpression[pass] { $$ = $pass; }
1226 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1227 ;
1228
1229 BitwiseORExpression
1230 : BitwiseXORExpression[pass] { $$ = $pass; }
1231 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1232 ;
1233 /* }}} */
1234 /* 12.12 Binary Logical Operators {{{ */
1235 LogicalANDExpression
1236 : BitwiseORExpression[pass] { $$ = $pass; }
1237 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1238 ;
1239
1240 LogicalORExpression
1241 : LogicalANDExpression[pass] { $$ = $pass; }
1242 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1243 ;
1244 /* }}} */
1245 /* 12.13 Conditional Operator ( ? : ) {{{ */
1246 @begin ObjectiveC
1247 ConditionalExpressionClassic
1248 : LogicalORExpression[pass] { $$ = $pass; }
1249 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1250 ;
1251 @end
1252
1253 ConditionalExpression
1254 : LogicalORExpression[pass] { $$ = $pass; }
1255 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1256 ;
1257 /* }}} */
1258 /* 12.14 Assignment Operators {{{ */
1259 LeftHandSideAssignment
1260 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1261 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1262 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1263 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1264 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1265 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1266 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1267 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1268 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1269 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1270 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1271 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1272 ;
1273
1274 @begin ObjectiveC
1275 AssignmentExpressionClassic
1276 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1277 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1278 ;
1279 @end
1280
1281 AssignmentExpression
1282 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1283 | LexOf YieldExpression[pass] { $$ = $pass; }
1284 | ArrowFunction[pass] { $$ = $pass; }
1285 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1286 ;
1287
1288 AssignmentExpressionOpt
1289 : AssignmentExpression[pass] { $$ = $pass; }
1290 | LexOf { $$ = NULL; }
1291 ;
1292 /* }}} */
1293 /* 12.15 Comma Operator ( , ) {{{ */
1294 Expression
1295 : AssignmentExpression[pass] { $$ = $pass; }
1296 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1297 ;
1298
1299 ExpressionOpt
1300 : Expression[pass] { $$ = $pass; }
1301 | LexOf { $$ = NULL; }
1302 ;
1303 /* }}} */
1304
1305 /* 13 Statements and Declarations {{{ */
1306 Statement__
1307 : BlockStatement[pass] { $$ = $pass; }
1308 | VariableStatement[pass] { $$ = $pass; }
1309 | EmptyStatement[pass] { $$ = $pass; }
1310 | IfStatement[pass] { $$ = $pass; }
1311 | BreakableStatement[pass] { $$ = $pass; }
1312 | ContinueStatement[pass] { $$ = $pass; }
1313 | BreakStatement[pass] { $$ = $pass; }
1314 | ReturnStatement[pass] { $$ = $pass; }
1315 | WithStatement[pass] { $$ = $pass; }
1316 | LabelledStatement[pass] { $$ = $pass; }
1317 | ThrowStatement[pass] { $$ = $pass; }
1318 | TryStatement[pass] { $$ = $pass; }
1319 | DebuggerStatement[pass] { $$ = $pass; }
1320 ;
1321
1322 Statement_
1323 : LexOf Statement__[pass] { $$ = $pass; }
1324 | ExpressionStatement[pass] { $$ = $pass; }
1325 ;
1326
1327 Statement
1328 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1329 ;
1330
1331 Declaration_
1332 : HoistableDeclaration[pass] { $$ = $pass; }
1333 | ClassDeclaration[pass] { $$ = $pass; }
1334 ;
1335
1336 Declaration
1337 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1338 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1339 ;
1340
1341 HoistableDeclaration
1342 : FunctionDeclaration[pass] { $$ = $pass; }
1343 | GeneratorDeclaration[pass] { $$ = $pass; }
1344 ;
1345
1346 BreakableStatement
1347 : IterationStatement[pass] { $$ = $pass; }
1348 | SwitchStatement[pass] { $$ = $pass; }
1349 ;
1350 /* }}} */
1351 /* 13.2 Block {{{ */
1352 BlockStatement
1353 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1354 ;
1355
1356 Block
1357 : "{" StatementListOpt[code] "}" { $$ = $code; }
1358 ;
1359
1360 StatementList
1361 : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
1362 ;
1363
1364 StatementListOpt
1365 : StatementList[pass] { $$ = $pass; }
1366 | LexSetStatement LexLet LexOf { $$ = NULL; }
1367 ;
1368
1369 StatementListItem
1370 : Statement[pass] { $$ = $pass; }
1371 | Declaration[pass] { $$ = $pass; }
1372 ;
1373 /* }}} */
1374 /* 13.3 Let and Const Declarations {{{ */
1375 LexicalDeclaration_
1376 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1377 ;
1378
1379 LexicalDeclaration
1380 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1381 ;
1382
1383 LexLet
1384 : { CYMAP(_let__, _let_); }
1385 ;
1386
1387 LexOf
1388 : { CYMAP(_of__, _of_); }
1389 ;
1390
1391 LexBind
1392 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1393 ;
1394
1395 LetOrConst
1396 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1397 | LexLet LexOf "const" { $$ = true; }
1398 ;
1399
1400 BindingList_
1401 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1402 | { $$ = NULL; }
1403 ;
1404
1405 BindingList
1406 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1407 ;
1408
1409 LexicalBinding
1410 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1411 | LexOf BindingPattern Initializer { CYNOT(@$); }
1412 ;
1413 /* }}} */
1414 /* 13.3.2 Variable Statement {{{ */
1415 VariableStatement_
1416 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1417 ;
1418
1419 VariableStatement
1420 : VariableStatement_[statement] Terminator { $$ = $statement; }
1421 ;
1422
1423 VariableDeclarationList_
1424 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1425 | { $$ = NULL; }
1426 ;
1427
1428 VariableDeclarationList
1429 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1430 ;
1431
1432 VariableDeclaration
1433 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1434 | LexOf BindingPattern Initializer { CYNOT(@$); }
1435 ;
1436 /* }}} */
1437 /* 13.3.3 Destructuring Binding Patterns {{{ */
1438 BindingPattern
1439 : ObjectBindingPattern
1440 | ArrayBindingPattern
1441 ;
1442
1443 ObjectBindingPattern
1444 : "let {" BindingPropertyListOpt "}"
1445 ;
1446
1447 ArrayBindingPattern
1448 : "let [" BindingElementListOpt "]"
1449 ;
1450
1451 BindingPropertyList_
1452 : "," BindingPropertyListOpt
1453 |
1454 ;
1455
1456 BindingPropertyList
1457 : BindingProperty BindingPropertyList_
1458 ;
1459
1460 BindingPropertyListOpt
1461 : BindingPropertyList
1462 | LexOf
1463 ;
1464
1465 BindingElementList
1466 : BindingElementOpt[element] "," BindingElementListOpt[next]
1467 | BindingRestElement[element]
1468 | BindingElement[element]
1469 ;
1470
1471 BindingElementListOpt
1472 : BindingElementList[pass]
1473 | LexBind LexOf
1474 ;
1475
1476 BindingProperty
1477 : SingleNameBinding
1478 | LexOf PropertyName ":" BindingElement
1479 ;
1480
1481 BindingElement
1482 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1483 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1484 ;
1485
1486 BindingElementOpt
1487 : BindingElement[pass]
1488 | LexBind LexOf
1489 ;
1490
1491 SingleNameBinding
1492 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1493 ;
1494
1495 BindingRestElement
1496 : LexBind LexOf "..." BindingIdentifier
1497 ;
1498 /* }}} */
1499 /* 13.4 Empty Statement {{{ */
1500 EmptyStatement
1501 : ";" { $$ = CYNew CYEmpty(); }
1502 ;
1503 /* }}} */
1504 /* 13.5 Expression Statement {{{ */
1505 ExpressionStatement_
1506 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1507
1508 ExpressionStatement
1509 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1510 ;
1511 /* }}} */
1512 /* 13.6 The if Statement {{{ */
1513 ElseStatementOpt
1514 : "else" Statement[false] { $$ = $false; }
1515 | %prec "if" { $$ = NULL; }
1516 ;
1517
1518 IfStatement
1519 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1520 ;
1521 /* }}} */
1522 /* 13.7 Iteration Statements {{{ */
1523 IterationStatement
1524 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1525 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1526 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1527 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1528 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1529 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1530 ;
1531
1532 ForStatementInitializer
1533 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1534 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1535 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1536 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1537 ;
1538
1539 ForInStatementInitializer
1540 : LexLet LexOf AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
1541 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1542 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1543 | ForDeclaration[pass] { $$ = $pass; }
1544 ;
1545
1546 ForDeclaration
1547 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1548 ;
1549
1550 ForBinding
1551 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1552 | LexOf BindingPattern { CYNOT(@$); }
1553 ;
1554 /* }}} */
1555 /* 13.8 The continue Statement {{{ */
1556 ContinueStatement
1557 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1558 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1559 ;
1560 /* }}} */
1561 /* 13.9 The break Statement {{{ */
1562 BreakStatement
1563 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1564 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1565 ;
1566 /* }}} */
1567 /* 13.10 The return Statement {{{ */
1568 Return
1569 : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }
1570 ;
1571
1572 ReturnStatement
1573 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1574 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1575 ;
1576 /* }}} */
1577 /* 13.11 The with Statement {{{ */
1578 WithStatement
1579 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1580 ;
1581 /* }}} */
1582 /* 13.12 The switch Statement {{{ */
1583 SwitchStatement
1584 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1585 ;
1586
1587 CaseBlock
1588 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1589 ;
1590
1591 CaseClause
1592 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1593 ;
1594
1595 CaseClausesOpt
1596 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1597 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1598 | { $$ = NULL; }
1599 ;
1600
1601 // XXX: the standard makes certain you can only have one of these
1602 DefaultClause
1603 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1604 ;
1605 /* }}} */
1606 /* 13.13 Labelled Statements {{{ */
1607 LabelledStatement
1608 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1609 ;
1610
1611 LabelledItem
1612 : Statement[pass] { $$ = $pass; }
1613 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1614 ;
1615 /* }}} */
1616 /* 13.14 The throw Statement {{{ */
1617 ThrowStatement
1618 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1619 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1620 ;
1621 /* }}} */
1622 /* 13.15 The try Statement {{{ */
1623 TryStatement
1624 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1625 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1626 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1627 ;
1628
1629 Catch
1630 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1631 ;
1632
1633 Finally
1634 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1635 ;
1636
1637 CatchParameter
1638 : BindingIdentifier[pass] { $$ = $pass; }
1639 | LexOf BindingPattern { CYNOT(@$); }
1640 ;
1641 /* }}} */
1642 /* 13.16 The debugger Statement {{{ */
1643 DebuggerStatement
1644 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1645 ;
1646 /* }}} */
1647
1648 /* 14.1 Function Definitions {{{ */
1649 FunctionDeclaration
1650 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1651 ;
1652
1653 FunctionExpression
1654 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1655 ;
1656
1657 StrictFormalParameters
1658 : FormalParameters[pass] { $$ = $pass; }
1659 ;
1660
1661 FormalParameters
1662 : LexBind LexOf { $$ = NULL; }
1663 | FormalParameterList
1664 ;
1665
1666 FormalParameterList_
1667 : "," FormalParameterList[parameters] { $$ = $parameters; }
1668 | { $$ = NULL; }
1669 ;
1670
1671 FormalParameterList
1672 : FunctionRestParameter { CYNOT(@$); }
1673 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1674 ;
1675
1676 FunctionRestParameter
1677 : BindingRestElement
1678 ;
1679
1680 FormalParameter
1681 : BindingElement[pass] { $$ = $pass; }
1682 ;
1683
1684 FunctionBody
1685 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1686 ;
1687
1688 FunctionStatementList
1689 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1690 ;
1691 /* }}} */
1692 /* 14.2 Arrow Function Definitions {{{ */
1693 ArrowFunction
1694 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1695 ;
1696
1697 ArrowParameters
1698 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1699 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1700 ;
1701
1702 ConciseBody
1703 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1704 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1705 ;
1706 /* }}} */
1707 /* 14.3 Method Definitions {{{ */
1708 MethodDefinition
1709 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1710 | GeneratorMethod[pass] { $$ = $pass; }
1711 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1712 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1713 ;
1714
1715 PropertySetParameterList
1716 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1717 ;
1718 /* }}} */
1719 /* 14.4 Generator Function Definitions {{{ */
1720 GeneratorMethod
1721 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1722 ;
1723
1724 GeneratorDeclaration
1725 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1726 ;
1727
1728 GeneratorExpression
1729 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1730 ;
1731
1732 GeneratorBody
1733 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1734 ;
1735
1736 YieldExpression
1737 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1738 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1739 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1740 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1741 ;
1742 /* }}} */
1743 /* 14.5 Class Definitions {{{ */
1744 ClassDeclaration
1745 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1746 ;
1747
1748 ClassExpression
1749 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1750 ;
1751
1752 ClassTail
1753 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1754 ;
1755
1756 ClassHeritage
1757 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1758 ;
1759
1760 ClassHeritageOpt
1761 : ClassHeritage[pass] { $$ = $pass; }
1762 | { $$ = CYNew CYClassTail(NULL); }
1763 ;
1764
1765 ClassBody
1766 : ClassElementList
1767 ;
1768
1769 ClassBodyOpt
1770 : ClassBody
1771 |
1772 ;
1773
1774 ClassElementList
1775 : ClassElementListOpt ClassElement
1776 ;
1777
1778 ClassElementListOpt
1779 : ClassElementList
1780 |
1781 ;
1782
1783 ClassElement
1784 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1785 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1786 | ";"
1787 ;
1788 /* }}} */
1789
1790 /* 15.1 Scripts {{{ */
1791 Script
1792 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1793 ;
1794
1795 ScriptBody
1796 : StatementList[pass] { $$ = $pass; }
1797 ;
1798
1799 ScriptBodyOpt
1800 : ScriptBody[pass] { $$ = $pass; }
1801 | LexSetStatement LexLet LexOf { $$ = NULL; }
1802 ;
1803 /* }}} */
1804 /* 15.2 Modules {{{ */
1805 Module
1806 : ModuleBodyOpt
1807 ;
1808
1809 ModuleBody
1810 : ModuleItemList
1811 ;
1812
1813 ModuleBodyOpt
1814 : ModuleBody
1815 |
1816 ;
1817
1818 ModuleItemList
1819 : ModuleItemListOpt ModuleItem
1820 ;
1821
1822 ModuleItemListOpt
1823 : ModuleItemList
1824 |
1825 ;
1826
1827 ModuleItem
1828 : LexSetStatement LexLet LexOf ImportDeclaration
1829 | LexSetStatement LexLet LexOf ExportDeclaration
1830 | StatementListItem
1831 ;
1832 /* }}} */
1833 /* 15.2.2 Imports {{{ */
1834 ImportDeclaration
1835 : "import" ImportClause FromClause Terminator
1836 | "import" LexOf ModuleSpecifier Terminator
1837 ;
1838
1839 ImportClause
1840 : ImportedDefaultBinding
1841 | LexOf NameSpaceImport
1842 | LexOf NamedImports
1843 | ImportedDefaultBinding "," NameSpaceImport
1844 | ImportedDefaultBinding "," NamedImports
1845 ;
1846
1847 ImportedDefaultBinding
1848 : ImportedBinding
1849 ;
1850
1851 NameSpaceImport
1852 : "*" "as" ImportedBinding
1853 ;
1854
1855 NamedImports
1856 : "{" ImportsListOpt "}"
1857 ;
1858
1859 FromClause
1860 : "from" ModuleSpecifier
1861 ;
1862
1863 ImportsList_
1864 : "," ImportsListOpt
1865 |
1866 ;
1867
1868 ImportsList
1869 : ImportSpecifier ImportsList_
1870 ;
1871
1872 ImportsListOpt
1873 : ImportsList
1874 | LexOf
1875 ;
1876
1877 ImportSpecifier
1878 : ImportedBinding
1879 | LexOf IdentifierName "as" ImportedBinding
1880 ;
1881
1882 ModuleSpecifier
1883 : StringLiteral
1884 ;
1885
1886 ImportedBinding
1887 : BindingIdentifier
1888 ;
1889 /* }}} */
1890 /* 15.2.3 Exports {{{ */
1891 ExportDeclaration_
1892 : "*" FromClause Terminator
1893 | ExportClause FromClause Terminator
1894 | ExportClause Terminator
1895 | VariableStatement
1896 | "default" LexSetStatement LexOf HoistableDeclaration
1897 | "default" LexSetStatement LexOf ClassDeclaration
1898 | "default" LexSetStatement AssignmentExpression Terminator
1899 ;
1900
1901 ExportDeclaration
1902 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1903 | "export" Declaration
1904 ;
1905
1906 ExportClause
1907 : ";{" ExportsListOpt "}"
1908 ;
1909
1910 ExportsList_
1911 : "," ExportsListOpt
1912 |
1913 ;
1914
1915 ExportsList
1916 : ExportSpecifier ExportsList_
1917 ;
1918
1919 ExportsListOpt
1920 : ExportsList
1921 |
1922 ;
1923
1924 ExportSpecifier
1925 : IdentifierName
1926 | IdentifierName "as" IdentifierName
1927 ;
1928 /* }}} */
1929
1930 @begin C
1931 /* Cycript (C): Type Encoding {{{ */
1932 TypeSignifier
1933 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1934 | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; }
1935 ;
1936
1937 SuffixedType
1938 : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1939 | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1940 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1941 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1942 | TypeSignifier[pass] { $$ = $pass; }
1943 | { $$ = CYNew CYTypedIdentifier(@$); }
1944 ;
1945
1946 PrefixedType
1947 : "*" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1948 ;
1949
1950 TypeQualifierLeft
1951 : { $$ = NULL; }
1952 | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1953 | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1954 ;
1955
1956 TypeQualifierRight
1957 : PrefixedType[pass] { $$ = $pass; }
1958 | SuffixedType[pass] { $$ = $pass; }
1959 | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1960 | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1961 ;
1962
1963 IntegerType
1964 : "int" { $$ = CYNew CYTypeVariable("int"); }
1965 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
1966 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
1967 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
1968 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
1969 ;
1970
1971 IntegerTypeOpt
1972 : IntegerType[pass] { $$ = $pass; }
1973 | { $$ = CYNew CYTypeVariable("int"); }
1974 ;
1975
1976 PrimitiveType
1977 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
1978 | IntegerType[pass] { $$ = $pass; }
1979 | "void" { $$ = CYNew CYTypeVoid(); }
1980 | "char" { $$ = CYNew CYTypeVariable("char"); }
1981 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1982 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1983 ;
1984
1985 TypedIdentifier
1986 : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
1987 ;
1988
1989 PrimaryExpression
1990 : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
1991 ;
1992 /* }}} */
1993 @end
1994
1995 @begin ObjectiveC
1996 /* Cycript (Objective-C): @class Declaration {{{ */
1997 ClassSuperOpt
1998 /* XXX: why the hell did I choose MemberExpression? */
1999 : ":" MemberExpression[extends] { $$ = $extends; }
2000 | { $$ = NULL; }
2001 ;
2002
2003 ImplementationFieldListOpt
2004 : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2005 | { $$ = NULL; }
2006 ;
2007
2008 ImplementationFields
2009 : "{" ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
2010 ;
2011
2012 MessageScope
2013 : "+" { $$ = false; }
2014 | "-" { $$ = true; }
2015 ;
2016
2017 TypeOpt
2018 : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
2019 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2020 ;
2021
2022 MessageParameter
2023 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2024 ;
2025
2026 MessageParameterList
2027 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2028 ;
2029
2030 MessageParameterListOpt
2031 : MessageParameterList[pass] { $$ = $pass; }
2032 | { $$ = NULL; }
2033 ;
2034
2035 MessageParameters
2036 : MessageParameterList[pass] { $$ = $pass; }
2037 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2038 ;
2039
2040 ClassMessageDeclaration
2041 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2042 ;
2043
2044 ClassMessageDeclarationListOpt
2045 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2046 | { $$ = NULL; }
2047 ;
2048
2049 // XXX: this should be AssignmentExpressionNoRight
2050 ClassProtocols
2051 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2052 ;
2053
2054 ClassProtocolsOpt
2055 : "," ClassProtocols[protocols] { $$ = $protocols; }
2056 | { $$ = NULL; }
2057 ;
2058
2059 ClassProtocolListOpt
2060 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2061 | { $$ = NULL; }
2062 ;
2063
2064 ImplementationStatement
2065 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2066 ;
2067
2068 CategoryName
2069 : "(" WordOpt ")"
2070 ;
2071
2072 CategoryStatement
2073 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2074 ;
2075
2076 Statement__
2077 : ImplementationStatement[pass] { $$ = $pass; }
2078 | CategoryStatement[pass] { $$ = $pass; }
2079 ;
2080 /* }}} */
2081 /* Cycript (Objective-C): Send Message {{{ */
2082 VariadicCall
2083 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2084 | { $$ = NULL; }
2085 ;
2086
2087 SelectorWordOpt
2088 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2089 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2090 ;
2091
2092 SelectorCall_
2093 : SelectorCall[pass] { $$ = $pass; }
2094 | VariadicCall[pass] { $$ = $pass; }
2095 ;
2096
2097 SelectorCall
2098 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2099 ;
2100
2101 SelectorList
2102 : SelectorCall[pass] { $$ = $pass; }
2103 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2104 ;
2105
2106 MessageExpression
2107 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2108 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2109 ;
2110
2111 SelectorExpression_
2112 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2113 ;
2114
2115 SelectorExpression
2116 : SelectorExpression_[pass] { $$ = $pass; }
2117 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2118 ;
2119
2120 SelectorExpressionOpt
2121 : SelectorExpression_[pass] { $$ = $pass; }
2122 | { $$ = NULL; }
2123 ;
2124
2125 PrimaryExpression
2126 : MessageExpression[pass] { $$ = $pass; }
2127 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2128 ;
2129 /* }}} */
2130 @end
2131
2132 /* Cycript: @import Directive {{{ */
2133 ModulePath
2134 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2135 | Word[part] { $$ = CYNew CYModule($part); }
2136 ;
2137
2138 Declaration_
2139 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2140 ;
2141 /* }}} */
2142
2143 @begin ObjectiveC
2144 /* Cycript (Objective-C): Boxed Expressions {{{ */
2145 BoxableExpression
2146 : NullLiteral[pass] { $$ = $pass; }
2147 | BooleanLiteral[pass] { $$ = $pass; }
2148 | NumericLiteral[pass] { $$ = $pass; }
2149 | StringLiteral[pass] { $$ = $pass; }
2150 | ArrayLiteral[pass] { $$ = $pass; }
2151 | ObjectLiteral[pass] { $$ = $pass; }
2152 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2153 | "YES" { $$ = CYNew CYTrue(); }
2154 | "NO" { $$ = CYNew CYFalse(); }
2155 ;
2156
2157 PrimaryExpression
2158 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2159 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2160 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2161 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2162 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2163 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2164 ;
2165 /* }}} */
2166 /* Cycript (Objective-C): Block Expressions {{{ */
2167 PrimaryExpression
2168 : "^" 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"); }
2169 ;
2170 /* }}} */
2171 /* Cycript (Objective-C): Instance Literals {{{ */
2172 PrimaryExpression
2173 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2174 ;
2175 /* }}} */
2176 @end
2177
2178 @begin C
2179 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2180 UnaryExpression_
2181 : IndirectExpression[pass] { $$ = $pass; }
2182 ;
2183
2184 IndirectExpression
2185 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2186 ;
2187
2188 UnaryExpression_
2189 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2190 ;
2191
2192 MemberAccess
2193 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2194 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2195 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2196 ;
2197 /* }}} */
2198 /* Cycript (C): Lambda Expressions {{{ */
2199 TypedParameterList_
2200 : "," TypedParameterList[parameters] { $$ = $parameters; }
2201 | { $$ = NULL; }
2202 ;
2203
2204 TypedParameterList
2205 : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2206 ;
2207
2208 TypedParameterListOpt
2209 : TypedParameterList[pass] { $$ = $pass; }
2210 | { $$ = NULL; }
2211 ;
2212
2213 PrimaryExpression
2214 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2215 ;
2216 /* }}} */
2217 /* Cycript (C): Type Definitions {{{ */
2218 IdentifierNoOf
2219 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2220 ;
2221
2222 Statement__
2223 : "typedef" NewLineNot TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
2224 ;
2225 /* }}} */
2226 /* Cycript (C): extern "C" {{{ */
2227 IdentifierNoOf
2228 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2229 ;
2230
2231 Statement__
2232 : "extern" NewLineNot 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); }
2233 ;
2234 /* }}} */
2235
2236 @end
2237
2238 @begin E4X
2239 /* Lexer State {{{ */
2240 LexPushRegExp
2241 : { driver.PushCondition(CYDriver::RegExpCondition); }
2242 ;
2243
2244 LexPushXMLContent
2245 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2246 ;
2247
2248 LexPushXMLTag
2249 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2250 ;
2251
2252 LexPop
2253 : { driver.PopCondition(); }
2254 ;
2255
2256 LexSetXMLContent
2257 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2258 ;
2259
2260 LexSetXMLTag
2261 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2262 ;
2263 /* }}} */
2264 /* Virtual Tokens {{{ */
2265 XMLWhitespaceOpt
2266 : XMLWhitespace
2267 |
2268 ;
2269 /* }}} */
2270
2271 /* 8.1 Context Keywords {{{ */
2272 Identifier
2273 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2274 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2275 ;
2276 /* }}} */
2277 /* 8.3 XML Initializer Input Elements {{{ */
2278 XMLMarkup
2279 : XMLComment { $$ = $1; }
2280 | XMLCDATA { $$ = $1; }
2281 | XMLPI { $$ = $1; }
2282 ;
2283 /* }}} */
2284
2285 /* 11.1 Primary Expressions {{{ */
2286 PrimaryExpression
2287 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2288 | XMLInitilizer { $$ = $1; }
2289 | XMLListInitilizer { $$ = $1; }
2290 ;
2291
2292 PropertyIdentifier
2293 : AttributeIdentifier { $$ = $1; }
2294 | QualifiedIdentifier { $$ = $1; }
2295 | WildcardIdentifier { $$ = $1; }
2296 ;
2297 /* }}} */
2298 /* 11.1.1 Attribute Identifiers {{{ */
2299 AttributeIdentifier
2300 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2301 ;
2302
2303 PropertySelector_
2304 : PropertySelector { $$ = $1; }
2305 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2306 ;
2307
2308 PropertySelector
2309 : Identifier { $$ = CYNew CYSelector($1); }
2310 | WildcardIdentifier { $$ = $1; }
2311 ;
2312 /* }}} */
2313 /* 11.1.2 Qualified Identifiers {{{ */
2314 QualifiedIdentifier_
2315 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2316 | QualifiedIdentifier { $$ = $1; }
2317 ;
2318
2319 QualifiedIdentifier
2320 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2321 ;
2322 /* }}} */
2323 /* 11.1.3 Wildcard Identifiers {{{ */
2324 WildcardIdentifier
2325 : "*" { $$ = CYNew CYWildcard(); }
2326 ;
2327 /* }}} */
2328 /* 11.1.4 XML Initializer {{{ */
2329 XMLInitilizer
2330 : XMLMarkup { $$ = $1; }
2331 | XMLElement { $$ = $1; }
2332 ;
2333
2334 XMLElement
2335 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2336 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2337 ;
2338
2339 XMLTagContent
2340 : LexPushXMLTag XMLTagName XMLAttributes
2341 ;
2342
2343 XMLExpression
2344 : "{" LexPushRegExp Expression LexPop "}"
2345 ;
2346
2347 XMLTagName
2348 : XMLExpression
2349 | XMLName
2350 ;
2351
2352 XMLAttributes_
2353 : XMLAttributes_ XMLAttribute
2354 |
2355 ;
2356
2357 XMLAttributes
2358 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2359 | XMLAttributes_ XMLWhitespaceOpt
2360 ;
2361
2362 XMLAttributeValue_
2363 : XMLExpression
2364 | XMLAttributeValue
2365 ;
2366
2367 XMLAttribute
2368 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2369 ;
2370
2371 XMLElementContent
2372 : XMLExpression XMLElementContentOpt
2373 | XMLMarkup XMLElementContentOpt
2374 | XMLText XMLElementContentOpt
2375 | XMLElement XMLElementContentOpt
2376 ;
2377
2378 XMLElementContentOpt
2379 : XMLElementContent
2380 |
2381 ;
2382 /* }}} */
2383 /* 11.1.5 XMLList Initializer {{{ */
2384 XMLListInitilizer
2385 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2386 ;
2387 /* }}} */
2388
2389 /* 11.2 Left-Hand-Side Expressions {{{ */
2390 PropertyIdentifier_
2391 : Identifier { $$ = $1; }
2392 | PropertyIdentifier { $$ = $1; }
2393 ;
2394
2395 MemberAccess
2396 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2397 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2398 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2399 ;
2400 /* }}} */
2401 /* 12.1 The default xml namespace Statement {{{ */
2402 /* XXX: DefaultXMLNamespaceStatement
2403 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2404 ;
2405
2406 Statement__
2407 : DefaultXMLNamespaceStatement { $$ = $1; }
2408 ; */
2409 /* }}} */
2410 @end
2411
2412 /* JavaScript FTL: Array Comprehensions {{{ */
2413 Comprehension
2414 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2415 ;
2416
2417 ComprehensionFor
2418 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2419 ;
2420 /* }}} */
2421 /* JavaScript FTL: for each {{{ */
2422 IterationStatement
2423 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2424 ;
2425 /* }}} */
2426
2427 /* JavaScript FTW: Array Comprehensions {{{ */
2428 PrimaryExpression
2429 : ArrayComprehension
2430 ;
2431
2432 ArrayComprehension
2433 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2434 ;
2435
2436 Comprehension
2437 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2438 ;
2439
2440 ComprehensionTail
2441 : { $$ = NULL; }
2442 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2443 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2444 ;
2445
2446 ComprehensionFor
2447 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2448 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2449 ;
2450
2451 ComprehensionIf
2452 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2453 ;
2454 /* }}} */
2455 /* JavaScript FTW: Coalesce Operator {{{ */
2456 ConditionalExpression
2457 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2458 ;
2459 /* }}} */
2460 /* JavaScript FTW: Named Arguments {{{ */
2461 ArgumentList
2462 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2463 ;
2464 /* }}} */
2465 /* JavaScript FTW: Ruby Blocks {{{ */
2466 RubyProcParameterList_
2467 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2468 | { $$ = NULL; }
2469 ;
2470
2471 RubyProcParameterList
2472 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2473 | LexOf { $$ = NULL; }
2474 ;
2475
2476 RubyProcParameters
2477 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2478 | "||" { $$ = NULL; }
2479 ;
2480
2481 RubyProcParametersOpt
2482 : RubyProcParameters[pass] { $$ = $pass; }
2483 | { $$ = NULL; }
2484 ;
2485
2486 RubyProcExpression
2487 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2488 ;
2489
2490 PrimaryExpression
2491 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2492 ;
2493
2494 PostfixExpression
2495 : PostfixExpression[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2496 ;
2497 /* }}} */
2498
2499 %%
2500
2501 bool CYDriver::Parse(CYMark mark) {
2502 mark_ = mark;
2503 CYLocal<CYPool> local(&pool_);
2504 cy::parser parser(*this);
2505 #ifdef YYDEBUG
2506 parser.set_debug_level(debug_);
2507 #endif
2508 return parser.parse() != 0;
2509 }
2510
2511 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2512 if (!strict_)
2513 return;
2514
2515 CYDriver::Error error;
2516 error.warning_ = true;
2517 error.location_ = location;
2518 error.message_ = message;
2519 errors_.push_back(error);
2520 }
2521
2522 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2523 CYDriver::Error error;
2524 error.warning_ = false;
2525 error.location_ = location;
2526 error.message_ = message;
2527 driver.errors_.push_back(error);
2528 }