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