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