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