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