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