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