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