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