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