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