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