]> git.saurik.com Git - cycript.git/blob - Parser.ypp.in
Remove LexSetRegExp now that it is no longer used.
[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 <statement_> Declaration
520 %type <clause_> DefaultClause
521 %type <element_> ElementList
522 %type <element_> ElementListOpt
523 %type <statement_> ElseStatementOpt
524 %type <for_> EmptyStatement
525 %type <expression_> EqualityExpression
526 %type <expression_> Expression
527 %type <expression_> ExpressionOpt
528 %type <for_> ExpressionStatement_
529 %type <statement_> ExpressionStatement
530 %type <finally_> Finally
531 %type <binding_> ForBinding
532 %type <forin_> ForDeclaration
533 %type <forin_> ForInStatementInitializer
534 %type <for_> ForStatementInitializer
535 %type <binding_> FormalParameter
536 %type <functionParameter_> FormalParameterList_
537 %type <functionParameter_> FormalParameterList
538 %type <functionParameter_> FormalParameters
539 %type <statement_> FunctionBody
540 %type <statement_> FunctionDeclaration
541 %type <target_> FunctionExpression
542 %type <statement_> FunctionStatementList
543 %type <statement_> GeneratorBody
544 %type <statement_> GeneratorDeclaration
545 %type <target_> GeneratorExpression
546 %type <method_> GeneratorMethod
547 %type <statement_> HoistableDeclaration
548 %type <identifier_> Identifier
549 %type <identifier_> IdentifierNoOf
550 %type <identifier_> IdentifierType
551 %type <identifier_> IdentifierTypeNoOf
552 %type <word_> IdentifierName
553 %type <variable_> IdentifierReference
554 %type <statement_> IfStatement
555 %type <target_> IndirectExpression
556 %type <expression_> Initializer
557 %type <expression_> InitializerOpt
558 %type <statement_> IterationStatement
559 %type <identifier_> LabelIdentifier
560 %type <statement_> LabelledItem
561 %type <statement_> LabelledStatement
562 %type <assignment_> LeftHandSideAssignment
563 %type <target_> LeftHandSideExpression
564 %type <bool_> LetOrConst
565 %type <binding_> LexicalBinding
566 %type <for_> LexicalDeclaration_
567 %type <statement_> LexicalDeclaration
568 %type <literal_> Literal
569 %type <propertyName_> LiteralPropertyName
570 %type <expression_> LogicalANDExpression
571 %type <expression_> LogicalORExpression
572 %type <access_> MemberAccess
573 %type <target_> MemberExpression
574 %type <method_> MethodDefinition
575 %type <module_> ModulePath
576 %type <expression_> MultiplicativeExpression
577 %type <target_> NewExpression
578 %type <null_> NullLiteral
579 %type <literal_> ObjectLiteral
580 %type <expression_> PostfixExpression
581 %type <target_> PrimaryExpression
582 %type <propertyName_> PropertyName
583 %type <property_> PropertyDefinition
584 %type <property_> PropertyDefinitionList_
585 %type <property_> PropertyDefinitionList
586 %type <property_> PropertyDefinitionListOpt
587 %type <functionParameter_> PropertySetParameterList
588 %type <literal_> RegularExpressionLiteral
589 %type <bool_> RegularExpressionSlash
590 %type <expression_> RelationalExpression
591 %type <statement_> ReturnStatement
592 %type <rubyProc_> RubyProcExpression
593 %type <functionParameter_> RubyProcParameterList_
594 %type <functionParameter_> RubyProcParameterList
595 %type <functionParameter_> RubyProcParameters
596 %type <functionParameter_> RubyProcParametersOpt
597 %type <statement_> Script
598 %type <statement_> ScriptBody
599 %type <statement_> ScriptBodyOpt
600 %type <expression_> ShiftExpression
601 %type <binding_> SingleNameBinding
602 %type <statement_> Statement__
603 %type <statement_> Statement_
604 %type <statement_> Statement
605 %type <statement_> StatementList
606 %type <statement_> StatementListOpt
607 %type <statement_> StatementListItem
608 %type <functionParameter_> StrictFormalParameters
609 %type <target_> SuperCall
610 %type <target_> SuperProperty
611 %type <statement_> SwitchStatement
612 %type <target_> TemplateLiteral
613 %type <span_> TemplateSpans
614 %type <statement_> ThrowStatement
615 %type <statement_> TryStatement
616 %type <expression_> UnaryExpression_
617 %type <expression_> UnaryExpression
618 %type <binding_> VariableDeclaration
619 %type <bindings_> VariableDeclarationList_
620 %type <bindings_> VariableDeclarationList
621 %type <for_> VariableStatement_
622 %type <statement_> VariableStatement
623 %type <statement_> WithStatement
624 %type <word_> Word
625 @begin ObjectiveC
626 %type <word_> WordOpt
627 @end
628 %type <expression_> YieldExpression
629
630 @begin C
631 %type <specifier_> IntegerType
632 %type <specifier_> IntegerTypeOpt
633 %type <typedIdentifier_> PrefixedType
634 %type <specifier_> PrimitiveType
635 %type <typedIdentifier_> SuffixedType
636 %type <typedIdentifier_> TypeSignifier
637 %type <modifier_> TypeQualifierLeft
638 %type <typedIdentifier_> TypeQualifierRight
639 %type <typedIdentifier_> TypedIdentifier
640 %type <typedParameter_> TypedParameterList_
641 %type <typedParameter_> TypedParameterList
642 %type <typedParameter_> TypedParameterListOpt
643 @end
644
645 @begin ObjectiveC
646 %type <expression_> AssignmentExpressionClassic
647 %type <expression_> BoxableExpression
648 %type <statement_> CategoryStatement
649 %type <expression_> ClassSuperOpt
650 %type <expression_> ConditionalExpressionClassic
651 %type <implementationField_> ImplementationFieldListOpt
652 %type <implementationField_> ImplementationFields
653 %type <message_> ClassMessageDeclaration
654 %type <message_> ClassMessageDeclarationListOpt
655 %type <protocol_> ClassProtocolListOpt
656 %type <protocol_> ClassProtocols
657 %type <protocol_> ClassProtocolsOpt
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 LexNewLine
730 : { CYMPT(@$); driver.next_ = true; }
731 ;
732
733 LexNoStar
734 : { CYMAP(YieldStar, Star); }
735 ;
736
737 LexNoBrace
738 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
739 ;
740
741 LexNoClass
742 : { CYMAP(_class__, _class_); }
743 ;
744
745 LexNoFunction
746 : { CYMAP(_function__, _function_); }
747 ;
748
749 LexSetStatement
750 : LexNoBrace LexNoClass LexNoFunction
751 ;
752 /* }}} */
753 /* Virtual Tokens {{{ */
754 BRACE
755 : "{"
756 | "\n{"
757 ;
758
759 Var_
760 : "var"
761 ;
762 /* }}} */
763
764 /* 11.6 Names and Keywords {{{ */
765 IdentifierName
766 : Word[pass] { $$ = $pass; }
767 | "for" { $$ = CYNew CYWord("for"); }
768 | "in" { $$ = CYNew CYWord("in"); }
769 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
770 ;
771
772 NewLineOpt
773 : "\n"
774 |
775 ;
776
777 Word
778 : IdentifierNoOf[pass] { $$ = $pass; }
779 | "auto" { $$ = CYNew CYWord("auto"); }
780 | "break" { $$ = CYNew CYWord("break"); }
781 | "case" { $$ = CYNew CYWord("case"); }
782 | "catch" { $$ = CYNew CYWord("catch"); }
783 | "class" LexOf { $$ = CYNew CYWord("class"); }
784 | ";class" { $$ = CYNew CYWord("class"); }
785 | "const" { $$ = CYNew CYWord("const"); }
786 | "continue" { $$ = CYNew CYWord("continue"); }
787 | "debugger" { $$ = CYNew CYWord("debugger"); }
788 | "default" { $$ = CYNew CYWord("default"); }
789 | "delete" { $$ = CYNew CYWord("delete"); }
790 | "do" { $$ = CYNew CYWord("do"); }
791 | "else" { $$ = CYNew CYWord("else"); }
792 | "enum" { $$ = CYNew CYWord("enum"); }
793 | "export" { $$ = CYNew CYWord("export"); }
794 | "extends" { $$ = CYNew CYWord("extends"); }
795 | "false" { $$ = CYNew CYWord("false"); }
796 | "finally" { $$ = CYNew CYWord("finally"); }
797 | "function" LexOf { $$ = CYNew CYWord("function"); }
798 | "if" { $$ = CYNew CYWord("if"); }
799 | "import" { $$ = CYNew CYWord("import"); }
800 | "!in" { $$ = CYNew CYWord("in"); }
801 | "!of" { $$ = CYNew CYWord("of"); }
802 | "new" { $$ = CYNew CYWord("new"); }
803 | "null" { $$ = CYNew CYWord("null"); }
804 | "return" { $$ = CYNew CYWord("return"); }
805 | "super" { $$ = CYNew CYWord("super"); }
806 | "switch" { $$ = CYNew CYWord("switch"); }
807 | "this" { $$ = CYNew CYWord("this"); }
808 | "throw" { $$ = CYNew CYWord("throw"); }
809 | "true" { $$ = CYNew CYWord("true"); }
810 | "try" { $$ = CYNew CYWord("try"); }
811 | "typeof" { $$ = CYNew CYWord("typeof"); }
812 | "var" { $$ = CYNew CYWord("var"); }
813 | "void" { $$ = CYNew CYWord("void"); }
814 | "while" { $$ = CYNew CYWord("while"); }
815 | "with" { $$ = CYNew CYWord("with"); }
816 | "yield" { $$ = CYNew CYIdentifier("yield"); }
817
818 | Yield NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
819 ;
820
821 @begin ObjectiveC
822 WordOpt
823 : Word[pass] { $$ = $pass; }
824 | { $$ = NULL; }
825 ;
826 @end
827 /* }}} */
828 /* 11.8.1 Null Literals {{{ */
829 NullLiteral
830 : "null" { $$ = CYNew CYNull(); }
831 ;
832 /* }}} */
833 /* 11.8.2 Boolean Literals {{{ */
834 BooleanLiteral
835 : "true" { $$ = CYNew CYTrue(); }
836 | "false" { $$ = CYNew CYFalse(); }
837 ;
838 /* }}} */
839 /* 11.8.5 Regular Expression Literals {{{ */
840 RegularExpressionSlash
841 : "/" { $$ = false; }
842 | "/=" { $$ = true; }
843 ;
844
845 RegularExpressionLiteral
846 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
847 ;
848 /* }}} */
849
850 /* 11.9 Automatic Semicolon Insertion {{{ */
851 StrictSemi
852 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
853 ;
854
855 TerminatorSoft
856 : ";"
857 | "\n" StrictSemi
858 ;
859
860 Terminator
861 : ";"
862 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) 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 : IdentifierNoOf[pass] { $$ = $pass; }
879 | "!of" { $$ = CYNew CYIdentifier("of"); }
880 | "yield" { $$ = CYNew CYIdentifier("yield"); }
881 ;
882
883 BindingIdentifierOpt
884 : BindingIdentifier[pass] { $$ = $pass; }
885 | { $$ = 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 { $$ = CYNew CYIdentifier("let"); }
913 | "native" { $$ = CYNew CYIdentifier("native"); }
914 | "package" { $$ = CYNew CYIdentifier("package"); }
915 | "private" { $$ = CYNew CYIdentifier("private"); }
916 | "protected" { $$ = CYNew CYIdentifier("protected"); }
917 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
918 | "public" { $$ = CYNew CYIdentifier("public"); }
919 | "set" { $$ = CYNew CYIdentifier("set"); }
920 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
921 | "target" { $$ = CYNew CYIdentifier("target"); }
922 | "throws" { $$ = CYNew CYIdentifier("throws"); }
923 | "transient" { $$ = CYNew CYIdentifier("transient"); }
924 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
925 @begin ObjectiveC
926 | "bool" { $$ = CYNew CYIdentifier("bool"); }
927 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
928 | "id" { $$ = CYNew CYIdentifier("id"); }
929 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
930 @end
931 ;
932
933 IdentifierType
934 : IdentifierTypeNoOf[pass] { $$ = $pass; }
935 | "of" { $$ = CYNew CYIdentifier("of"); }
936 ;
937
938 IdentifierNoOf
939 : IdentifierTypeNoOf
940 | "char" { $$ = CYNew CYIdentifier("char"); }
941 | "int" { $$ = CYNew CYIdentifier("int"); }
942 | "long" { $$ = CYNew CYIdentifier("long"); }
943 | "short" { $$ = CYNew CYIdentifier("short"); }
944 | "static" { $$ = CYNew CYIdentifier("static"); }
945 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
946 @begin C
947 | "extern" { $$ = CYNew CYIdentifier("extern"); }
948 | "signed" { $$ = CYNew CYIdentifier("signed"); }
949 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
950 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
951 @end
952 @begin ObjectiveC
953 | "nil" { $$ = CYNew CYIdentifier("nil"); }
954 | "NO" { $$ = CYNew CYIdentifier("NO"); }
955 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
956 | "YES" { $$ = CYNew CYIdentifier("YES"); }
957 @end
958 ;
959
960 Identifier
961 : IdentifierNoOf[pass] { $$ = $pass; }
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 | "(" ")" { $$ = NULL; }
984 | "(" "..." BindingIdentifier ")" { CYNOT(@$); }
985 | "(" Expression "," "..." 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 | "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1004 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1005 ;
1006
1007 ElementListOpt
1008 : ElementList[pass] { $$ = $pass; }
1009 | { $$ = 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 | "..." AssignmentExpression { CYNOT(@$); }
1139 ;
1140
1141 ArgumentListOpt
1142 : ArgumentList[pass] { $$ = $pass; }
1143 | { $$ = 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 : ConditionalExpressionClassic[pass] { $$ = $pass; }
1289 | LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1290 ;
1291 @end
1292
1293 AssignmentExpression
1294 : ConditionalExpression[pass] { $$ = $pass; }
1295 | YieldExpression[pass] { $$ = $pass; }
1296 | ArrowFunction[pass] { $$ = $pass; }
1297 | LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1298 ;
1299
1300 AssignmentExpressionOpt
1301 : AssignmentExpression[pass] { $$ = $pass; }
1302 | { $$ = 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 | { $$ = 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 : 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 : LexLet Declaration__[pass] { $$ = $pass; }
1350 | LexicalDeclaration[pass] { $$ = $pass; }
1351 ;
1352
1353 Declaration
1354 : LexSetStatement Declaration_[pass] { $$ = $pass; }
1355 ;
1356
1357 HoistableDeclaration
1358 : FunctionDeclaration[pass] { $$ = $pass; }
1359 | GeneratorDeclaration[pass] { $$ = $pass; }
1360 ;
1361
1362 BreakableStatement
1363 : IterationStatement[pass] { $$ = $pass; }
1364 | SwitchStatement[pass] { $$ = $pass; }
1365 ;
1366 /* }}} */
1367 /* 13.2 Block {{{ */
1368 BlockStatement
1369 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1370 ;
1371
1372 Block
1373 : BRACE StatementListOpt[code] "}" { $$ = $code; }
1374 ;
1375
1376 StatementList
1377 : StatementListItem[statement] StatementListOpt[next] { $statement->SetNext($next); $$ = $statement; }
1378 ;
1379
1380 StatementListOpt
1381 : StatementList[pass] { $$ = $pass; }
1382 | LexSetStatement LexLet { $$ = NULL; }
1383 ;
1384
1385 StatementListItem
1386 : Statement[pass] { $$ = $pass; }
1387 | Declaration[pass] { $$ = $pass; }
1388 ;
1389 /* }}} */
1390 /* 13.3 Let and Const Declarations {{{ */
1391 LexicalDeclaration_
1392 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1393 ;
1394
1395 LexicalDeclaration
1396 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1397 ;
1398
1399 LexLet
1400 : { CYMAP(_let__, _let_); }
1401 ;
1402
1403 LexOf
1404 : { CYMAP(_of__, _of_); }
1405 ;
1406
1407 LexBind
1408 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } LexOf
1409 ;
1410
1411 LetOrConst
1412 : LexLet "!let" LexBind { $$ = false; }
1413 | LexLet "const" { $$ = true; }
1414 ;
1415
1416 BindingList_
1417 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1418 | { $$ = NULL; }
1419 ;
1420
1421 BindingList
1422 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1423 ;
1424
1425 LexicalBinding
1426 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1427 | BindingPattern Initializer { CYNOT(@$); }
1428 ;
1429 /* }}} */
1430 /* 13.3.2 Variable Statement {{{ */
1431 VariableStatement_
1432 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1433 ;
1434
1435 VariableStatement
1436 : VariableStatement_[statement] Terminator { $$ = $statement; }
1437 ;
1438
1439 VariableDeclarationList_
1440 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1441 | { $$ = NULL; }
1442 ;
1443
1444 VariableDeclarationList
1445 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1446 ;
1447
1448 VariableDeclaration
1449 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1450 | BindingPattern Initializer { CYNOT(@$); }
1451 ;
1452 /* }}} */
1453 /* 13.3.3 Destructuring Binding Patterns {{{ */
1454 BindingPattern
1455 : ObjectBindingPattern
1456 | ArrayBindingPattern
1457 ;
1458
1459 ObjectBindingPattern
1460 : "let {" BindingPropertyListOpt "}"
1461 ;
1462
1463 ArrayBindingPattern
1464 : "let [" { CYNOT(@$); }
1465 ;
1466
1467 BindingPropertyList_
1468 : "," BindingPropertyListOpt
1469 |
1470 ;
1471
1472 BindingPropertyList
1473 : BindingProperty BindingPropertyList_
1474 ;
1475
1476 BindingPropertyListOpt
1477 : BindingPropertyList
1478 |
1479 ;
1480
1481 BindingProperty
1482 : SingleNameBinding
1483 | PropertyName ":" BindingElement
1484 ;
1485
1486 BindingElement
1487 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1488 | LexBind BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1489 ;
1490
1491 SingleNameBinding
1492 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1493 ;
1494
1495 BindingRestElement
1496 : "..." BindingIdentifier
1497 ;
1498 /* }}} */
1499 /* 13.4 Empty Statement {{{ */
1500 EmptyStatement
1501 : ";" { $$ = CYNew CYEmpty(); }
1502 ;
1503 /* }}} */
1504 /* 13.5 Expression Statement {{{ */
1505 ExpressionStatement_
1506 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1507
1508 ExpressionStatement
1509 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1510 ;
1511 /* }}} */
1512 /* 13.6 The if Statement {{{ */
1513 ElseStatementOpt
1514 : "else" Statement[false] { $$ = $false; }
1515 | %prec "if" { $$ = NULL; }
1516 ;
1517
1518 IfStatement
1519 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1520 ;
1521 /* }}} */
1522 /* 13.7 Iteration Statements {{{ */
1523 IterationStatement
1524 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1525 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1526 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1527 | "for" "(" LexPushInOn LexLet Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1528 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1529 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1530 ;
1531
1532 ForStatementInitializer
1533 : LexLet EmptyStatement[pass] { $$ = $pass; }
1534 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1535 | LexLet VariableStatement_[initializer] ";" { $$ = $initializer; }
1536 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1537 ;
1538
1539 ForInStatementInitializer
1540 : LexLet AccessExpression[pass] LexCrement { $$ = $pass; }
1541 | LexLet IndirectExpression[pass] { $$ = $pass; }
1542 | LexLet Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1543 | ForDeclaration[pass] { $$ = $pass; }
1544 ;
1545
1546 ForDeclaration
1547 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1548 ;
1549
1550 ForBinding
1551 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1552 | BindingPattern { CYNOT(@$); }
1553 ;
1554 /* }}} */
1555 /* 13.8 The continue Statement {{{ */
1556 Continue
1557 : "continue" LexNewLine
1558 ;
1559
1560 ContinueStatement
1561 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1562 | Continue Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1563 ;
1564 /* }}} */
1565 /* 13.9 The break Statement {{{ */
1566 Break
1567 : "break" LexNewLine
1568 ;
1569
1570 BreakStatement
1571 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1572 | Break Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1573 ;
1574 /* }}} */
1575 /* 13.10 The return Statement {{{ */
1576 Return
1577 : "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); } LexNewLine
1578 ;
1579
1580 ReturnStatement
1581 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1582 | Return Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1583 ;
1584 /* }}} */
1585 /* 13.11 The with Statement {{{ */
1586 WithStatement
1587 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1588 ;
1589 /* }}} */
1590 /* 13.12 The switch Statement {{{ */
1591 SwitchStatement
1592 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1593 ;
1594
1595 CaseBlock
1596 : BRACE CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1597 ;
1598
1599 CaseClause
1600 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1601 ;
1602
1603 CaseClausesOpt
1604 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1605 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1606 | { $$ = NULL; }
1607 ;
1608
1609 // XXX: the standard makes certain you can only have one of these
1610 DefaultClause
1611 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1612 ;
1613 /* }}} */
1614 /* 13.13 Labelled Statements {{{ */
1615 LabelledStatement
1616 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1617 ;
1618
1619 LabelledItem
1620 : Statement[pass] { $$ = $pass; }
1621 | LexSetStatement LexLet FunctionDeclaration[pass] { $$ = $pass; }
1622 ;
1623 /* }}} */
1624 /* 13.14 The throw Statement {{{ */
1625 Throw
1626 : "throw" LexNewLine
1627 ;
1628
1629 ThrowStatement
1630 : Throw[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1631 | Throw Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1632 ;
1633 /* }}} */
1634 /* 13.15 The try Statement {{{ */
1635 TryStatement
1636 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1637 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1638 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1639 ;
1640
1641 Catch
1642 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1643 ;
1644
1645 Finally
1646 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1647 ;
1648
1649 CatchParameter
1650 : BindingIdentifier[pass] { $$ = $pass; }
1651 | BindingPattern { CYNOT(@$); }
1652 ;
1653 /* }}} */
1654 /* 13.16 The debugger Statement {{{ */
1655 DebuggerStatement
1656 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1657 ;
1658 /* }}} */
1659
1660 /* 14.1 Function Definitions {{{ */
1661 FunctionDeclaration
1662 : ";function" LexOf BindingIdentifier[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1663 ;
1664
1665 FunctionExpression
1666 : "function" LexOf BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1667 ;
1668
1669 StrictFormalParameters
1670 : FormalParameters[pass] { $$ = $pass; }
1671 ;
1672
1673 FormalParameters
1674 : LexBind { $$ = NULL; }
1675 | FormalParameterList
1676 ;
1677
1678 FormalParameterList_
1679 : "," FormalParameterList[parameters] { $$ = $parameters; }
1680 | { $$ = NULL; }
1681 ;
1682
1683 FormalParameterList
1684 : LexBind FunctionRestParameter { CYNOT(@$); }
1685 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1686 ;
1687
1688 FunctionRestParameter
1689 : BindingRestElement
1690 ;
1691
1692 FormalParameter
1693 : BindingElement[pass] { $$ = $pass; }
1694 ;
1695
1696 FunctionBody
1697 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1698 ;
1699
1700 FunctionStatementList
1701 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1702 ;
1703 /* }}} */
1704 /* 14.2 Arrow Function Definitions {{{ */
1705 LexEqualRight
1706 : { CYLIN(EqualRight); }
1707 ;
1708
1709 ArrowFunction
1710 : ArrowParameters[parameters] LexEqualRight "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1711 ;
1712
1713 ArrowParameters
1714 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1715 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1716 ;
1717
1718 ConciseBody
1719 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1720 | ";{" FunctionBody[code] "}" { $$ = $code; }
1721 ;
1722 /* }}} */
1723 /* 14.3 Method Definitions {{{ */
1724 MethodDefinition
1725 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1726 | GeneratorMethod[pass] { $$ = $pass; }
1727 | "get" PropertyName[name] "(" ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1728 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" BRACE FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1729 ;
1730
1731 PropertySetParameterList
1732 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1733 ;
1734 /* }}} */
1735 /* 14.4 Generator Function Definitions {{{ */
1736 GeneratorMethod
1737 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1738 ;
1739
1740 GeneratorDeclaration
1741 : ";function" LexOf "*" LexOf BindingIdentifier[name] "(" FormalParameters[code] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1742 ;
1743
1744 GeneratorExpression
1745 : "function" LexOf "*" LexOf BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" BRACE GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1746 ;
1747
1748 GeneratorBody
1749 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1750 ;
1751
1752 Yield
1753 : "!yield" LexNewLine LexNoStar
1754 ;
1755
1756 YieldExpression
1757 : Yield NewLineOpt { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1758 | Yield AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1759 | Yield YieldStar AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1760 ;
1761 /* }}} */
1762 /* 14.5 Class Definitions {{{ */
1763 ClassDeclaration
1764 : ";class" LexOf BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1765 ;
1766
1767 ClassExpression
1768 : "class" LexOf BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1769 ;
1770
1771 ClassTail
1772 : ClassHeritageOpt[tail] { driver.class_.push($tail); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1773 ;
1774
1775 ClassHeritage
1776 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1777 ;
1778
1779 ClassHeritageOpt
1780 : ClassHeritage[pass] { $$ = $pass; }
1781 | { $$ = CYNew CYClassTail(NULL); }
1782 ;
1783
1784 ClassBody
1785 : ClassElementList
1786 ;
1787
1788 ClassBodyOpt
1789 : ClassBody
1790 |
1791 ;
1792
1793 ClassElementList
1794 : ClassElementListOpt ClassElement
1795 ;
1796
1797 ClassElementListOpt
1798 : ClassElementList
1799 |
1800 ;
1801
1802 ClassElement
1803 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1804 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1805 | ";"
1806 ;
1807 /* }}} */
1808
1809 /* 15.1 Scripts {{{ */
1810 Script
1811 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1812 ;
1813
1814 ScriptBody
1815 : StatementList[pass] { $$ = $pass; }
1816 ;
1817
1818 ScriptBodyOpt
1819 : ScriptBody[pass] { $$ = $pass; }
1820 | LexSetStatement LexLet { $$ = NULL; }
1821 ;
1822 /* }}} */
1823 /* 15.2 Modules {{{ */
1824 Module
1825 : ModuleBodyOpt
1826 ;
1827
1828 ModuleBody
1829 : ModuleItemList
1830 ;
1831
1832 ModuleBodyOpt
1833 : ModuleBody
1834 |
1835 ;
1836
1837 ModuleItemList
1838 : ModuleItemListOpt ModuleItem
1839 ;
1840
1841 ModuleItemListOpt
1842 : ModuleItemList
1843 |
1844 ;
1845
1846 ModuleItem
1847 : LexSetStatement LexLet ImportDeclaration
1848 | LexSetStatement LexLet ExportDeclaration
1849 | StatementListItem
1850 ;
1851 /* }}} */
1852 /* 15.2.2 Imports {{{ */
1853 ImportDeclaration
1854 : "import" ImportClause FromClause Terminator
1855 | "import" ModuleSpecifier Terminator
1856 ;
1857
1858 ImportClause
1859 : ImportedDefaultBinding
1860 | NameSpaceImport
1861 | NamedImports
1862 | ImportedDefaultBinding "," NameSpaceImport
1863 | ImportedDefaultBinding "," NamedImports
1864 ;
1865
1866 ImportedDefaultBinding
1867 : ImportedBinding
1868 ;
1869
1870 NameSpaceImport
1871 : "*" "as" ImportedBinding
1872 ;
1873
1874 NamedImports
1875 : BRACE ImportsListOpt "}"
1876 ;
1877
1878 FromClause
1879 : "from" ModuleSpecifier
1880 ;
1881
1882 ImportsList_
1883 : "," ImportsListOpt
1884 |
1885 ;
1886
1887 ImportsList
1888 : ImportSpecifier ImportsList_
1889 ;
1890
1891 ImportsListOpt
1892 : ImportsList
1893 |
1894 ;
1895
1896 ImportSpecifier
1897 : ImportedBinding
1898 | IdentifierName "as" ImportedBinding
1899 ;
1900
1901 ModuleSpecifier
1902 : StringLiteral
1903 ;
1904
1905 ImportedBinding
1906 : BindingIdentifier
1907 ;
1908 /* }}} */
1909 /* 15.2.3 Exports {{{ */
1910 ExportDeclaration_
1911 : "*" FromClause Terminator
1912 | ExportClause FromClause Terminator
1913 | ExportClause Terminator
1914 | VariableStatement
1915 | "default" LexSetStatement HoistableDeclaration
1916 | "default" LexSetStatement ClassDeclaration
1917 | "default" LexSetStatement AssignmentExpression Terminator
1918 ;
1919
1920 ExportDeclaration
1921 : "export" LexSetStatement LexLet ExportDeclaration_
1922 | "export" Declaration
1923 ;
1924
1925 ExportClause
1926 : ";{" ExportsListOpt "}"
1927 ;
1928
1929 ExportsList_
1930 : "," ExportsListOpt
1931 |
1932 ;
1933
1934 ExportsList
1935 : ExportSpecifier ExportsList_
1936 ;
1937
1938 ExportsListOpt
1939 : ExportsList
1940 |
1941 ;
1942
1943 ExportSpecifier
1944 : IdentifierName
1945 | IdentifierName "as" IdentifierName
1946 ;
1947 /* }}} */
1948
1949 @begin C
1950 /* Cycript (C): Type Encoding {{{ */
1951 TypeSignifier
1952 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1953 | "(" "*" TypeQualifierRight[typed] ")" { $$ = $typed; }
1954 ;
1955
1956 SuffixedType
1957 : SuffixedType[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1958 | "(" "^" TypeQualifierRight[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1959 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1960 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1961 | TypeSignifier[pass] { $$ = $pass; }
1962 | { $$ = CYNew CYTypedIdentifier(@$); }
1963 ;
1964
1965 PrefixedType
1966 : "*" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1967 ;
1968
1969 TypeQualifierLeft
1970 : { $$ = NULL; }
1971 | "const" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1972 | "volatile" TypeQualifierLeft[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1973 ;
1974
1975 TypeQualifierRight
1976 : PrefixedType[pass] { $$ = $pass; }
1977 | SuffixedType[pass] { $$ = $pass; }
1978 | "const" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1979 | "volatile" TypeQualifierRight[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1980 ;
1981
1982 IntegerType
1983 : "int" { $$ = CYNew CYTypeVariable("int"); }
1984 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
1985 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
1986 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
1987 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
1988 ;
1989
1990 IntegerTypeOpt
1991 : IntegerType[pass] { $$ = $pass; }
1992 | { $$ = CYNew CYTypeVariable("int"); }
1993 ;
1994
1995 PrimitiveType
1996 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
1997 | IntegerType[pass] { $$ = $pass; }
1998 | "void" { $$ = CYNew CYTypeVoid(); }
1999 | "char" { $$ = CYNew CYTypeVariable("char"); }
2000 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
2001 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2002 ;
2003
2004 TypedIdentifier
2005 : TypeQualifierLeft[modifier] PrimitiveType[specifier] TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2006 ;
2007
2008 PrimaryExpression
2009 : "@encode" "(" TypedIdentifier[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2010 ;
2011 /* }}} */
2012 @end
2013
2014 @begin ObjectiveC
2015 /* Cycript (Objective-C): @class Declaration {{{ */
2016 ClassSuperOpt
2017 /* XXX: why the hell did I choose MemberExpression? */
2018 : ":" MemberExpression[extends] { $$ = $extends; }
2019 | { $$ = NULL; }
2020 ;
2021
2022 ImplementationFieldListOpt
2023 : TypedIdentifier[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2024 | { $$ = NULL; }
2025 ;
2026
2027 ImplementationFields
2028 : BRACE ImplementationFieldListOpt[fields] "}" { $$ = $fields; }
2029 ;
2030
2031 MessageScope
2032 : "+" { $$ = false; }
2033 | "-" { $$ = true; }
2034 ;
2035
2036 TypeOpt
2037 : "(" TypedIdentifier[type] ")" { if ($type->identifier_ != NULL) CYERR($type->location_, "unexpected identifier"); $$ = $type; }
2038 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2039 ;
2040
2041 MessageParameter
2042 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2043 ;
2044
2045 MessageParameterList
2046 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2047 ;
2048
2049 MessageParameterListOpt
2050 : MessageParameterList[pass] { $$ = $pass; }
2051 | { $$ = NULL; }
2052 ;
2053
2054 MessageParameters
2055 : MessageParameterList[pass] { $$ = $pass; }
2056 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2057 ;
2058
2059 ClassMessageDeclaration
2060 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] BRACE LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2061 ;
2062
2063 ClassMessageDeclarationListOpt
2064 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2065 | { $$ = NULL; }
2066 ;
2067
2068 // XXX: this should be AssignmentExpressionNoRight
2069 ClassProtocols
2070 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2071 ;
2072
2073 ClassProtocolsOpt
2074 : "," ClassProtocols[protocols] { $$ = $protocols; }
2075 | { $$ = NULL; }
2076 ;
2077
2078 ClassProtocolListOpt
2079 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2080 | { $$ = NULL; }
2081 ;
2082
2083 ImplementationStatement
2084 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] ImplementationFields[fields] ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2085 ;
2086
2087 CategoryName
2088 : "(" WordOpt ")"
2089 ;
2090
2091 CategoryStatement
2092 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2093 ;
2094
2095 Statement__
2096 : ImplementationStatement[pass] { $$ = $pass; }
2097 | CategoryStatement[pass] { $$ = $pass; }
2098 ;
2099 /* }}} */
2100 /* Cycript (Objective-C): Send Message {{{ */
2101 VariadicCall
2102 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2103 | { $$ = NULL; }
2104 ;
2105
2106 SelectorWordOpt
2107 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2108 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2109 ;
2110
2111 SelectorCall_
2112 : SelectorCall[pass] { $$ = $pass; }
2113 | VariadicCall[pass] { $$ = $pass; }
2114 ;
2115
2116 SelectorCall
2117 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2118 ;
2119
2120 SelectorList
2121 : SelectorCall[pass] { $$ = $pass; }
2122 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2123 ;
2124
2125 MessageExpression
2126 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2127 | "[" "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2128 ;
2129
2130 SelectorExpression_
2131 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2132 ;
2133
2134 SelectorExpression
2135 : SelectorExpression_[pass] { $$ = $pass; }
2136 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2137 ;
2138
2139 SelectorExpressionOpt
2140 : SelectorExpression_[pass] { $$ = $pass; }
2141 | { $$ = NULL; }
2142 ;
2143
2144 PrimaryExpression
2145 : MessageExpression[pass] { $$ = $pass; }
2146 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2147 ;
2148 /* }}} */
2149 @end
2150
2151 /* Cycript: @import Directive {{{ */
2152 ModulePath
2153 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2154 | Word[part] { $$ = CYNew CYModule($part); }
2155 ;
2156
2157 Declaration__
2158 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2159 ;
2160 /* }}} */
2161
2162 @begin ObjectiveC
2163 /* Cycript (Objective-C): Boxed Expressions {{{ */
2164 BoxableExpression
2165 : NullLiteral[pass] { $$ = $pass; }
2166 | BooleanLiteral[pass] { $$ = $pass; }
2167 | NumericLiteral[pass] { $$ = $pass; }
2168 | StringLiteral[pass] { $$ = $pass; }
2169 | ArrayLiteral[pass] { $$ = $pass; }
2170 | ObjectLiteral[pass] { $$ = $pass; }
2171 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2172 | "YES" { $$ = CYNew CYTrue(); }
2173 | "NO" { $$ = CYNew CYFalse(); }
2174 ;
2175
2176 PrimaryExpression
2177 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2178 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2179 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2180 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2181 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2182 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2183 ;
2184 /* }}} */
2185 /* Cycript (Objective-C): Block Expressions {{{ */
2186 PrimaryExpression
2187 : "^" 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"); }
2188 ;
2189 /* }}} */
2190 /* Cycript (Objective-C): Instance Literals {{{ */
2191 PrimaryExpression
2192 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2193 ;
2194 /* }}} */
2195 @end
2196
2197 @begin C
2198 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2199 UnaryExpression_
2200 : IndirectExpression[pass] { $$ = $pass; }
2201 ;
2202
2203 IndirectExpression
2204 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2205 ;
2206
2207 UnaryExpression_
2208 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2209 ;
2210
2211 MemberAccess
2212 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2213 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2214 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2215 ;
2216 /* }}} */
2217 /* Cycript (C): auto Compatibility {{{ */
2218 Var_
2219 : "auto"
2220 ;
2221 /* }}} */
2222 /* Cycript (C): Lambda Expressions {{{ */
2223 TypedParameterList_
2224 : "," TypedParameterList[parameters] { $$ = $parameters; }
2225 | { $$ = NULL; }
2226 ;
2227
2228 TypedParameterList
2229 : TypedIdentifier[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2230 ;
2231
2232 TypedParameterListOpt
2233 : TypedParameterList[pass] { $$ = $pass; }
2234 | { $$ = NULL; }
2235 ;
2236
2237 PrimaryExpression
2238 : "[" "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifier[type] BRACE FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2239 ;
2240 /* }}} */
2241 /* Cycript (C): Type Definitions {{{ */
2242 Statement__
2243 : "typedef" TypedIdentifier[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($typed); }
2244 ;
2245 /* }}} */
2246 /* Cycript (C): extern "C" {{{ */
2247 Statement__
2248 : "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); }
2249 ;
2250 /* }}} */
2251
2252 @end
2253
2254 @begin E4X
2255 /* Lexer State {{{ */
2256 LexPushRegExp
2257 : { driver.PushCondition(CYDriver::RegExpCondition); }
2258 ;
2259
2260 LexPushXMLContent
2261 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2262 ;
2263
2264 LexPushXMLTag
2265 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2266 ;
2267
2268 LexPop
2269 : { driver.PopCondition(); }
2270 ;
2271
2272 LexSetXMLContent
2273 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2274 ;
2275
2276 LexSetXMLTag
2277 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2278 ;
2279 /* }}} */
2280 /* Virtual Tokens {{{ */
2281 XMLWhitespaceOpt
2282 : XMLWhitespace
2283 |
2284 ;
2285 /* }}} */
2286
2287 /* 8.1 Context Keywords {{{ */
2288 Identifier
2289 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2290 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2291 ;
2292 /* }}} */
2293 /* 8.3 XML Initializer Input Elements {{{ */
2294 XMLMarkup
2295 : XMLComment { $$ = $1; }
2296 | XMLCDATA { $$ = $1; }
2297 | XMLPI { $$ = $1; }
2298 ;
2299 /* }}} */
2300
2301 /* 11.1 Primary Expressions {{{ */
2302 PrimaryExpression
2303 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2304 | XMLInitilizer { $$ = $1; }
2305 | XMLListInitilizer { $$ = $1; }
2306 ;
2307
2308 PropertyIdentifier
2309 : AttributeIdentifier { $$ = $1; }
2310 | QualifiedIdentifier { $$ = $1; }
2311 | WildcardIdentifier { $$ = $1; }
2312 ;
2313 /* }}} */
2314 /* 11.1.1 Attribute Identifiers {{{ */
2315 AttributeIdentifier
2316 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2317 ;
2318
2319 PropertySelector_
2320 : PropertySelector { $$ = $1; }
2321 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2322 ;
2323
2324 PropertySelector
2325 : Identifier { $$ = CYNew CYSelector($1); }
2326 | WildcardIdentifier { $$ = $1; }
2327 ;
2328 /* }}} */
2329 /* 11.1.2 Qualified Identifiers {{{ */
2330 QualifiedIdentifier_
2331 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2332 | QualifiedIdentifier { $$ = $1; }
2333 ;
2334
2335 QualifiedIdentifier
2336 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2337 ;
2338 /* }}} */
2339 /* 11.1.3 Wildcard Identifiers {{{ */
2340 WildcardIdentifier
2341 : "*" { $$ = CYNew CYWildcard(); }
2342 ;
2343 /* }}} */
2344 /* 11.1.4 XML Initializer {{{ */
2345 XMLInitilizer
2346 : XMLMarkup { $$ = $1; }
2347 | XMLElement { $$ = $1; }
2348 ;
2349
2350 XMLElement
2351 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2352 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2353 ;
2354
2355 XMLTagContent
2356 : LexPushXMLTag XMLTagName XMLAttributes
2357 ;
2358
2359 XMLExpression
2360 : BRACE LexPushRegExp Expression LexPop "}"
2361 ;
2362
2363 XMLTagName
2364 : XMLExpression
2365 | XMLName
2366 ;
2367
2368 XMLAttributes_
2369 : XMLAttributes_ XMLAttribute
2370 |
2371 ;
2372
2373 XMLAttributes
2374 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2375 | XMLAttributes_ XMLWhitespaceOpt
2376 ;
2377
2378 XMLAttributeValue_
2379 : XMLExpression
2380 | XMLAttributeValue
2381 ;
2382
2383 XMLAttribute
2384 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2385 ;
2386
2387 XMLElementContent
2388 : XMLExpression XMLElementContentOpt
2389 | XMLMarkup XMLElementContentOpt
2390 | XMLText XMLElementContentOpt
2391 | XMLElement XMLElementContentOpt
2392 ;
2393
2394 XMLElementContentOpt
2395 : XMLElementContent
2396 |
2397 ;
2398 /* }}} */
2399 /* 11.1.5 XMLList Initializer {{{ */
2400 XMLListInitilizer
2401 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2402 ;
2403 /* }}} */
2404
2405 /* 11.2 Left-Hand-Side Expressions {{{ */
2406 PropertyIdentifier_
2407 : Identifier { $$ = $1; }
2408 | PropertyIdentifier { $$ = $1; }
2409 ;
2410
2411 MemberAccess
2412 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2413 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2414 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2415 ;
2416 /* }}} */
2417 /* 12.1 The default xml namespace Statement {{{ */
2418 /* XXX: DefaultXMLNamespaceStatement
2419 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2420 ;
2421
2422 Statement__
2423 : DefaultXMLNamespaceStatement { $$ = $1; }
2424 ; */
2425 /* }}} */
2426 @end
2427
2428 /* JavaScript FTL: Array Comprehensions {{{ */
2429 Comprehension
2430 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2431 ;
2432
2433 ComprehensionFor
2434 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2435 ;
2436 /* }}} */
2437 /* JavaScript FTL: for each {{{ */
2438 IterationStatement
2439 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2440 ;
2441 /* }}} */
2442
2443 /* JavaScript FTW: Array Comprehensions {{{ */
2444 PrimaryExpression
2445 : ArrayComprehension
2446 ;
2447
2448 ArrayComprehension
2449 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2450 ;
2451
2452 Comprehension
2453 : ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2454 ;
2455
2456 ComprehensionTail
2457 : { $$ = NULL; }
2458 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2459 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2460 ;
2461
2462 ComprehensionFor
2463 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2464 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2465 ;
2466
2467 ComprehensionIf
2468 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2469 ;
2470 /* }}} */
2471 /* JavaScript FTW: Coalesce Operator {{{ */
2472 ConditionalExpression
2473 : LogicalORExpression[test] "?" LexPushInOff ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2474 ;
2475 /* }}} */
2476 /* JavaScript FTW: Named Arguments {{{ */
2477 ArgumentList
2478 : Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2479 ;
2480 /* }}} */
2481 /* JavaScript FTW: Ruby Blocks {{{ */
2482 RubyProcParameterList_
2483 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2484 | { $$ = NULL; }
2485 ;
2486
2487 RubyProcParameterList
2488 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2489 | { $$ = NULL; }
2490 ;
2491
2492 RubyProcParameters
2493 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2494 | "||" { $$ = NULL; }
2495 ;
2496
2497 RubyProcParametersOpt
2498 : RubyProcParameters[pass] { $$ = $pass; }
2499 | { $$ = NULL; }
2500 ;
2501
2502 LexOpenBrace
2503 : { CYLIN(OpenBrace); }
2504 ;
2505
2506 RubyProcExpression
2507 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2508 ;
2509
2510 PrimaryExpression
2511 : BRACE RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2512 ;
2513
2514 PostfixExpression
2515 : PostfixExpression[lhs] LexOpenBrace RubyProcExpression[rhs] { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2516 ;
2517 /* }}} */
2518
2519 %%
2520
2521 bool CYDriver::Parse(CYMark mark) {
2522 mark_ = mark;
2523 CYLocal<CYPool> local(&pool_);
2524 cy::parser parser(*this);
2525 #ifdef YYDEBUG
2526 parser.set_debug_level(debug_);
2527 #endif
2528 return parser.parse() != 0;
2529 }
2530
2531 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2532 if (!strict_)
2533 return;
2534
2535 CYDriver::Error error;
2536 error.warning_ = true;
2537 error.location_ = location;
2538 error.message_ = message;
2539 errors_.push_back(error);
2540 }
2541
2542 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2543 CYDriver::Error error;
2544 error.warning_ = false;
2545 error.location_ = location;
2546 error.message_ = message;
2547 driver.errors_.push_back(error);
2548 }