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