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