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