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