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