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