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