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