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