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