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