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