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