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