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