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