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