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