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