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