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