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