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