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