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