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