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