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