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