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