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