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