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