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