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