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