]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
410730af0d411330e40caf52a4c43fd8b7ade770
[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 <expression_> Element
362 %type <expression_> ElementOpt
363 %type <element_> ElementList
364 %type <element_> ElementListOpt
365 %type <statement_> ElseStatementOpt
366 %type <statement_> EmptyStatement
367 %type <expression_> EqualityExpression
368 %type <compound_> Expression_
369 %type <compound_> Expression
370 %type <expression_> ExpressionOpt
371 %type <statement_> ExpressionStatement
372 %type <finally_> FinallyOpt
373 %type <comprehension_> ForComprehension
374 %type <for_> ForStatementInitialiser
375 %type <forin_> ForInStatementInitialiser
376 %type <declaration_> FormalParameter
377 %type <functionParameter_> FormalParameterList_
378 %type <functionParameter_> FormalParameterList
379 %type <functionParameter_> FormalParameterListOpt
380 %type <statement_> FunctionBody
381 %type <statement_> FunctionDeclaration
382 %type <expression_> FunctionExpression
383 %type <identifier_> Identifier
384 %type <identifier_> IdentifierOpt
385 %type <comprehension_> IfComprehension
386 %type <statement_> IfStatement
387 %type <expression_> Initialiser
388 %type <expression_> InitialiserOpt
389 %type <statement_> IterationStatement
390 %type <statement_> LabelledStatement
391 %type <expression_> LeftHandSideExpression
392 %type <statement_> LetStatement
393 %type <statement_> LexicalDeclaration
394 %type <literal_> Literal
395 %type <literal_> LiteralNoRE
396 %type <expression_> LogicalANDExpression
397 %type <expression_> LogicalORExpression
398 %type <member_> MemberAccess
399 %type <expression_> MemberExpression_
400 %type <expression_> MemberExpression
401 %type <expression_> MultiplicativeExpression
402 %type <expression_> NewExpression
403 %type <null_> NullLiteral
404 %type <literal_> ObjectLiteral
405 %type <compound_> Parenthetical
406 %type <compound_> ParentheticalOpt
407 %type <expression_> PostfixExpression
408 %type <expression_> PrimaryExpression
409 %type <statement_> Program
410 %type <statement_> ProgramBody
411 %type <statement_> ProgramBodyOpt
412 %type <propertyName_> PropertyName_
413 %type <propertyName_> PropertyName
414 %type <property_> PropertyNameAndValueList_
415 %type <property_> PropertyNameAndValueList
416 %type <property_> PropertyNameAndValueListOpt
417 %type <expression_> RelationalExpression
418 %type <statement_> ReturnStatement
419 %type <rubyProc_> RubyProcExpression
420 %type <functionParameter_> RubyProcParameterList_
421 %type <functionParameter_> RubyProcParameterList
422 %type <functionParameter_> RubyProcParameters
423 %type <functionParameter_> RubyProcParametersOpt
424 %type <expression_> ShiftExpression
425 %type <declaration_> SingleNameBinding
426 %type <statement_> Statement__
427 %type <statement_> Statement_
428 %type <statement_> Statement
429 %type <statement_> StatementList
430 %type <statement_> StatementListOpt
431 %type <statement_> StatementListItem
432 %type <statement_> SwitchStatement
433 %type <statement_> ThrowStatement
434 %type <statement_> TryStatement
435 %type <expression_> UnaryExpression_
436 %type <expression_> UnaryExpression
437 %type <declaration_> VariableDeclaration
438 %type <declarations_> VariableDeclarationList_
439 %type <declarations_> VariableDeclarationList
440 %type <statement_> VariableStatement
441 %type <statement_> WithStatement
442
443 @begin ObjectiveC
444 %type <statement_> CategoryStatement
445 %type <expression_> ClassExpression
446 %type <statement_> ClassStatement
447 %type <expression_> ClassSuperOpt
448 %type <field_> ClassFieldList
449 %type <message_> ClassMessageDeclaration
450 %type <message_> ClassMessageDeclarationListOpt
451 %type <className_> ClassName
452 %type <className_> ClassNameOpt
453 %type <protocol_> ClassProtocolListOpt
454 %type <protocol_> ClassProtocols
455 %type <protocol_> ClassProtocolsOpt
456 %type <expression_> MessageExpression
457 %type <messageParameter_> MessageParameter
458 %type <messageParameter_> MessageParameters
459 %type <messageParameter_> MessageParameterList
460 %type <messageParameter_> MessageParameterListOpt
461 %type <bool_> MessageScope
462 %type <argument_> SelectorCall_
463 %type <argument_> SelectorCall
464 %type <selector_> SelectorExpression_
465 %type <selector_> SelectorExpression
466 %type <selector_> SelectorExpressionOpt
467 %type <argument_> SelectorList
468 %type <word_> SelectorWordOpt
469 %type <expression_> TypeOpt
470 %type <argument_> VariadicCall
471 %type <word_> Word
472 %type <word_> WordOpt
473 @end
474
475 @begin E4X
476 %type <propertyIdentifier_> PropertyIdentifier_
477 %type <selector_> PropertySelector_
478 %type <selector_> PropertySelector
479 %type <identifier_> QualifiedIdentifier_
480 %type <identifier_> QualifiedIdentifier
481 %type <identifier_> WildcardIdentifier
482 %type <identifier_> XMLComment
483 %type <identifier_> XMLCDATA
484 %type <identifier_> XMLElement
485 %type <identifier_> XMLElementContent
486 %type <identifier_> XMLMarkup
487 %type <identifier_> XMLPI
488
489 %type <attribute_> AttributeIdentifier
490 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
491 %type <expression_> PropertyIdentifier
492 %type <expression_> XMLListInitialiser
493 %type <expression_> XMLInitialiser
494 @end
495
496 %nonassoc ""
497 %left "++" "--"
498
499 %nonassoc "if"
500 %nonassoc "else"
501
502 %start Program
503
504 %%
505
506 /* Lexer State {{{ */
507 LexPushInOn
508 : { driver.in_.push(true); }
509 ;
510
511 LexPushInOff
512 : { driver.in_.push(false); }
513 ;
514
515 LexPopIn
516 : { driver.in_.pop(); }
517 ;
518
519 LexSetRegExp
520 : { driver.SetCondition(CYDriver::RegExpCondition); }
521 ;
522
523 LexNoBrace
524 : { if (yychar == yyempty_) driver.nobrace_ = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
525 ;
526
527 LexNoFunction
528 : { if (yychar == token::Function) yychar = token::Function_; }
529 ;
530
531 LexSetStatement
532 : LexNoBrace LexNoFunction
533 ;
534 /* }}} */
535
536 BRACE
537 : "{"
538 | "\n{"
539 ;
540
541 StrictSemi
542 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
543 ;
544
545 Terminator_
546 : ";"
547 | "\n" StrictSemi
548 ;
549
550 Terminator
551 : Terminator_
552 | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
553 ;
554
555 TerminatorOpt
556 : Terminator_
557 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
558 ;
559
560 /*CommaOpt
561 : ","
562 |
563 ;*/
564
565 @begin ObjectiveC
566 NewLineOpt
567 : "\n"
568 |
569 ;
570
571 Word
572 : Identifier { $$ = $1; }
573 | "break" NewLineOpt { $$ = $1; }
574 | "case" { $$ = $1; }
575 | "catch" { $$ = $1; }
576 | "class" { $$ = $1; }
577 | "const" { $$ = $1; }
578 | "continue" NewLineOpt { $$ = $1; }
579 | "debugger" { $$ = $1; }
580 | "default" { $$ = $1; }
581 | "delete" { $$ = $1; }
582 | "do" { $$ = $1; }
583 | "else" { $$ = $1; }
584 | "enum" { $$ = $1; }
585 | "export" { $$ = $1; }
586 | "extends" { $$ = $1; }
587 | "false" { $$ = $1; }
588 | "finally" { $$ = $1; }
589 /* XXX: | "for" { $$ = $1; } */
590 | "function" { $$ = $1; }
591 | "if" { $$ = $1; }
592 | "import" { $$ = $1; }
593 /* XXX: | "in" { $$ = $1; } */
594 /* XXX: | "instanceof" { $$ = $1; } */
595 | "new" { $$ = $1; }
596 | "null" { $$ = $1; }
597 | "of" { $$ = $1; }
598 | "return" NewLineOpt { $$ = $1; }
599 | "super" { $$ = $1; }
600 | "switch" { $$ = $1; }
601 | "this" { $$ = $1; }
602 | "throw" NewLineOpt { $$ = $1; }
603 | "true" { $$ = $1; }
604 | "try" { $$ = $1; }
605 | "typeof" { $$ = $1; }
606 | "var" { $$ = $1; }
607 | "void" { $$ = $1; }
608 | "while" { $$ = $1; }
609 | "with" { $$ = $1; }
610 ;
611
612 WordOpt
613 : Word { $$ = $1; }
614 | { $$ = NULL; }
615 ;
616
617 PrimaryExpression
618 : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
619 | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
620 | "@" ObjectLiteral { $$ = CYNew CYBox($2); }
621 | "@" Parenthetical { $$ = CYNew CYBox($2); }
622 ;
623 @end
624
625 Identifier
626 : Identifier_ { $$ = $1; }
627
628 | "implements" { $$ = $1; }
629 | "interface" { $$ = $1; }
630 | "package" { $$ = $1; }
631 | "private" { $$ = $1; }
632 | "protected" { $$ = $1; }
633 | "public" { $$ = $1; }
634 | "static" { $$ = $1; }
635
636 | "abstract" { $$ = $1; }
637 | "boolean" { $$ = $1; }
638 | "byte" { $$ = $1; }
639 | "char" { $$ = $1; }
640 | "double" { $$ = $1; }
641 | "final" { $$ = $1; }
642 | "float" { $$ = $1; }
643 | "goto" { $$ = $1; }
644 | "int" { $$ = $1; }
645 | "long" { $$ = $1; }
646 | "native" { $$ = $1; }
647 | "short" { $$ = $1; }
648 | "synchronized" { $$ = $1; }
649 | "throws" { $$ = $1; }
650 | "transient" { $$ = $1; }
651 | "volatile" { $$ = $1; }
652
653 // XXX: is this allowed?! | "let" { $$ = $1; }
654 | "yield" { $$ = $1; }
655
656 | "each" { $$ = $1; }
657 ;
658
659 IdentifierOpt
660 : Identifier { $$ = $1; }
661 | { $$ = NULL; }
662 ;
663
664 LiteralNoRE
665 : NullLiteral { $$ = $1; }
666 | BooleanLiteral { $$ = $1; }
667 | NumericLiteral { $$ = $1; }
668 | StringLiteral { $$ = $1; }
669 ;
670
671 Literal
672 : LiteralNoRE { $$ = $1; }
673 | RegularExpressionLiteral { $$ = $1; }
674 ;
675
676 NullLiteral
677 : "null" { $$ = $1; }
678 ;
679
680 BooleanLiteral
681 : "true" { $$ = $1; }
682 | "false" { $$ = $1; }
683 ;
684
685 /* 11.1 Primary Expressions {{{ */
686 Parenthetical
687 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
688 ;
689
690 ParentheticalOpt
691 : Parenthetical { $$ = $1; }
692 | { $$ = NULL; }
693 ;
694
695 PrimaryExpression
696 : "this" { $$ = $1; }
697 | Identifier { $$ = CYNew CYVariable($1); }
698 | Literal { $$ = $1; }
699 | ArrayLiteral { $$ = $1; }
700 | ObjectLiteral { $$ = $1; }
701 | FunctionExpression { $$ = $1; }
702 | Parenthetical { $$ = $1; }
703 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
704 ;
705 /* }}} */
706 /* 11.1.4.1 Array Initialiser {{{ */
707 ArrayLiteral
708 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
709 ;
710
711 Element
712 : AssignmentExpression { $$ = $1; }
713 ;
714
715 ElementOpt
716 : Element { $$ = $1; }
717 | LexSetRegExp { $$ = NULL; }
718 ;
719
720 ElementList
721 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
722 | Element { $$ = CYNew CYElement($1, NULL); }
723 ;
724
725 ElementListOpt
726 : ElementList { $$ = $1; }
727 | LexSetRegExp { $$ = NULL; }
728 ;
729 /* }}} */
730 /* 11.1.5 Object Initialiser {{{ */
731 ObjectLiteral
732 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
733 ;
734
735 PropertyNameAndValueList_
736 : "," PropertyNameAndValueList { $$ = $2; }
737 | { $$ = NULL; }
738 ;
739
740 PropertyNameAndValueList
741 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
742 ;
743
744 PropertyNameAndValueListOpt
745 : PropertyNameAndValueList { $$ = $1; }
746 | { $$ = NULL; }
747 ;
748
749 PropertyName_
750 : Identifier { $$ = $1; }
751 | StringLiteral { $$ = $1; }
752 | NumericLiteral { $$ = $1; }
753 ;
754
755 PropertyName
756 : LexSetRegExp PropertyName_ { $$ = $2; }
757 ;
758 /* }}} */
759
760 /* 11.2 Left-Hand-Side Expressions {{{ */
761 MemberAccess
762 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
763 | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
764 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
765 ;
766
767 MemberExpression_
768 : MemberExpression { $$ = $1; }
769 //| "super" { $$ = $1; }
770 ;
771
772 MemberExpression
773 : LexSetRegExp PrimaryExpression { $$ = $2; }
774 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
775 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
776 ;
777
778 NewExpression
779 : MemberExpression { $$ = $1; }
780 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
781 ;
782
783 CallExpression_
784 : MemberExpression_
785 | CallExpression
786 ;
787
788 CallExpression
789 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
790 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
791 ;
792
793 Arguments
794 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
795 ;
796
797 ArgumentList_
798 : "," ArgumentList { $$ = $2; }
799 | { $$ = NULL; }
800 ;
801
802 ArgumentList
803 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
804 ;
805
806 ArgumentListOpt
807 : ArgumentList { $$ = $1; }
808 | LexSetRegExp { $$ = NULL; }
809 ;
810
811 LeftHandSideExpression
812 : NewExpression { $$ = $1; }
813 | CallExpression { $$ = $1; }
814 ;
815 /* }}} */
816 /* 11.3 Postfix Expressions {{{ */
817 PostfixExpression
818 : %prec "" LeftHandSideExpression { $$ = $1; }
819 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
820 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
821 ;
822 /* }}} */
823 /* 11.4 Unary Operators {{{ */
824 UnaryExpression_
825 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
826 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
827 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
828 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
829 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
830 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
831 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
832 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
833 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
834 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
835 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
836 ;
837
838 UnaryExpression
839 : PostfixExpression { $$ = $1; }
840 | LexSetRegExp UnaryExpression_ { $$ = $2; }
841 ;
842 /* }}} */
843 /* 11.5 Multiplicative Operators {{{ */
844 MultiplicativeExpression
845 : UnaryExpression { $$ = $1; }
846 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
847 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
848 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
849 ;
850 /* }}} */
851 /* 11.6 Additive Operators {{{ */
852 AdditiveExpression
853 : MultiplicativeExpression { $$ = $1; }
854 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
855 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
856 ;
857 /* }}} */
858 /* 11.7 Bitwise Shift Operators {{{ */
859 ShiftExpression
860 : AdditiveExpression { $$ = $1; }
861 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
862 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
863 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
864 ;
865 /* }}} */
866 /* 11.8 Relational Operators {{{ */
867 RelationalExpression
868 : ShiftExpression { $$ = $1; }
869 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
870 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
871 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
872 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
873 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
874 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
875 ;
876 /* }}} */
877 /* 11.9 Equality Operators {{{ */
878 EqualityExpression
879 : RelationalExpression { $$ = $1; }
880 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
881 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
882 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
883 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
884 ;
885 /* }}} */
886 /* 11.10 Binary Bitwise Operators {{{ */
887 BitwiseANDExpression
888 : EqualityExpression { $$ = $1; }
889 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
890 ;
891
892 BitwiseXORExpression
893 : BitwiseANDExpression { $$ = $1; }
894 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
895 ;
896
897 BitwiseORExpression
898 : BitwiseXORExpression { $$ = $1; }
899 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
900 ;
901 /* }}} */
902 /* 11.11 Binary Logical Operators {{{ */
903 LogicalANDExpression
904 : BitwiseORExpression { $$ = $1; }
905 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
906 ;
907
908 LogicalORExpression
909 : LogicalANDExpression { $$ = $1; }
910 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
911 ;
912 /* }}} */
913 /* 11.12 Conditional Operator ( ? : ) {{{ */
914 ConditionalExpression
915 : LogicalORExpression { $$ = $1; }
916 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
917 ;
918 /* }}} */
919 /* 11.13 Assignment Operators {{{ */
920 AssignmentExpression
921 : ConditionalExpression { $$ = $1; }
922 | ArrowFunction { $$ = $1; }
923 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
924 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
925 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
926 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
927 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
928 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
929 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
930 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
931 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
932 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
933 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
934 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
935 ;
936 /* }}} */
937 /* 11.14 Comma Operator {{{ */
938 Expression_
939 : "," Expression { $$ = $2; }
940 | { $$ = CYNew CYCompound(); }
941 ;
942
943 Expression
944 : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
945 ;
946
947 ExpressionOpt
948 : Expression { $$ = $1; }
949 | LexSetRegExp { $$ = NULL; }
950 ;
951 /* }}} */
952
953 /* 12 Statements {{{ */
954 Statement__
955 : Block { $$ = $1; }
956 | VariableStatement { $$ = $1; }
957 | EmptyStatement { $$ = $1; }
958 | IfStatement { $$ = $1; }
959 | BreakableStatement { $$ = $1; }
960 | ContinueStatement { $$ = $1; }
961 | BreakStatement { $$ = $1; }
962 | ReturnStatement { $$ = $1; }
963 | WithStatement { $$ = $1; }
964 | LabelledStatement { $$ = $1; }
965 | ThrowStatement { $$ = $1; }
966 | TryStatement { $$ = $1; }
967 | DebuggerStatement { $$ = $1; }
968 ;
969
970 Statement_
971 : LexSetRegExp Statement__ { $$ = $2; }
972 | ExpressionStatement { $$ = $1; }
973 ;
974
975 Statement
976 : LexSetStatement Statement_ { $$ = $2; }
977 ;
978
979 Declaration__
980 : FunctionDeclaration { $$ = $1; }
981 | LexicalDeclaration { $$ = $1; }
982 ;
983
984 Declaration_
985 : LexSetRegExp Declaration__ { $$ = $2; }
986 ;
987
988 Declaration
989 : LexSetStatement Declaration_ { $$ = $2; }
990 ;
991
992 BreakableStatement
993 : IterationStatement { $$ = $1; }
994 | SwitchStatement { $$ = $1; }
995 ;
996 /* }}} */
997 /* 12.1 Block {{{ */
998 Block_
999 : BRACE StatementListOpt "}" { $$ = $2; }
1000 ;
1001
1002 Block
1003 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1004 ;
1005
1006 StatementList
1007 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1008 ;
1009
1010 StatementListOpt
1011 : StatementList { $$ = $1; }
1012 | LexSetRegExp { $$ = NULL; }
1013 ;
1014
1015 StatementListItem
1016 : Statement { $$ = $1; }
1017 | Declaration { $$ = $1; }
1018 ;
1019 /* }}} */
1020 /* 12.2 Declarations {{{ */
1021 BindingIdentifier
1022 : Identifier { $$ = $1; }
1023 ;
1024
1025 // XXX: BindingPattern
1026 /* }}} */
1027 /* 12.2.1 Let and Const Declarations {{{ */
1028 LexicalDeclaration
1029 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1030 ;
1031
1032 LetOrConst
1033 : "let"
1034 | "const"
1035 ;
1036 /* }}} */
1037 /* 12.2.2 Variable Statement {{{ */
1038 VariableStatement
1039 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1040 ;
1041
1042 VariableDeclarationList_
1043 : "," VariableDeclarationList { $$ = $2; }
1044 | { $$ = NULL; }
1045 ;
1046
1047 VariableDeclarationList
1048 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1049 ;
1050
1051 VariableDeclaration
1052 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1053 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1054 ;
1055
1056 Initialiser
1057 : "=" AssignmentExpression { $$ = $2; }
1058 ;
1059
1060 InitialiserOpt
1061 : Initialiser { $$ = $1; }
1062 | { $$ = NULL; }
1063 ;
1064 /* }}} */
1065 /* 12.2.4 Destructuring Binding Patterns {{{ */
1066 // XXX: *
1067
1068 BindingElement
1069 : SingleNameBinding { $$ = $1; }
1070 ;
1071
1072 SingleNameBinding
1073 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1074 ;
1075 /* }}} */
1076 /* 12.3 Empty Statement {{{ */
1077 EmptyStatement
1078 : ";" { $$ = CYNew CYEmpty(); }
1079 ;
1080 /* }}} */
1081 /* 12.4 Expression Statement {{{ */
1082 ExpressionStatement
1083 : Expression Terminator { $$ = CYNew CYExpress($1); }
1084 ;
1085 /* }}} */
1086 /* 12.5 The if Statement {{{ */
1087 ElseStatementOpt
1088 : "else" Statement { $$ = $2; }
1089 | %prec "if" { $$ = NULL; }
1090 ;
1091
1092 IfStatement
1093 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1094 ;
1095 /* }}} */
1096
1097 /* 12.6.1 The do-while Statement {{{ */
1098 IterationStatement
1099 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1100 ;
1101 /* }}} */
1102 /* 12.6.2 The while Statement {{{ */
1103 IterationStatement
1104 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1105 ;
1106 /* }}} */
1107 /* 12.6.3 The for Statement {{{ */
1108 IterationStatement
1109 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1110 ;
1111
1112 ForStatementInitialiser
1113 : ExpressionOpt { $$ = $1; }
1114 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1115 ;
1116 /* }}} */
1117 /* 12.6.4 The for-in and for-of Statements {{{ */
1118 IterationStatement
1119 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1120 | "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "of" Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1121 ;
1122
1123 ForInStatementInitialiser
1124 : LeftHandSideExpression { $$ = $1; }
1125 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1126 ;
1127 /* }}} */
1128
1129 /* 12.7 The continue Statement {{{ */
1130 ContinueStatement
1131 : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1132 ;
1133 /* }}} */
1134 /* 12.8 The break Statement {{{ */
1135 BreakStatement
1136 : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1137 ;
1138 /* }}} */
1139 /* 12.9 The return Statement {{{ */
1140 ReturnStatement
1141 : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1142 ;
1143 /* }}} */
1144 /* 12.10 The with Statement {{{ */
1145 WithStatement
1146 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1147 ;
1148 /* }}} */
1149
1150 /* 12.11 The switch Statement {{{ */
1151 SwitchStatement
1152 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1153 ;
1154
1155 CaseBlock
1156 : BRACE CaseClausesOpt "}" { $$ = $2; }
1157 ;
1158
1159 CaseClause
1160 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1161 ;
1162
1163 CaseClausesOpt
1164 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1165 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1166 | { $$ = NULL; }
1167 ;
1168
1169 DefaultClause
1170 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1171 ;
1172 /* }}} */
1173 /* 12.12 Labelled Statements {{{ */
1174 LabelledStatement
1175 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1176 ;
1177 /* }}} */
1178 /* 12.13 The throw Statement {{{ */
1179 ThrowStatement
1180 : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1181 ;
1182 /* }}} */
1183 /* 12.14 The try Statement {{{ */
1184 TryStatement
1185 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1186 ;
1187
1188 CatchOpt
1189 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1190 | { $$ = NULL; }
1191 ;
1192
1193 FinallyOpt
1194 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1195 | { $$ = NULL; }
1196 ;
1197 /* }}} */
1198 /* 12.14 The debugger Statement {{{ */
1199 DebuggerStatement
1200 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1201 ;
1202 /* }}} */
1203
1204 /* 13.1 Function Definitions {{{ */
1205 FunctionDeclaration
1206 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1207 ;
1208
1209 FunctionExpression
1210 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1211 ;
1212
1213 FormalParameterList_
1214 : "," FormalParameterList { $$ = $2; }
1215 | { $$ = NULL; }
1216 ;
1217
1218 FormalParameterList
1219 // XXX: : FunctionRestParameter { $$ = $1; }
1220 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1221 ;
1222
1223 FormalParameterListOpt
1224 : FormalParameterList
1225 | { $$ = NULL; }
1226 ;
1227
1228 /* XXX: FunctionRestParameter
1229 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1230 ;*/
1231
1232 FormalParameter
1233 : BindingElement { $$ = $1; }
1234 ;
1235
1236 FunctionBody
1237 : StatementListOpt { $$ = $1; }
1238 ;
1239 /* }}} */
1240 /* 13.2 Arrow Function Definitions {{{ */
1241 ArrowFunction
1242 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFunctionExpression(NULL, $2, $5); }
1243 ;
1244
1245 ArrowParameters
1246 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1247 //| ParentheticalOpt { $$ = $1; }
1248 ;
1249
1250 ConciseBody
1251 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1252 | ";{" LexPushInOff FunctionBody LexPopIn "}" { $$ = $3; }
1253 ;
1254 /* }}} */
1255 /* 14 Program {{{ */
1256 Program
1257 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1258 ;
1259
1260 ProgramBody
1261 : StatementList { $$ = $1; }
1262 ;
1263
1264 ProgramBodyOpt
1265 : ProgramBody { $$ = $1; }
1266 | { $$ = NULL; }
1267 ;
1268 /* }}} */
1269
1270 @begin ObjectiveC
1271 /* Cycript (Objective-C): @class Declaration {{{ */
1272 ClassSuperOpt
1273 /* XXX: why the hell did I choose MemberExpression? */
1274 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1275 | { $$ = NULL; }
1276 ;
1277
1278 ClassField
1279 : Expression Identifier ";"
1280 ;
1281
1282 ClassFieldList
1283 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1284 ;
1285
1286 ClassFieldListOpt
1287 : ClassFieldListOpt ClassField
1288 |
1289 ;
1290
1291 MessageScope
1292 : "+" { $$ = false; }
1293 | "-" { $$ = true; }
1294 ;
1295
1296 TypeOpt
1297 : "(" Expression ")" { $$ = $2; }
1298 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1299 | { $$ = NULL; }
1300 ;
1301
1302 MessageParameter
1303 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1304 ;
1305
1306 MessageParameterList
1307 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1308 ;
1309
1310 MessageParameterListOpt
1311 : MessageParameterList { $$ = $1; }
1312 | { $$ = NULL; }
1313 ;
1314
1315 MessageParameters
1316 : MessageParameterList { $$ = $1; }
1317 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1318 ;
1319
1320 ClassMessageDeclaration
1321 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1322 ;
1323
1324 ClassMessageDeclarationListOpt
1325 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1326 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1327 | { $$ = NULL; }
1328 ;
1329
1330 ClassName
1331 : Identifier { $$ = $1; }
1332 | "(" AssignmentExpression ")" { $$ = $2; }
1333 ;
1334
1335 ClassNameOpt
1336 : ClassName { $$ = $1; }
1337 | { $$ = NULL; }
1338 ;
1339
1340 // XXX: this should be AssignmentExpressionNoRight
1341 ClassProtocols
1342 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1343 ;
1344
1345 ClassProtocolsOpt
1346 : "," ClassProtocols { $$ = $2; }
1347 | { $$ = NULL; }
1348 ;
1349
1350 ClassProtocolListOpt
1351 : "<" ClassProtocols ">" { $$ = $2; }
1352 | { $$ = NULL; }
1353 ;
1354
1355 ClassExpression
1356 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1357 ;
1358
1359 ClassStatement
1360 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1361 ;
1362
1363 CategoryName
1364 : "(" WordOpt ")"
1365 ;
1366
1367 CategoryStatement
1368 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1369 ;
1370
1371 PrimaryExpression
1372 : ClassExpression { $$ = $1; }
1373 ;
1374
1375 Statement__
1376 : ClassStatement { $$ = $1; }
1377 | CategoryStatement { $$ = $1; }
1378 ;
1379 /* }}} */
1380 /* Cycript (Objective-C): Send Message {{{ */
1381 VariadicCall
1382 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1383 | { $$ = NULL; }
1384 ;
1385
1386 SelectorWordOpt
1387 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1388 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1389 ;
1390
1391 SelectorCall_
1392 : SelectorCall { $$ = $1; }
1393 | VariadicCall { $$ = $1; }
1394 ;
1395
1396 SelectorCall
1397 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1398 ;
1399
1400 SelectorList
1401 : SelectorCall { $$ = $1; }
1402 | Word { $$ = CYNew CYArgument($1, NULL); }
1403 ;
1404
1405 MessageExpression
1406 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1407 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1408 ;
1409
1410 SelectorExpression_
1411 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1412 ;
1413
1414 SelectorExpression
1415 : SelectorExpression_ { $$ = $1; }
1416 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1417 ;
1418
1419 SelectorExpressionOpt
1420 : SelectorExpression_ { $$ = $1; }
1421 | { $$ = NULL; }
1422 ;
1423
1424 PrimaryExpression
1425 : MessageExpression { $$ = $1; }
1426 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1427 ;
1428 /* }}} */
1429 /* Cycript (Objective-C): @import Directive {{{ */
1430 PathName
1431 : "/" PathName
1432 | "." PathName
1433 | Word PathName
1434 |
1435 ;
1436
1437 ImportPath
1438 : "<" PathName ">"
1439 | StringLiteral
1440 ;
1441
1442 StatementListItem
1443 : "@import" ImportPath { $$ = CYNew CYImport(); }
1444 ;
1445 /* }}} */
1446 @end
1447
1448 @begin C
1449 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1450 LeftHandSideExpression
1451 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1452 ;
1453
1454 UnaryExpression_
1455 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1456 ;
1457
1458 MemberAccess
1459 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1460 | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1461 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1462 ;
1463 /* }}} */
1464 @end
1465
1466 /* YUI: Documentation Comments {{{ */
1467 Statement__
1468 : Comment { $$ = $1; }
1469 ;
1470 /* }}} */
1471
1472 @begin E4X
1473 /* Lexer State {{{ */
1474 LexPushRegExp
1475 : { driver.PushCondition(CYDriver::RegExpCondition); }
1476 ;
1477
1478 LexPushXMLContent
1479 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1480 ;
1481
1482 LexPushXMLTag
1483 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1484 ;
1485
1486 LexPop
1487 : { driver.PopCondition(); }
1488 ;
1489
1490 LexSetXMLContent
1491 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1492 ;
1493
1494 LexSetXMLTag
1495 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1496 ;
1497 /* }}} */
1498
1499 XMLWhitespaceOpt
1500 : XMLWhitespace
1501 |
1502 ;
1503
1504 /* 8.1 Context Keywords {{{ */
1505 Identifier
1506 : "namespace" { $$ = $1; }
1507 | "xml" { $$ = $1; }
1508 ;
1509 /* }}} */
1510 /* 8.3 XML Initialiser Input Elements {{{ */
1511 XMLMarkup
1512 : XMLComment { $$ = $1; }
1513 | XMLCDATA { $$ = $1; }
1514 | XMLPI { $$ = $1; }
1515 ;
1516 /* }}} */
1517 /* 11.1 Primary Expressions {{{ */
1518 PrimaryExpression
1519 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1520 | XMLInitialiser { $$ = $1; }
1521 | XMLListInitialiser { $$ = $1; }
1522 ;
1523
1524 PropertyIdentifier
1525 : AttributeIdentifier { $$ = $1; }
1526 | QualifiedIdentifier { $$ = $1; }
1527 | WildcardIdentifier { $$ = $1; }
1528 ;
1529 /* }}} */
1530 /* 11.1.1 Attribute Identifiers {{{ */
1531 AttributeIdentifier
1532 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1533 ;
1534
1535 PropertySelector_
1536 : PropertySelector { $$ = $1; }
1537 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1538 ;
1539
1540 PropertySelector
1541 : Identifier { $$ = CYNew CYSelector($1); }
1542 | WildcardIdentifier { $$ = $1; }
1543 ;
1544 /* }}} */
1545 /* 11.1.2 Qualified Identifiers {{{ */
1546 QualifiedIdentifier_
1547 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1548 | QualifiedIdentifier { $$ = $1; }
1549 ;
1550
1551 QualifiedIdentifier
1552 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1553 ;
1554 /* }}} */
1555 /* 11.1.3 Wildcard Identifiers {{{ */
1556 WildcardIdentifier
1557 : "*" { $$ = CYNew CYWildcard(); }
1558 ;
1559 /* }}} */
1560 /* 11.1.4 XML Initialiser {{{ */
1561 XMLInitialiser
1562 : XMLMarkup { $$ = $1; }
1563 | XMLElement { $$ = $1; }
1564 ;
1565
1566 XMLElement
1567 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1568 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1569 ;
1570
1571 XMLTagContent
1572 : LexPushXMLTag XMLTagName XMLAttributes
1573 ;
1574
1575 XMLExpression
1576 : BRACE LexPushRegExp Expression LexPop "}"
1577 ;
1578
1579 XMLTagName
1580 : XMLExpression
1581 | XMLName
1582 ;
1583
1584 XMLAttributes_
1585 : XMLAttributes_ XMLAttribute
1586 |
1587 ;
1588
1589 XMLAttributes
1590 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1591 | XMLAttributes_ XMLWhitespaceOpt
1592 ;
1593
1594 XMLAttributeValue_
1595 : XMLExpression
1596 | XMLAttributeValue
1597 ;
1598
1599 XMLAttribute
1600 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1601 ;
1602
1603 XMLElementContent
1604 : XMLExpression XMLElementContentOpt
1605 | XMLMarkup XMLElementContentOpt
1606 | XMLText XMLElementContentOpt
1607 | XMLElement XMLElementContentOpt
1608 ;
1609
1610 XMLElementContentOpt
1611 : XMLElementContent
1612 |
1613 ;
1614 /* }}} */
1615 /* 11.1.5 XMLList Initialiser {{{ */
1616 XMLListInitialiser
1617 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1618 ;
1619 /* }}} */
1620 /* 11.2 Left-Hand-Side Expressions {{{ */
1621 PropertyIdentifier_
1622 : Identifier { $$ = $1; }
1623 | PropertyIdentifier { $$ = $1; }
1624 ;
1625
1626 MemberAccess
1627 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1628 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1629 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1630 ;
1631 /* }}} */
1632 /* 12.1 The default xml namespace Statement {{{ */
1633 /* XXX: DefaultXMLNamespaceStatement
1634 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1635 ;
1636
1637 Statement__
1638 : DefaultXMLNamespaceStatement { $$ = $1; }
1639 ; */
1640 /* }}} */
1641 @end
1642
1643 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1644 PropertyNameAndValueList_
1645 : "," { $$ = NULL; }
1646 ;
1647 /* }}} */
1648
1649 /* JavaScript 1.7: Array Comprehensions {{{ */
1650 IfComprehension
1651 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1652 ;
1653
1654 ForComprehension
1655 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1656 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
1657 ;
1658
1659 ComprehensionList
1660 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1661 ;
1662
1663 ComprehensionListOpt
1664 : ComprehensionList { $$ = $1; }
1665 | IfComprehension { $$ = $1; }
1666 | { $$ = NULL; }
1667 ;
1668
1669 PrimaryExpression
1670 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1671 ;
1672 /* }}} */
1673 /* JavaScript 1.7: for each {{{ */
1674 IterationStatement
1675 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1676 ;
1677 /* }}} */
1678 /* JavaScript 1.7: let Statements {{{ */
1679 LetStatement
1680 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1681 ;
1682
1683 Statement__
1684 : LetStatement
1685 ;
1686 /* }}} */
1687
1688 /* JavaScript FTW: Ruby Blocks {{{ */
1689 RubyProcParameterList_
1690 : "," RubyProcParameterList { $$ = $2; }
1691 | { $$ = NULL; }
1692 ;
1693
1694 RubyProcParameterList
1695 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1696 | { $$ = NULL; }
1697 ;
1698
1699 RubyProcParameters
1700 : "|" RubyProcParameterList "|" { $$ = $2; }
1701 | "||" { $$ = NULL; }
1702 ;
1703
1704 RubyProcParametersOpt
1705 : RubyProcParameters
1706 | { $$ = NULL; }
1707 ;
1708
1709 RubyProcExpression
1710 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1711 ;
1712
1713 PrimaryExpression
1714 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1715 ;
1716
1717 CallExpression
1718 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
1719 ;
1720 /* }}} */
1721
1722 %%