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