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