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