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