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