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