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