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