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