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