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