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