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