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