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