]> git.saurik.com Git - cycript.git/blame_incremental - Parser.ypp.in
Allow extern "C" {} and limit semicolon insertion.
[cycript.git] / Parser.ypp.in
... / ...
CommitLineData
1/* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3*/
4
5/* GNU Affero General Public License, Version 3 {{{ */
6/*
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
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
19**/
20/* }}} */
21
22%code top {
23#define YYSTACKEXPANDABLE 1
24}
25
26%code requires {
27#include "Driver.hpp"
28#include "Parser.hpp"
29#include "Stack.hpp"
30#define CYNew new(driver.pool_)
31
32@begin ObjectiveC
33#include "ObjectiveC/Syntax.hpp"
34@end
35
36@begin E4X
37#include "E4X/Syntax.hpp"
38@end
39
40#include "Highlight.hpp"
41}
42
43%union { bool bool_; }
44
45%union { CYMember *access_; }
46%union { CYArgument *argument_; }
47%union { CYAssignment *assignment_; }
48%union { CYBinding *binding_; }
49%union { CYBindings *bindings_; }
50%union { CYBoolean *boolean_; }
51%union { CYClause *clause_; }
52%union { cy::Syntax::Catch *catch_; }
53%union { CYClassTail *classTail_; }
54%union { CYComprehension *comprehension_; }
55%union { CYElement *element_; }
56%union { CYExpression *expression_; }
57%union { CYFalse *false_; }
58%union { CYVariable *variable_; }
59%union { CYFinally *finally_; }
60%union { CYForInitializer *for_; }
61%union { CYForInInitializer *forin_; }
62%union { CYFunctionParameter *functionParameter_; }
63%union { CYIdentifier *identifier_; }
64%union { CYInfix *infix_; }
65%union { CYLiteral *literal_; }
66%union { CYMethod *method_; }
67%union { CYModule *module_; }
68%union { CYNull *null_; }
69%union { CYNumber *number_; }
70%union { CYParenthetical *parenthetical_; }
71%union { CYProperty *property_; }
72%union { CYPropertyName *propertyName_; }
73%union { CYRubyProc *rubyProc_; }
74%union { CYSpan *span_; }
75%union { CYStatement *statement_; }
76%union { CYString *string_; }
77%union { CYTarget *target_; }
78%union { CYThis *this_; }
79%union { CYTrue *true_; }
80%union { CYWord *word_; }
81
82@begin C
83%union { CYTypeStructField *structField_; }
84%union { CYTypeModifier *modifier_; }
85%union { CYTypeSpecifier *specifier_; }
86%union { CYTypedIdentifier *typedIdentifier_; }
87%union { CYTypedParameter *typedParameter_; }
88@end
89
90@begin ObjectiveC
91%union { CYImplementationField *implementationField_; }
92%union { CYMessage *message_; }
93%union { CYMessageParameter *messageParameter_; }
94%union { CYProtocol *protocol_; }
95%union { CYSelectorPart *selector_; }
96@end
97
98@begin E4X
99%union { CYAttribute *attribute_; }
100%union { CYPropertyIdentifier *propertyIdentifier_; }
101%union { CYSelector *selector_; }
102@end
103
104%code provides {
105
106struct YYSTYPE {
107 cy::parser::semantic_type semantic_;
108 hi::Value highlight_;
109};
110
111int cylex(YYSTYPE *, CYLocation *, void *);
112
113}
114
115%code {
116
117#undef yylex
118
119typedef cy::parser::token tk;
120
121_finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
122 driver.newline_ = false;
123 lex:
124 YYSTYPE data;
125 int token(cylex(&data, location, driver.scanner_));
126 *semantic = data.semantic_;
127
128 switch (token) {
129 case tk::OpenBrace:
130 case tk::OpenBracket:
131 case tk::OpenParen:
132 driver.in_.push(false);
133 break;
134
135 case tk::_in_:
136 if (driver.in_.top())
137 token = tk::_in__;
138 break;
139
140 case tk::CloseBrace:
141 case tk::CloseBracket:
142 case tk::CloseParen:
143 driver.in_.pop();
144 break;
145
146
147 case tk::_yield_:
148 if (driver.yield_.top())
149 token = tk::_yield__;
150 break;
151
152 case tk::NewLine:
153 driver.newline_ = true;
154 goto lex;
155 break;
156 }
157
158 return token;
159}
160
161#define yylex_(semantic, location, driver) ({ \
162 int type; \
163 if (driver.hold_ == cy::parser::empty_symbol) \
164 type = yytranslate_(cylex_(semantic, location, driver)); \
165 else { \
166 type = driver.hold_; \
167 driver.hold_ = cy::parser::empty_symbol; \
168 } \
169type; })
170
171#define CYLEX() do if (yyla.empty()) { \
172 YYCDEBUG << "Mapping a token: "; \
173 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
174 YY_SYMBOL_PRINT("Next token is", yyla); \
175} while (false)
176
177#define CYMAP(to, from) do { \
178 CYLEX(); \
179 if (yyla.type == yytranslate_(token::from)) \
180 yyla.type = yytranslate_(token::to); \
181} while (false)
182
183#define CYERR(location, message) do { \
184 error(location, message); \
185 YYABORT; \
186} while (false)
187
188#define CYEOK() do { \
189 yyerrok; \
190 driver.errors_.pop_back(); \
191} while (false)
192
193#define CYNOT(location) \
194 CYERR(location, "unimplemented feature")
195
196#define CYMPT(location) do { \
197 if (!yyla.empty() && yyla.type_get() != yyeof_) \
198 CYERR(location, "unexpected lookahead"); \
199} while (false)
200
201}
202
203%name-prefix "cy"
204
205%language "C++"
206
207%initial-action {
208 @$.begin.filename = @$.end.filename = &driver.filename_;
209
210 switch (driver.mark_) {
211 case CYMarkScript:
212 driver.hold_ = yytranslate_(token::MarkScript);
213 break;
214 case CYMarkModule:
215 driver.hold_ = yytranslate_(token::MarkModule);
216 break;
217 }
218};
219
220%locations
221%defines
222
223%define api.location.type { CYLocation }
224
225//%glr-parser
226//%expect 1
227
228%error-verbose
229
230%param { CYDriver &driver }
231
232/* Token Declarations {{{ */
233@begin E4X
234%token XMLCDATA
235%token XMLComment
236%token XMLPI
237
238%token XMLAttributeValue
239%token XMLName
240%token XMLTagCharacters
241%token XMLText
242%token XMLWhitespace
243@end
244
245@begin E4X
246%token LeftRight "<>"
247%token LeftSlashRight "</>"
248
249%token SlashRight "/>"
250%token LeftSlash "</"
251
252%token ColonColon "::"
253%token PeriodPeriod ".."
254@end
255
256@begin E4X ObjectiveC
257%token At "@"
258%token Pound "#"
259@end
260
261%token Ampersand "&"
262%token AmpersandAmpersand "&&"
263%token AmpersandEqual "&="
264%token Carrot "^"
265%token CarrotEqual "^="
266%token Equal "="
267%token EqualEqual "=="
268%token EqualEqualEqual "==="
269%token EqualRight "=>"
270%token Exclamation "!"
271%token ExclamationEqual "!="
272%token ExclamationEqualEqual "!=="
273%token Hyphen "-"
274%token HyphenEqual "-="
275%token HyphenHyphen "--"
276%token HyphenRight "->"
277%token Left "<"
278%token LeftEqual "<="
279%token LeftLeft "<<"
280%token LeftLeftEqual "<<="
281%token Percent "%"
282%token PercentEqual "%="
283%token Period "."
284%token PeriodPeriodPeriod "..."
285%token Pipe "|"
286%token PipeEqual "|="
287%token PipePipe "||"
288%token Plus "+"
289%token PlusEqual "+="
290%token PlusPlus "++"
291%token Right ">"
292%token RightEqual ">="
293%token RightRight ">>"
294%token RightRightEqual ">>="
295%token RightRightRight ">>>"
296%token RightRightRightEqual ">>>="
297%token Slash "/"
298%token SlashEqual "/="
299%token Star "*"
300%token StarEqual "*="
301%token Tilde "~"
302
303%token Colon ":"
304%token Comma ","
305%token Question "?"
306%token SemiColon ";"
307%token NewLine "\n"
308%token __ ""
309
310%token Comment
311
312%token OpenParen "("
313%token CloseParen ")"
314
315%token OpenBrace "{"
316%token OpenBrace_ ";{"
317%token OpenBrace_let "let {"
318%token CloseBrace "}"
319
320%token OpenBracket "["
321%token OpenBracket_let "let ["
322%token CloseBracket "]"
323
324%token At_error_ "@error"
325
326@begin Java
327%token At_class_ "@class"
328@end
329
330@begin C
331%token _typedef_ "typedef"
332%token _unsigned_ "unsigned"
333%token _signed_ "signed"
334%token _struct_ "struct"
335%token _extern_ "extern"
336@end
337
338@begin C
339%token At_encode_ "@encode"
340@end
341
342@begin ObjectiveC
343%token At_implementation_ "@implementation"
344%token At_import_ "@import"
345%token At_end_ "@end"
346%token At_selector_ "@selector"
347%token At_null_ "@null"
348%token At_YES_ "@YES"
349%token At_NO_ "@NO"
350%token At_true_ "@true"
351%token At_false_ "@false"
352%token _YES_ "YES"
353%token _NO_ "NO"
354@end
355
356%token _false_ "false"
357%token _null_ "null"
358%token _true_ "true"
359
360%token _break_ "break"
361%token _case_ "case"
362%token _catch_ "catch"
363%token _class_ "class"
364%token _class__ ";class"
365%token _const_ "const"
366%token _continue_ "continue"
367%token _debugger_ "debugger"
368%token _default_ "default"
369%token _delete_ "delete"
370%token _do_ "do"
371%token _else_ "else"
372%token _enum_ "enum"
373%token _export_ "export"
374%token _extends_ "extends"
375%token _finally_ "finally"
376%token _for_ "for"
377%token _function_ "function"
378%token _function__ ";function"
379%token _if_ "if"
380%token _import_ "import"
381%token _in_ "in"
382%token _in__ "!in"
383%token _Infinity_ "Infinity"
384%token _instanceof_ "instanceof"
385%token _new_ "new"
386%token _return_ "return"
387%token _super_ "super"
388%token _switch_ "switch"
389%token _target_ "target"
390%token _this_ "this"
391%token _throw_ "throw"
392%token _try_ "try"
393%token _typeof_ "typeof"
394%token _var_ "var"
395%token _void_ "void"
396%token _while_ "while"
397%token _with_ "with"
398
399%token _abstract_ "abstract"
400%token _await_ "await"
401%token _boolean_ "boolean"
402%token _byte_ "byte"
403%token _char_ "char"
404%token _constructor_ "constructor"
405%token _double_ "double"
406%token _eval_ "eval"
407%token _final_ "final"
408%token _float_ "float"
409%token _from_ "from"
410%token _get_ "get"
411%token _goto_ "goto"
412%token _implements_ "implements"
413%token _int_ "int"
414%token _interface_ "interface"
415%token _let_ "let"
416%token _let__ "!let"
417%token _long_ "long"
418%token _native_ "native"
419%token _package_ "package"
420%token _private_ "private"
421%token _protected_ "protected"
422%token ___proto___ "__proto__"
423%token _prototype_ "prototype"
424%token _public_ "public"
425%token _set_ "set"
426%token _short_ "short"
427%token _static_ "static"
428%token _synchronized_ "synchronized"
429%token _throws_ "throws"
430%token _transient_ "transient"
431%token _volatile_ "volatile"
432%token _yield_ "yield"
433%token _yield__ "!yield"
434
435%token _undefined_ "undefined"
436
437@begin ObjectiveC
438%token _bool_ "bool"
439%token _BOOL_ "BOOL"
440%token _id_ "id"
441%token _nil_ "nil"
442%token _NULL_ "NULL"
443%token _SEL_ "SEL"
444@end
445
446%token _each_ "each"
447%token _of_ "of"
448%token _of__ "!of"
449
450@begin E4X
451%token _namespace_ "namespace"
452%token _xml_ "xml"
453@end
454
455%token AutoComplete
456%token YieldStar "yield *"
457
458%token <identifier_> Identifier_
459%token <number_> NumericLiteral
460%token <string_> StringLiteral
461%token <literal_> RegularExpressionLiteral_
462
463%token <string_> NoSubstitutionTemplate
464%token <string_> TemplateHead
465%token <string_> TemplateMiddle
466%token <string_> TemplateTail
467
468%type <target_> AccessExpression
469%type <expression_> AdditiveExpression
470%type <argument_> ArgumentList_
471%type <argument_> ArgumentList
472%type <argument_> ArgumentListOpt
473%type <argument_> Arguments
474%type <target_> ArrayComprehension
475%type <literal_> ArrayLiteral
476%type <expression_> ArrowFunction
477%type <functionParameter_> ArrowParameters
478%type <expression_> AssignmentExpression
479%type <expression_> AssignmentExpressionOpt
480%type <identifier_> BindingIdentifier
481%type <identifier_> BindingIdentifierOpt
482%type <bindings_> BindingList_
483%type <bindings_> BindingList
484%type <expression_> BitwiseANDExpression
485%type <statement_> Block
486%type <statement_> BlockStatement
487%type <boolean_> BooleanLiteral
488%type <binding_> BindingElement
489%type <expression_> BitwiseORExpression
490%type <expression_> BitwiseXORExpression
491%type <statement_> BreakStatement
492%type <statement_> BreakableStatement
493%type <expression_> CallExpression_
494%type <target_> CallExpression
495%type <clause_> CaseBlock
496%type <clause_> CaseClause
497%type <clause_> CaseClausesOpt
498%type <catch_> Catch
499%type <identifier_> CatchParameter
500%type <statement_> ClassDeclaration
501%type <target_> ClassExpression
502%type <classTail_> ClassHeritage
503%type <classTail_> ClassHeritageOpt
504%type <classTail_> ClassTail
505%type <target_> Comprehension
506%type <comprehension_> ComprehensionFor
507%type <comprehension_> ComprehensionIf
508%type <comprehension_> ComprehensionTail
509%type <propertyName_> ComputedPropertyName
510%type <expression_> ConditionalExpression
511%type <statement_> ContinueStatement
512%type <statement_> ConciseBody
513%type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
514%type <statement_> DebuggerStatement
515%type <statement_> Declaration_
516%type <statement_> Declaration
517%type <clause_> DefaultClause
518%type <element_> ElementList
519%type <element_> ElementListOpt
520%type <statement_> ElseStatementOpt
521%type <for_> EmptyStatement
522%type <expression_> EqualityExpression
523%type <expression_> Expression
524%type <expression_> ExpressionOpt
525%type <for_> ExpressionStatement_
526%type <statement_> ExpressionStatement
527%type <statement_> ExternC
528%type <statement_> ExternCStatement
529%type <statement_> ExternCStatementListOpt
530%type <finally_> Finally
531%type <binding_> ForBinding
532%type <forin_> ForDeclaration
533%type <forin_> ForInStatementInitializer
534%type <for_> ForStatementInitializer
535%type <binding_> FormalParameter
536%type <functionParameter_> FormalParameterList_
537%type <functionParameter_> FormalParameterList
538%type <functionParameter_> FormalParameters
539%type <statement_> FunctionBody
540%type <statement_> FunctionDeclaration
541%type <target_> FunctionExpression
542%type <statement_> FunctionStatementList
543%type <statement_> GeneratorBody
544%type <statement_> GeneratorDeclaration
545%type <target_> GeneratorExpression
546%type <method_> GeneratorMethod
547%type <statement_> HoistableDeclaration
548%type <identifier_> Identifier
549%type <identifier_> IdentifierNoOf
550%type <identifier_> IdentifierType
551%type <identifier_> IdentifierTypeNoOf
552%type <identifier_> IdentifierTypeOpt
553%type <word_> IdentifierName
554%type <variable_> IdentifierReference
555%type <statement_> IfStatement
556%type <target_> IndirectExpression
557%type <expression_> Initializer
558%type <expression_> InitializerOpt
559%type <statement_> IterationStatement
560%type <identifier_> LabelIdentifier
561%type <statement_> LabelledItem
562%type <statement_> LabelledStatement
563%type <assignment_> LeftHandSideAssignment
564%type <target_> LeftHandSideExpression
565%type <bool_> LetOrConst
566%type <binding_> LexicalBinding
567%type <for_> LexicalDeclaration_
568%type <statement_> LexicalDeclaration
569%type <literal_> Literal
570%type <propertyName_> LiteralPropertyName
571%type <expression_> LogicalANDExpression
572%type <expression_> LogicalORExpression
573%type <access_> MemberAccess
574%type <target_> MemberExpression
575%type <method_> MethodDefinition
576%type <module_> ModulePath
577%type <expression_> MultiplicativeExpression
578%type <target_> NewExpression
579%type <null_> NullLiteral
580%type <literal_> ObjectLiteral
581%type <expression_> PostfixExpression
582%type <target_> PrimaryExpression
583%type <propertyName_> PropertyName
584%type <property_> PropertyDefinition
585%type <property_> PropertyDefinitionList_
586%type <property_> PropertyDefinitionList
587%type <property_> PropertyDefinitionListOpt
588%type <functionParameter_> PropertySetParameterList
589%type <literal_> RegularExpressionLiteral
590%type <bool_> RegularExpressionSlash
591%type <expression_> RelationalExpression
592%type <statement_> ReturnStatement
593%type <target_> RubyBlockExpression_
594%type <target_> RubyBlockExpression
595%type <rubyProc_> RubyProcExpression
596%type <functionParameter_> RubyProcParameterList_
597%type <functionParameter_> RubyProcParameterList
598%type <functionParameter_> RubyProcParameters
599%type <functionParameter_> RubyProcParametersOpt
600%type <statement_> Script
601%type <statement_> ScriptBody
602%type <statement_> ScriptBodyOpt
603%type <expression_> ShiftExpression
604%type <binding_> SingleNameBinding
605%type <statement_> Statement__
606%type <statement_> Statement_
607%type <statement_> Statement
608%type <statement_> StatementList
609%type <statement_> StatementListOpt
610%type <statement_> StatementListItem
611%type <functionParameter_> StrictFormalParameters
612%type <target_> SuperCall
613%type <target_> SuperProperty
614%type <statement_> SwitchStatement
615%type <target_> TemplateLiteral
616%type <span_> TemplateSpans
617%type <statement_> ThrowStatement
618%type <statement_> TryStatement
619%type <statement_> TypeDefinition
620%type <expression_> UnaryExpression_
621%type <expression_> UnaryExpression
622%type <binding_> VariableDeclaration
623%type <bindings_> VariableDeclarationList_
624%type <bindings_> VariableDeclarationList
625%type <for_> VariableStatement_
626%type <statement_> VariableStatement
627%type <statement_> WithStatement
628%type <word_> Word
629@begin ObjectiveC
630%type <word_> WordOpt
631@end
632%type <expression_> YieldExpression
633
634@begin C
635%type <specifier_> IntegerType
636%type <specifier_> IntegerTypeOpt
637%type <typedIdentifier_> PrefixedType
638%type <specifier_> PrimitiveType
639%type <structField_> StructFieldListOpt
640%type <typedIdentifier_> SuffixedType
641%type <typedIdentifier_> SuffixedTypeOpt
642%type <typedIdentifier_> TypeSignifier
643%type <typedIdentifier_> TypeSignifierOpt
644%type <modifier_> TypeQualifierLeft
645%type <modifier_> TypeQualifierLeftOpt
646%type <typedIdentifier_> TypeQualifierRight
647%type <typedIdentifier_> TypeQualifierRightOpt
648%type <typedIdentifier_> TypedIdentifierMaybe
649%type <typedIdentifier_> TypedIdentifierNo
650%type <typedIdentifier_> TypedIdentifierYes
651%type <typedParameter_> TypedParameterList_
652%type <typedParameter_> TypedParameterList
653%type <typedParameter_> TypedParameterListOpt
654@end
655
656@begin ObjectiveC
657%type <expression_> AssignmentExpressionClassic
658%type <expression_> BoxableExpression
659%type <statement_> CategoryStatement
660%type <expression_> ClassSuperOpt
661%type <expression_> ConditionalExpressionClassic
662%type <message_> ClassMessageDeclaration
663%type <message_> ClassMessageDeclarationListOpt
664%type <protocol_> ClassProtocolListOpt
665%type <protocol_> ClassProtocols
666%type <protocol_> ClassProtocolsOpt
667%type <implementationField_> ImplementationFieldListOpt
668%type <statement_> ImplementationStatement
669%type <target_> MessageExpression
670%type <messageParameter_> MessageParameter
671%type <messageParameter_> MessageParameters
672%type <messageParameter_> MessageParameterList
673%type <messageParameter_> MessageParameterListOpt
674%type <bool_> MessageScope
675%type <argument_> SelectorCall_
676%type <argument_> SelectorCall
677%type <selector_> SelectorExpression_
678%type <selector_> SelectorExpression
679%type <selector_> SelectorExpressionOpt
680%type <argument_> SelectorList
681%type <word_> SelectorWordOpt
682%type <typedIdentifier_> TypeOpt
683%type <argument_> VariadicCall
684@end
685
686@begin E4X
687%type <propertyIdentifier_> PropertyIdentifier_
688%type <selector_> PropertySelector_
689%type <selector_> PropertySelector
690%type <identifier_> QualifiedIdentifier_
691%type <identifier_> QualifiedIdentifier
692%type <identifier_> WildcardIdentifier
693%type <identifier_> XMLComment
694%type <identifier_> XMLCDATA
695%type <identifier_> XMLElement
696%type <identifier_> XMLElementContent
697%type <identifier_> XMLMarkup
698%type <identifier_> XMLPI
699
700%type <attribute_> AttributeIdentifier
701/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
702%type <expression_> PropertyIdentifier
703%type <expression_> XMLListInitilizer
704%type <expression_> XMLInitilizer
705@end
706/* }}} */
707/* Token Priorities {{{ */
708%nonassoc "if"
709%nonassoc "else"
710/* }}} */
711
712%start Program
713%token MarkModule
714%token MarkScript
715
716%%
717
718Program
719 : MarkScript Script
720 | MarkModule Module
721 ;
722
723/* Lexer State {{{ */
724LexPushInOn: { driver.in_.push(true); };
725LexPushInOff: { driver.in_.push(false); };
726LexPopIn: { driver.in_.pop(); };
727
728LexPushReturnOn: { driver.return_.push(true); };
729LexPopReturn: { driver.return_.pop(); };
730Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
731
732LexPushSuperOn: { driver.super_.push(true); };
733LexPushSuperOff: { driver.super_.push(false); };
734LexPopSuper: { driver.super_.pop(); };
735Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
736
737LexPushYieldOn: { driver.yield_.push(true); };
738LexPushYieldOff: { driver.yield_.push(false); };
739LexPopYield: { driver.yield_.pop(); };
740
741LexNewLineOrOpt
742 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
743 ;
744
745LexNewLineOrNot
746 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
747 ;
748
749LexNoStar
750 : { CYMAP(YieldStar, Star); }
751 ;
752
753LexNoBrace
754 : { CYMAP(OpenBrace_, OpenBrace); }
755 ;
756
757LexNoClass
758 : { CYMAP(_class__, _class_); }
759 ;
760
761LexNoFunction
762 : { CYMAP(_function__, _function_); }
763 ;
764
765LexSetStatement
766 : LexNoBrace LexNoClass LexNoFunction
767 ;
768/* }}} */
769/* Virtual Tokens {{{ */
770Var_
771 : "var"
772 ;
773/* }}} */
774
775/* 11.6 Names and Keywords {{{ */
776IdentifierName
777 : Word[pass] { $$ = $pass; }
778 | "for" { $$ = CYNew CYWord("for"); }
779 | "in" { $$ = CYNew CYWord("in"); }
780 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
781 ;
782
783Word
784 : IdentifierNoOf[pass] { $$ = $pass; }
785 | "break" { $$ = CYNew CYWord("break"); }
786 | "case" { $$ = CYNew CYWord("case"); }
787 | "catch" { $$ = CYNew CYWord("catch"); }
788 | "class" LexOf { $$ = CYNew CYWord("class"); }
789 | ";class" { $$ = CYNew CYWord("class"); }
790 | "const" { $$ = CYNew CYWord("const"); }
791 | "continue" { $$ = CYNew CYWord("continue"); }
792 | "debugger" { $$ = CYNew CYWord("debugger"); }
793 | "default" { $$ = CYNew CYWord("default"); }
794 | "delete" { $$ = CYNew CYWord("delete"); }
795 | "do" { $$ = CYNew CYWord("do"); }
796 | "else" { $$ = CYNew CYWord("else"); }
797 | "enum" { $$ = CYNew CYWord("enum"); }
798 | "export" { $$ = CYNew CYWord("export"); }
799 | "extends" { $$ = CYNew CYWord("extends"); }
800 | "false" { $$ = CYNew CYWord("false"); }
801 | "finally" { $$ = CYNew CYWord("finally"); }
802 | "function" LexOf { $$ = CYNew CYWord("function"); }
803 | "if" { $$ = CYNew CYWord("if"); }
804 | "import" { $$ = CYNew CYWord("import"); }
805 | "!in" { $$ = CYNew CYWord("in"); }
806 | "!of" { $$ = CYNew CYWord("of"); }
807 | "new" { $$ = CYNew CYWord("new"); }
808 | "null" { $$ = CYNew CYWord("null"); }
809 | "return" { $$ = CYNew CYWord("return"); }
810 | "super" { $$ = CYNew CYWord("super"); }
811 | "switch" { $$ = CYNew CYWord("switch"); }
812 | "this" { $$ = CYNew CYWord("this"); }
813 | "throw" { $$ = CYNew CYWord("throw"); }
814 | "true" { $$ = CYNew CYWord("true"); }
815 | "try" { $$ = CYNew CYWord("try"); }
816 | "typeof" { $$ = CYNew CYWord("typeof"); }
817 | "var" { $$ = CYNew CYWord("var"); }
818 | "void" { $$ = CYNew CYWord("void"); }
819 | "while" { $$ = CYNew CYWord("while"); }
820 | "with" { $$ = CYNew CYWord("with"); }
821 | "yield" { $$ = CYNew CYIdentifier("yield"); }
822 ;
823
824@begin ObjectiveC
825WordOpt
826 : Word[pass] { $$ = $pass; }
827 | { $$ = NULL; }
828 ;
829@end
830/* }}} */
831/* 11.8.1 Null Literals {{{ */
832NullLiteral
833 : "null" { $$ = CYNew CYNull(); }
834 ;
835/* }}} */
836/* 11.8.2 Boolean Literals {{{ */
837BooleanLiteral
838 : "true" { $$ = CYNew CYTrue(); }
839 | "false" { $$ = CYNew CYFalse(); }
840 ;
841/* }}} */
842/* 11.8.5 Regular Expression Literals {{{ */
843RegularExpressionSlash
844 : "/" { $$ = false; }
845 | "/=" { $$ = true; }
846 ;
847
848RegularExpressionLiteral
849 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
850 ;
851/* }}} */
852
853/* 11.9 Automatic Semicolon Insertion {{{ */
854StrictSemi
855 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
856 ;
857
858NewLineNot
859 : LexNewLineOrNot ""
860 ;
861
862NewLineOpt
863 : LexNewLineOrNot "\n"
864 | NewLineNot
865 ;
866
867TerminatorSoft
868 : LexNewLineOrNot "\n" StrictSemi
869 | NewLineNot LexOf Terminator
870 ;
871
872TerminatorHard
873 : ";"
874 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
875 ;
876
877Terminator
878 : ";"
879 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
880 ;
881
882TerminatorOpt
883 : ";"
884 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
885 ;
886/* }}} */
887
888/* 12.1 Identifiers {{{ */
889IdentifierReference
890 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
891 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
892 ;
893
894BindingIdentifier
895 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
896 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
897 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
898 ;
899
900BindingIdentifierOpt
901 : BindingIdentifier[pass] { $$ = $pass; }
902 | LexOf { $$ = NULL; }
903 ;
904
905LabelIdentifier
906 : Identifier[pass] { $$ = $pass; }
907 | "yield" { $$ = CYNew CYIdentifier("yield"); }
908 ;
909
910IdentifierTypeNoOf
911 : Identifier_[pass] { $$ = $pass; }
912 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
913 | "await" { $$ = CYNew CYIdentifier("await"); }
914 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
915 | "byte" { $$ = CYNew CYIdentifier("byte"); }
916 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
917 | "double" { $$ = CYNew CYIdentifier("double"); }
918 | "each" { $$ = CYNew CYIdentifier("each"); }
919 | "eval" { $$ = CYNew CYIdentifier("eval"); }
920 | "final" { $$ = CYNew CYIdentifier("final"); }
921 | "float" { $$ = CYNew CYIdentifier("float"); }
922 | "from" { $$ = CYNew CYIdentifier("from"); }
923 | "get" { $$ = CYNew CYIdentifier("get"); }
924 | "goto" { $$ = CYNew CYIdentifier("goto"); }
925 | "implements" { $$ = CYNew CYIdentifier("implements"); }
926 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
927 | "interface" { $$ = CYNew CYIdentifier("interface"); }
928 | "let" { $$ = CYNew CYIdentifier("let"); }
929 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
930 | "native" { $$ = CYNew CYIdentifier("native"); }
931 | "package" { $$ = CYNew CYIdentifier("package"); }
932 | "private" { $$ = CYNew CYIdentifier("private"); }
933 | "protected" { $$ = CYNew CYIdentifier("protected"); }
934 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
935 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
936 | "public" { $$ = CYNew CYIdentifier("public"); }
937 | "set" { $$ = CYNew CYIdentifier("set"); }
938 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
939 | "target" { $$ = CYNew CYIdentifier("target"); }
940 | "throws" { $$ = CYNew CYIdentifier("throws"); }
941 | "transient" { $$ = CYNew CYIdentifier("transient"); }
942 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
943@begin ObjectiveC
944 | "bool" { $$ = CYNew CYIdentifier("bool"); }
945 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
946 | "id" { $$ = CYNew CYIdentifier("id"); }
947 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
948@end
949 ;
950
951IdentifierType
952 : IdentifierTypeNoOf[pass] { $$ = $pass; }
953 | "of" { $$ = CYNew CYIdentifier("of"); }
954 ;
955
956IdentifierTypeOpt
957 : IdentifierType[pass] { $$ = $pass; }
958 | { $$ = NULL; }
959 ;
960
961IdentifierNoOf
962 : IdentifierTypeNoOf
963 | "char" { $$ = CYNew CYIdentifier("char"); }
964 | "int" { $$ = CYNew CYIdentifier("int"); }
965 | "long" { $$ = CYNew CYIdentifier("long"); }
966 | "short" { $$ = CYNew CYIdentifier("short"); }
967 | "static" { $$ = CYNew CYIdentifier("static"); }
968 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
969@begin C
970 | "signed" { $$ = CYNew CYIdentifier("signed"); }
971 | "struct" { $$ = CYNew CYIdentifier("struct"); }
972 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
973@end
974@begin ObjectiveC
975 | "nil" { $$ = CYNew CYIdentifier("nil"); }
976 | "NO" { $$ = CYNew CYIdentifier("NO"); }
977 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
978 | "YES" { $$ = CYNew CYIdentifier("YES"); }
979@end
980 ;
981
982Identifier
983 : IdentifierNoOf[pass] { $$ = $pass; }
984 | "of" { $$ = CYNew CYIdentifier("of"); }
985 | "!of" { $$ = CYNew CYIdentifier("of"); }
986 ;
987/* }}} */
988/* 12.2 Primary Expression {{{ */
989PrimaryExpression
990 : "this" { $$ = CYNew CYThis(); }
991 | IdentifierReference[pass] { $$ = $pass; }
992 | Literal[pass] { $$ = $pass; }
993 | ArrayLiteral[pass] { $$ = $pass; }
994 | ObjectLiteral[pass] { $$ = $pass; }
995 | FunctionExpression[pass] { $$ = $pass; }
996 | ClassExpression[pass] { $$ = $pass; }
997 | GeneratorExpression[pass] { $$ = $pass; }
998 | RegularExpressionLiteral[pass] { $$ = $pass; }
999 | TemplateLiteral[pass] { $$ = $pass; }
1000 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1001 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1002 ;
1003
1004CoverParenthesizedExpressionAndArrowParameterList
1005 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1006 | "(" LexOf ")" { $$ = NULL; }
1007 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1008 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1009 ;
1010/* }}} */
1011/* 12.2.4 Literals {{{ */
1012Literal
1013 : NullLiteral[pass] { $$ = $pass; }
1014 | BooleanLiteral[pass] { $$ = $pass; }
1015 | NumericLiteral[pass] { $$ = $pass; }
1016 | StringLiteral[pass] { $$ = $pass; }
1017 ;
1018/* }}} */
1019/* 12.2.5 Array Initializer {{{ */
1020ArrayLiteral
1021 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1022 ;
1023
1024ElementList
1025 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1026 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1027 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1028 ;
1029
1030ElementListOpt
1031 : ElementList[pass] { $$ = $pass; }
1032 | LexOf { $$ = NULL; }
1033 ;
1034/* }}} */
1035/* 12.2.6 Object Initializer {{{ */
1036ObjectLiteral
1037 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1038 ;
1039
1040PropertyDefinitionList_
1041 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1042 | { $$ = NULL; }
1043 ;
1044
1045PropertyDefinitionList
1046 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1047 ;
1048
1049PropertyDefinitionListOpt
1050 : PropertyDefinitionList[properties] { $$ = $properties; }
1051 | { $$ = NULL; }
1052 ;
1053
1054PropertyDefinition
1055 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1056 | CoverInitializedName[name] { CYNOT(@$); }
1057 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1058 | MethodDefinition[pass] { $$ = $pass; }
1059 ;
1060
1061PropertyName
1062 : LiteralPropertyName[pass] { $$ = $pass; }
1063 | ComputedPropertyName[pass] { $$ = $pass; }
1064 ;
1065
1066LiteralPropertyName
1067 : IdentifierName[pass] { $$ = $pass; }
1068 | StringLiteral[pass] { $$ = $pass; }
1069 | NumericLiteral[pass] { $$ = $pass; }
1070 ;
1071
1072ComputedPropertyName
1073 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1074 ;
1075
1076CoverInitializedName
1077 : IdentifierReference Initializer
1078 ;
1079
1080Initializer
1081 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1082 ;
1083
1084InitializerOpt
1085 : Initializer[pass] { $$ = $pass; }
1086 | { $$ = NULL; }
1087 ;
1088/* }}} */
1089/* 12.2.9 Template Literals {{{ */
1090TemplateLiteral
1091 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1092 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1093 ;
1094
1095TemplateSpans
1096 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1097 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1098 ;
1099/* }}} */
1100
1101/* 12.3 Left-Hand-Side Expressions {{{ */
1102MemberAccess
1103 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1104 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1105 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1106 | TemplateLiteral { CYNOT(@$); }
1107 ;
1108
1109MemberExpression
1110 : PrimaryExpression[pass] { $$ = $pass; }
1111 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1112 | SuperProperty[pass] { $$ = $pass; }
1113 | MetaProperty { CYNOT(@$); }
1114 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1115 ;
1116
1117SuperProperty
1118 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1119 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1120 ;
1121
1122MetaProperty
1123 : NewTarget
1124 ;
1125
1126NewTarget
1127 : "new" "." "target"
1128 ;
1129
1130NewExpression
1131 : MemberExpression[pass] { $$ = $pass; }
1132 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1133 ;
1134
1135CallExpression_
1136 : MemberExpression[pass] { $$ = $pass; }
1137 | CallExpression[pass] { $$ = $pass; }
1138 ;
1139
1140CallExpression
1141 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1142 | SuperCall[pass] { $$ = $pass; }
1143 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1144 ;
1145
1146SuperCall
1147 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1148 ;
1149
1150Arguments
1151 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1152 ;
1153
1154ArgumentList_
1155 : "," ArgumentList[arguments] { $$ = $arguments; }
1156 | { $$ = NULL; }
1157 ;
1158
1159ArgumentList
1160 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1161 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1162 ;
1163
1164ArgumentListOpt
1165 : ArgumentList[pass] { $$ = $pass; }
1166 | LexOf { $$ = NULL; }
1167 ;
1168
1169AccessExpression
1170 : NewExpression[pass] { $$ = $pass; }
1171 | CallExpression[pass] { $$ = $pass; }
1172 ;
1173
1174LeftHandSideExpression
1175 : RubyBlockExpression[pass] { $$ = $pass; }
1176 | IndirectExpression[pass] { $$ = $pass; }
1177 ;
1178/* }}} */
1179/* 12.4 Postfix Expressions {{{ */
1180PostfixExpression
1181 : RubyBlockExpression[pass] { $$ = $pass; }
1182 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1183 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1184 ;
1185/* }}} */
1186/* 12.5 Unary Operators {{{ */
1187UnaryExpression_
1188 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1189 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1190 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1191 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1192 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1193 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1194 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1195 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1196 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1197 ;
1198
1199UnaryExpression
1200 : PostfixExpression[expression] { $$ = $expression; }
1201 | UnaryExpression_[pass] { $$ = $pass; }
1202 ;
1203/* }}} */
1204/* 12.6 Multiplicative Operators {{{ */
1205MultiplicativeExpression
1206 : UnaryExpression[pass] { $$ = $pass; }
1207 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1208 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1209 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1210 ;
1211/* }}} */
1212/* 12.7 Additive Operators {{{ */
1213AdditiveExpression
1214 : MultiplicativeExpression[pass] { $$ = $pass; }
1215 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1216 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1217 ;
1218/* }}} */
1219/* 12.8 Bitwise Shift Operators {{{ */
1220ShiftExpression
1221 : AdditiveExpression[pass] { $$ = $pass; }
1222 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1223 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1224 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1225 ;
1226/* }}} */
1227/* 12.9 Relational Operators {{{ */
1228RelationalExpression
1229 : ShiftExpression[pass] { $$ = $pass; }
1230 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1231 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1232 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1233 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1234 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1235 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1236 ;
1237/* }}} */
1238/* 12.10 Equality Operators {{{ */
1239EqualityExpression
1240 : RelationalExpression[pass] { $$ = $pass; }
1241 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1242 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1243 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1244 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1245 ;
1246/* }}} */
1247/* 12.11 Binary Bitwise Operators {{{ */
1248BitwiseANDExpression
1249 : EqualityExpression[pass] { $$ = $pass; }
1250 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1251 ;
1252
1253BitwiseXORExpression
1254 : BitwiseANDExpression[pass] { $$ = $pass; }
1255 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1256 ;
1257
1258BitwiseORExpression
1259 : BitwiseXORExpression[pass] { $$ = $pass; }
1260 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1261 ;
1262/* }}} */
1263/* 12.12 Binary Logical Operators {{{ */
1264LogicalANDExpression
1265 : BitwiseORExpression[pass] { $$ = $pass; }
1266 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1267 ;
1268
1269LogicalORExpression
1270 : LogicalANDExpression[pass] { $$ = $pass; }
1271 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1272 ;
1273/* }}} */
1274/* 12.13 Conditional Operator ( ? : ) {{{ */
1275@begin ObjectiveC
1276ConditionalExpressionClassic
1277 : LogicalORExpression[pass] { $$ = $pass; }
1278 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1279 ;
1280@end
1281
1282ConditionalExpression
1283 : LogicalORExpression[pass] { $$ = $pass; }
1284 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1285 ;
1286/* }}} */
1287/* 12.14 Assignment Operators {{{ */
1288LeftHandSideAssignment
1289 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1290 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1291 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1292 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1293 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1294 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1295 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1296 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1297 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1298 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1299 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1300 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1301 ;
1302
1303@begin ObjectiveC
1304AssignmentExpressionClassic
1305 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1306 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1307 ;
1308@end
1309
1310AssignmentExpression
1311 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1312 | LexOf YieldExpression[pass] { $$ = $pass; }
1313 | ArrowFunction[pass] { $$ = $pass; }
1314 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1315 ;
1316
1317AssignmentExpressionOpt
1318 : AssignmentExpression[pass] { $$ = $pass; }
1319 | LexOf { $$ = NULL; }
1320 ;
1321/* }}} */
1322/* 12.15 Comma Operator ( , ) {{{ */
1323Expression
1324 : AssignmentExpression[pass] { $$ = $pass; }
1325 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1326 ;
1327
1328ExpressionOpt
1329 : Expression[pass] { $$ = $pass; }
1330 | LexOf { $$ = NULL; }
1331 ;
1332/* }}} */
1333
1334/* 13 Statements and Declarations {{{ */
1335Statement__
1336 : BlockStatement[pass] { $$ = $pass; }
1337 | VariableStatement[pass] { $$ = $pass; }
1338 | EmptyStatement[pass] { $$ = $pass; }
1339 | IfStatement[pass] { $$ = $pass; }
1340 | BreakableStatement[pass] { $$ = $pass; }
1341 | ContinueStatement[pass] { $$ = $pass; }
1342 | BreakStatement[pass] { $$ = $pass; }
1343 | ReturnStatement[pass] { $$ = $pass; }
1344 | WithStatement[pass] { $$ = $pass; }
1345 | LabelledStatement[pass] { $$ = $pass; }
1346 | ThrowStatement[pass] { $$ = $pass; }
1347 | TryStatement[pass] { $$ = $pass; }
1348 | DebuggerStatement[pass] { $$ = $pass; }
1349 ;
1350
1351Statement_
1352 : LexOf Statement__[pass] { $$ = $pass; }
1353 | ExpressionStatement[pass] { $$ = $pass; }
1354 ;
1355
1356Statement
1357 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1358 ;
1359
1360Declaration_
1361 : HoistableDeclaration[pass] { $$ = $pass; }
1362 | ClassDeclaration[pass] { $$ = $pass; }
1363 ;
1364
1365Declaration
1366 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1367 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1368 ;
1369
1370HoistableDeclaration
1371 : FunctionDeclaration[pass] { $$ = $pass; }
1372 | GeneratorDeclaration[pass] { $$ = $pass; }
1373 ;
1374
1375BreakableStatement
1376 : IterationStatement[pass] { $$ = $pass; }
1377 | SwitchStatement[pass] { $$ = $pass; }
1378 ;
1379/* }}} */
1380/* 13.2 Block {{{ */
1381BlockStatement
1382 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1383 ;
1384
1385Block
1386 : "{" StatementListOpt[code] "}" { $$ = $code; }
1387 ;
1388
1389StatementList
1390 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1391 ;
1392
1393StatementListOpt
1394 : StatementList[pass] { $$ = $pass; }
1395 | LexSetStatement LexLet LexOf { $$ = NULL; }
1396 ;
1397
1398StatementListItem
1399 : Statement[pass] { $$ = $pass; }
1400 | Declaration[pass] { $$ = $pass; }
1401 ;
1402/* }}} */
1403/* 13.3 Let and Const Declarations {{{ */
1404LexicalDeclaration_
1405 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1406 ;
1407
1408LexicalDeclaration
1409 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1410 ;
1411
1412LexLet
1413 : { CYMAP(_let__, _let_); }
1414 ;
1415
1416LexOf
1417 : { CYMAP(_of__, _of_); }
1418 ;
1419
1420LexBind
1421 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1422 ;
1423
1424LetOrConst
1425 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1426 | LexLet LexOf "const" { $$ = true; }
1427 ;
1428
1429BindingList_
1430 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1431 | { $$ = NULL; }
1432 ;
1433
1434BindingList
1435 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1436 ;
1437
1438LexicalBinding
1439 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1440 | LexOf BindingPattern Initializer { CYNOT(@$); }
1441 ;
1442/* }}} */
1443/* 13.3.2 Variable Statement {{{ */
1444VariableStatement_
1445 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1446 ;
1447
1448VariableStatement
1449 : VariableStatement_[statement] Terminator { $$ = $statement; }
1450 ;
1451
1452VariableDeclarationList_
1453 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1454 | { $$ = NULL; }
1455 ;
1456
1457VariableDeclarationList
1458 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1459 ;
1460
1461VariableDeclaration
1462 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1463 | LexOf BindingPattern Initializer { CYNOT(@$); }
1464 ;
1465/* }}} */
1466/* 13.3.3 Destructuring Binding Patterns {{{ */
1467BindingPattern
1468 : ObjectBindingPattern
1469 | ArrayBindingPattern
1470 ;
1471
1472ObjectBindingPattern
1473 : "let {" BindingPropertyListOpt "}"
1474 ;
1475
1476ArrayBindingPattern
1477 : "let [" BindingElementListOpt "]"
1478 ;
1479
1480BindingPropertyList_
1481 : "," BindingPropertyListOpt
1482 |
1483 ;
1484
1485BindingPropertyList
1486 : BindingProperty BindingPropertyList_
1487 ;
1488
1489BindingPropertyListOpt
1490 : BindingPropertyList
1491 | LexOf
1492 ;
1493
1494BindingElementList
1495 : BindingElementOpt[element] "," BindingElementListOpt[next]
1496 | BindingRestElement[element]
1497 | BindingElement[element]
1498 ;
1499
1500BindingElementListOpt
1501 : BindingElementList[pass]
1502 | LexBind LexOf
1503 ;
1504
1505BindingProperty
1506 : SingleNameBinding
1507 | LexOf PropertyName ":" BindingElement
1508 ;
1509
1510BindingElement
1511 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1512 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1513 ;
1514
1515BindingElementOpt
1516 : BindingElement[pass]
1517 | LexBind LexOf
1518 ;
1519
1520SingleNameBinding
1521 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1522 ;
1523
1524BindingRestElement
1525 : LexBind LexOf "..." BindingIdentifier
1526 ;
1527/* }}} */
1528/* 13.4 Empty Statement {{{ */
1529EmptyStatement
1530 : ";" { $$ = CYNew CYEmpty(); }
1531 ;
1532/* }}} */
1533/* 13.5 Expression Statement {{{ */
1534ExpressionStatement_
1535 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1536
1537ExpressionStatement
1538 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1539 ;
1540/* }}} */
1541/* 13.6 The if Statement {{{ */
1542ElseStatementOpt
1543 : "else" Statement[false] { $$ = $false; }
1544 | %prec "if" { $$ = NULL; }
1545 ;
1546
1547IfStatement
1548 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1549 ;
1550/* }}} */
1551/* 13.7 Iteration Statements {{{ */
1552IterationStatement
1553 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1554 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1555 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1556 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1557 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1558 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1559 ;
1560
1561ForStatementInitializer
1562 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1563 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1564 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1565 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1566 ;
1567
1568ForInStatementInitializer
1569 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1570 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1571 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1572 | ForDeclaration[pass] { $$ = $pass; }
1573 ;
1574
1575ForDeclaration
1576 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1577 ;
1578
1579ForBinding
1580 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1581 | LexOf BindingPattern { CYNOT(@$); }
1582 ;
1583/* }}} */
1584/* 13.8 The continue Statement {{{ */
1585ContinueStatement
1586 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1587 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1588 ;
1589/* }}} */
1590/* 13.9 The break Statement {{{ */
1591BreakStatement
1592 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1593 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1594 ;
1595/* }}} */
1596/* 13.10 The return Statement {{{ */
1597ReturnStatement
1598 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1599 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1600 ;
1601/* }}} */
1602/* 13.11 The with Statement {{{ */
1603WithStatement
1604 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1605 ;
1606/* }}} */
1607/* 13.12 The switch Statement {{{ */
1608SwitchStatement
1609 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1610 ;
1611
1612CaseBlock
1613 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1614 ;
1615
1616CaseClause
1617 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1618 ;
1619
1620CaseClausesOpt
1621 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1622 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1623 | { $$ = NULL; }
1624 ;
1625
1626// XXX: the standard makes certain you can only have one of these
1627DefaultClause
1628 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1629 ;
1630/* }}} */
1631/* 13.13 Labelled Statements {{{ */
1632LabelledStatement
1633 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1634 ;
1635
1636LabelledItem
1637 : Statement[pass] { $$ = $pass; }
1638 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1639 ;
1640/* }}} */
1641/* 13.14 The throw Statement {{{ */
1642ThrowStatement
1643 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1644 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1645 ;
1646/* }}} */
1647/* 13.15 The try Statement {{{ */
1648TryStatement
1649 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1650 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1651 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1652 ;
1653
1654Catch
1655 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1656 ;
1657
1658Finally
1659 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1660 ;
1661
1662CatchParameter
1663 : BindingIdentifier[pass] { $$ = $pass; }
1664 | LexOf BindingPattern { CYNOT(@$); }
1665 ;
1666/* }}} */
1667/* 13.16 The debugger Statement {{{ */
1668DebuggerStatement
1669 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1670 ;
1671/* }}} */
1672
1673/* 14.1 Function Definitions {{{ */
1674FunctionDeclaration
1675 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1676 ;
1677
1678FunctionExpression
1679 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1680 ;
1681
1682StrictFormalParameters
1683 : FormalParameters[pass] { $$ = $pass; }
1684 ;
1685
1686FormalParameters
1687 : LexBind LexOf { $$ = NULL; }
1688 | FormalParameterList
1689 ;
1690
1691FormalParameterList_
1692 : "," FormalParameterList[parameters] { $$ = $parameters; }
1693 | { $$ = NULL; }
1694 ;
1695
1696FormalParameterList
1697 : FunctionRestParameter { CYNOT(@$); }
1698 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1699 ;
1700
1701FunctionRestParameter
1702 : BindingRestElement
1703 ;
1704
1705FormalParameter
1706 : BindingElement[pass] { $$ = $pass; }
1707 ;
1708
1709FunctionBody
1710 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1711 ;
1712
1713FunctionStatementList
1714 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1715 ;
1716/* }}} */
1717/* 14.2 Arrow Function Definitions {{{ */
1718ArrowFunction
1719 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1720 ;
1721
1722ArrowParameters
1723 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1724 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1725 ;
1726
1727ConciseBody
1728 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1729 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1730 ;
1731/* }}} */
1732/* 14.3 Method Definitions {{{ */
1733MethodDefinition
1734 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1735 | GeneratorMethod[pass] { $$ = $pass; }
1736 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1737 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1738 ;
1739
1740PropertySetParameterList
1741 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1742 ;
1743/* }}} */
1744/* 14.4 Generator Function Definitions {{{ */
1745GeneratorMethod
1746 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1747 ;
1748
1749GeneratorDeclaration
1750 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1751 ;
1752
1753GeneratorExpression
1754 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1755 ;
1756
1757GeneratorBody
1758 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1759 ;
1760
1761YieldExpression
1762 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1763 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1764 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1765 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1766 ;
1767/* }}} */
1768/* 14.5 Class Definitions {{{ */
1769ClassDeclaration
1770 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1771 ;
1772
1773ClassExpression
1774 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1775 ;
1776
1777ClassTail
1778 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1779 ;
1780
1781ClassHeritage
1782 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1783 ;
1784
1785ClassHeritageOpt
1786 : ClassHeritage[pass] { $$ = $pass; }
1787 | { $$ = CYNew CYClassTail(NULL); }
1788 ;
1789
1790ClassBody
1791 : ClassElementList
1792 ;
1793
1794ClassBodyOpt
1795 : ClassBody
1796 |
1797 ;
1798
1799ClassElementList
1800 : ClassElementListOpt ClassElement
1801 ;
1802
1803ClassElementListOpt
1804 : ClassElementList
1805 |
1806 ;
1807
1808ClassElement
1809 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1810 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1811 | ";"
1812 ;
1813/* }}} */
1814
1815/* 15.1 Scripts {{{ */
1816Script
1817 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1818 ;
1819
1820ScriptBody
1821 : StatementList[pass] { $$ = $pass; }
1822 ;
1823
1824ScriptBodyOpt
1825 : ScriptBody[pass] { $$ = $pass; }
1826 | LexSetStatement LexLet LexOf { $$ = NULL; }
1827 ;
1828/* }}} */
1829/* 15.2 Modules {{{ */
1830Module
1831 : ModuleBodyOpt
1832 ;
1833
1834ModuleBody
1835 : ModuleItemList
1836 ;
1837
1838ModuleBodyOpt
1839 : ModuleBody
1840 |
1841 ;
1842
1843ModuleItemList
1844 : ModuleItemListOpt ModuleItem
1845 ;
1846
1847ModuleItemListOpt
1848 : ModuleItemList
1849 |
1850 ;
1851
1852ModuleItem
1853 : LexSetStatement LexLet LexOf ImportDeclaration
1854 | LexSetStatement LexLet LexOf ExportDeclaration
1855 | StatementListItem
1856 ;
1857/* }}} */
1858/* 15.2.2 Imports {{{ */
1859ImportDeclaration
1860 : "import" ImportClause FromClause Terminator
1861 | "import" LexOf ModuleSpecifier Terminator
1862 ;
1863
1864ImportClause
1865 : ImportedDefaultBinding
1866 | LexOf NameSpaceImport
1867 | LexOf NamedImports
1868 | ImportedDefaultBinding "," NameSpaceImport
1869 | ImportedDefaultBinding "," NamedImports
1870 ;
1871
1872ImportedDefaultBinding
1873 : ImportedBinding
1874 ;
1875
1876NameSpaceImport
1877 : "*" "as" ImportedBinding
1878 ;
1879
1880NamedImports
1881 : "{" ImportsListOpt "}"
1882 ;
1883
1884FromClause
1885 : "from" ModuleSpecifier
1886 ;
1887
1888ImportsList_
1889 : "," ImportsListOpt
1890 |
1891 ;
1892
1893ImportsList
1894 : ImportSpecifier ImportsList_
1895 ;
1896
1897ImportsListOpt
1898 : ImportsList
1899 | LexOf
1900 ;
1901
1902ImportSpecifier
1903 : ImportedBinding
1904 | LexOf IdentifierName "as" ImportedBinding
1905 ;
1906
1907ModuleSpecifier
1908 : StringLiteral
1909 ;
1910
1911ImportedBinding
1912 : BindingIdentifier
1913 ;
1914/* }}} */
1915/* 15.2.3 Exports {{{ */
1916ExportDeclaration_
1917 : "*" FromClause Terminator
1918 | ExportClause FromClause Terminator
1919 | ExportClause Terminator
1920 | VariableStatement
1921 | "default" LexSetStatement LexOf HoistableDeclaration
1922 | "default" LexSetStatement LexOf ClassDeclaration
1923 | "default" LexSetStatement AssignmentExpression Terminator
1924 ;
1925
1926ExportDeclaration
1927 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1928 | "export" Declaration
1929 ;
1930
1931ExportClause
1932 : ";{" ExportsListOpt "}"
1933 ;
1934
1935ExportsList_
1936 : "," ExportsListOpt
1937 |
1938 ;
1939
1940ExportsList
1941 : ExportSpecifier ExportsList_
1942 ;
1943
1944ExportsListOpt
1945 : ExportsList
1946 |
1947 ;
1948
1949ExportSpecifier
1950 : IdentifierName
1951 | IdentifierName "as" IdentifierName
1952 ;
1953/* }}} */
1954
1955@begin C
1956/* Cycript (C): Type Encoding {{{ */
1957TypeSignifier
1958 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1959 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1960 ;
1961
1962TypeSignifierOpt
1963 : TypeSignifier[pass] { $$ = $pass; }
1964 | { $$ = CYNew CYTypedIdentifier(@$); }
1965 ;
1966
1967SuffixedType
1968 : SuffixedTypeOpt[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1969 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1970 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1971 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1972 ;
1973
1974SuffixedTypeOpt
1975 : SuffixedType[pass] { $$ = $pass; }
1976 | TypeSignifierOpt[pass] { $$ = $pass; }
1977 ;
1978
1979PrefixedType
1980 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1981 ;
1982
1983TypeQualifierLeft
1984 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
1985 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
1986 ;
1987
1988TypeQualifierLeftOpt
1989 : TypeQualifierLeft[pass] { $$ = $pass; }
1990 | { $$ = NULL; }
1991 ;
1992
1993TypeQualifierRight
1994 : SuffixedType[pass] { $$ = $pass; }
1995 | PrefixedType[pass] { $$ = $pass; }
1996 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1997 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1998 ;
1999
2000TypeQualifierRightOpt
2001 : TypeQualifierRight[pass] { $$ = $pass; }
2002 | TypeSignifierOpt[pass] { $$ = $pass; }
2003 ;
2004
2005IntegerType
2006 : "int" { $$ = CYNew CYTypeVariable("int"); }
2007 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
2008 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
2009 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
2010 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
2011 ;
2012
2013IntegerTypeOpt
2014 : IntegerType[pass] { $$ = $pass; }
2015 | { $$ = CYNew CYTypeVariable("int"); }
2016 ;
2017
2018StructFieldListOpt
2019 : TypedIdentifierMaybe[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2020 | { $$ = NULL; }
2021 ;
2022
2023PrimitiveType
2024 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2025 | IntegerType[pass] { $$ = $pass; }
2026 | "char" { $$ = CYNew CYTypeVariable("char"); }
2027 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
2028 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2029 | "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYTypeStruct($name, $fields); }
2030 ;
2031
2032TypedIdentifierMaybe
2033 : TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2034 | TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2035 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2036 ;
2037
2038TypedIdentifierYes
2039 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2040 ;
2041
2042TypedIdentifierNo
2043 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2044 ;
2045
2046PrimaryExpression
2047 : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2048 ;
2049/* }}} */
2050@end
2051
2052@begin ObjectiveC
2053/* Cycript (Objective-C): @class Declaration {{{ */
2054ClassSuperOpt
2055 /* XXX: why the hell did I choose MemberExpression? */
2056 : ":" MemberExpression[extends] { $$ = $extends; }
2057 | { $$ = NULL; }
2058 ;
2059
2060ImplementationFieldListOpt
2061 : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2062 | { $$ = NULL; }
2063 ;
2064
2065MessageScope
2066 : "+" { $$ = false; }
2067 | "-" { $$ = true; }
2068 ;
2069
2070TypeOpt
2071 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2072 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2073 ;
2074
2075MessageParameter
2076 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2077 ;
2078
2079MessageParameterList
2080 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2081 ;
2082
2083MessageParameterListOpt
2084 : MessageParameterList[pass] { $$ = $pass; }
2085 | { $$ = NULL; }
2086 ;
2087
2088MessageParameters
2089 : MessageParameterList[pass] { $$ = $pass; }
2090 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2091 ;
2092
2093ClassMessageDeclaration
2094 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2095 ;
2096
2097ClassMessageDeclarationListOpt
2098 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2099 | { $$ = NULL; }
2100 ;
2101
2102// XXX: this should be AssignmentExpressionNoRight
2103ClassProtocols
2104 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2105 ;
2106
2107ClassProtocolsOpt
2108 : "," ClassProtocols[protocols] { $$ = $protocols; }
2109 | { $$ = NULL; }
2110 ;
2111
2112ClassProtocolListOpt
2113 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2114 | { $$ = NULL; }
2115 ;
2116
2117ImplementationStatement
2118 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2119 ;
2120
2121CategoryName
2122 : "(" WordOpt ")"
2123 ;
2124
2125CategoryStatement
2126 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2127 ;
2128
2129Statement__
2130 : ImplementationStatement[pass] { $$ = $pass; }
2131 | CategoryStatement[pass] { $$ = $pass; }
2132 ;
2133/* }}} */
2134/* Cycript (Objective-C): Send Message {{{ */
2135VariadicCall
2136 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2137 | { $$ = NULL; }
2138 ;
2139
2140SelectorWordOpt
2141 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2142 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2143 ;
2144
2145SelectorCall_
2146 : SelectorCall[pass] { $$ = $pass; }
2147 | VariadicCall[pass] { $$ = $pass; }
2148 ;
2149
2150SelectorCall
2151 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2152 ;
2153
2154SelectorList
2155 : SelectorCall[pass] { $$ = $pass; }
2156 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2157 ;
2158
2159MessageExpression
2160 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2161 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2162 ;
2163
2164SelectorExpression_
2165 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2166 ;
2167
2168SelectorExpression
2169 : SelectorExpression_[pass] { $$ = $pass; }
2170 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2171 ;
2172
2173SelectorExpressionOpt
2174 : SelectorExpression_[pass] { $$ = $pass; }
2175 | { $$ = NULL; }
2176 ;
2177
2178PrimaryExpression
2179 : MessageExpression[pass] { $$ = $pass; }
2180 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2181 ;
2182/* }}} */
2183@end
2184
2185/* Cycript: @import Directive {{{ */
2186ModulePath
2187 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2188 | Word[part] { $$ = CYNew CYModule($part); }
2189 ;
2190
2191Declaration_
2192 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2193 ;
2194/* }}} */
2195
2196@begin ObjectiveC
2197/* Cycript (Objective-C): Boxed Expressions {{{ */
2198BoxableExpression
2199 : NullLiteral[pass] { $$ = $pass; }
2200 | BooleanLiteral[pass] { $$ = $pass; }
2201 | NumericLiteral[pass] { $$ = $pass; }
2202 | StringLiteral[pass] { $$ = $pass; }
2203 | ArrayLiteral[pass] { $$ = $pass; }
2204 | ObjectLiteral[pass] { $$ = $pass; }
2205 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2206 | "YES" { $$ = CYNew CYTrue(); }
2207 | "NO" { $$ = CYNew CYFalse(); }
2208 ;
2209
2210PrimaryExpression
2211 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2212 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2213 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2214 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2215 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2216 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2217 ;
2218/* }}} */
2219/* Cycript (Objective-C): Block Expressions {{{ */
2220PrimaryExpression
2221 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2222 ;
2223/* }}} */
2224/* Cycript (Objective-C): Instance Literals {{{ */
2225PrimaryExpression
2226 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2227 ;
2228/* }}} */
2229@end
2230
2231@begin C
2232/* Cycript (C): Pointer Indirection/Addressing {{{ */
2233UnaryExpression_
2234 : IndirectExpression[pass] { $$ = $pass; }
2235 ;
2236
2237IndirectExpression
2238 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2239 ;
2240
2241UnaryExpression_
2242 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2243 ;
2244
2245MemberAccess
2246 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2247 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2248 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2249 ;
2250/* }}} */
2251/* Cycript (C): Lambda Expressions {{{ */
2252TypedParameterList_
2253 : "," TypedParameterList[parameters] { $$ = $parameters; }
2254 | { $$ = NULL; }
2255 ;
2256
2257TypedParameterList
2258 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2259 ;
2260
2261TypedParameterListOpt
2262 : TypedParameterList[pass] { $$ = $pass; }
2263 | "void" { $$ = NULL; }
2264 | { $$ = NULL; }
2265 ;
2266
2267PrimaryExpression
2268 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2269 ;
2270/* }}} */
2271/* Cycript (C): Type Definitions {{{ */
2272IdentifierNoOf
2273 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2274 ;
2275
2276TypeDefinition
2277 : "typedef" NewLineNot TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2278 ;
2279
2280Statement__
2281 : TypeDefinition[pass] { $$ = $pass; }
2282 ;
2283
2284PrimaryExpression
2285 : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2286 ;
2287/* }}} */
2288/* Cycript (C): extern "C" {{{ */
2289IdentifierNoOf
2290 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2291 ;
2292
2293ExternCStatement
2294 : TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2295 | TypeDefinition[pass] { $$ = $pass; }
2296 ;
2297
2298ExternCStatementListOpt
2299 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2300 | { $$ = NULL; }
2301 ;
2302
2303ExternC
2304 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2305 | ExternCStatement[pass] { $$ = $pass; }
2306 ;
2307
2308Statement__
2309 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2310 ;
2311/* }}} */
2312
2313@end
2314
2315@begin E4X
2316/* Lexer State {{{ */
2317LexPushRegExp
2318 : { driver.PushCondition(CYDriver::RegExpCondition); }
2319 ;
2320
2321LexPushXMLContent
2322 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2323 ;
2324
2325LexPushXMLTag
2326 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2327 ;
2328
2329LexPop
2330 : { driver.PopCondition(); }
2331 ;
2332
2333LexSetXMLContent
2334 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2335 ;
2336
2337LexSetXMLTag
2338 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2339 ;
2340/* }}} */
2341/* Virtual Tokens {{{ */
2342XMLWhitespaceOpt
2343 : XMLWhitespace
2344 |
2345 ;
2346/* }}} */
2347
2348/* 8.1 Context Keywords {{{ */
2349Identifier
2350 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2351 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2352 ;
2353/* }}} */
2354/* 8.3 XML Initializer Input Elements {{{ */
2355XMLMarkup
2356 : XMLComment { $$ = $1; }
2357 | XMLCDATA { $$ = $1; }
2358 | XMLPI { $$ = $1; }
2359 ;
2360/* }}} */
2361
2362/* 11.1 Primary Expressions {{{ */
2363PrimaryExpression
2364 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2365 | XMLInitilizer { $$ = $1; }
2366 | XMLListInitilizer { $$ = $1; }
2367 ;
2368
2369PropertyIdentifier
2370 : AttributeIdentifier { $$ = $1; }
2371 | QualifiedIdentifier { $$ = $1; }
2372 | WildcardIdentifier { $$ = $1; }
2373 ;
2374/* }}} */
2375/* 11.1.1 Attribute Identifiers {{{ */
2376AttributeIdentifier
2377 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2378 ;
2379
2380PropertySelector_
2381 : PropertySelector { $$ = $1; }
2382 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2383 ;
2384
2385PropertySelector
2386 : Identifier { $$ = CYNew CYSelector($1); }
2387 | WildcardIdentifier { $$ = $1; }
2388 ;
2389/* }}} */
2390/* 11.1.2 Qualified Identifiers {{{ */
2391QualifiedIdentifier_
2392 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2393 | QualifiedIdentifier { $$ = $1; }
2394 ;
2395
2396QualifiedIdentifier
2397 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2398 ;
2399/* }}} */
2400/* 11.1.3 Wildcard Identifiers {{{ */
2401WildcardIdentifier
2402 : "*" { $$ = CYNew CYWildcard(); }
2403 ;
2404/* }}} */
2405/* 11.1.4 XML Initializer {{{ */
2406XMLInitilizer
2407 : XMLMarkup { $$ = $1; }
2408 | XMLElement { $$ = $1; }
2409 ;
2410
2411XMLElement
2412 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2413 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2414 ;
2415
2416XMLTagContent
2417 : LexPushXMLTag XMLTagName XMLAttributes
2418 ;
2419
2420XMLExpression
2421 : "{" LexPushRegExp Expression LexPop "}"
2422 ;
2423
2424XMLTagName
2425 : XMLExpression
2426 | XMLName
2427 ;
2428
2429XMLAttributes_
2430 : XMLAttributes_ XMLAttribute
2431 |
2432 ;
2433
2434XMLAttributes
2435 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2436 | XMLAttributes_ XMLWhitespaceOpt
2437 ;
2438
2439XMLAttributeValue_
2440 : XMLExpression
2441 | XMLAttributeValue
2442 ;
2443
2444XMLAttribute
2445 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2446 ;
2447
2448XMLElementContent
2449 : XMLExpression XMLElementContentOpt
2450 | XMLMarkup XMLElementContentOpt
2451 | XMLText XMLElementContentOpt
2452 | XMLElement XMLElementContentOpt
2453 ;
2454
2455XMLElementContentOpt
2456 : XMLElementContent
2457 |
2458 ;
2459/* }}} */
2460/* 11.1.5 XMLList Initializer {{{ */
2461XMLListInitilizer
2462 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2463 ;
2464/* }}} */
2465
2466/* 11.2 Left-Hand-Side Expressions {{{ */
2467PropertyIdentifier_
2468 : Identifier { $$ = $1; }
2469 | PropertyIdentifier { $$ = $1; }
2470 ;
2471
2472MemberAccess
2473 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2474 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2475 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2476 ;
2477/* }}} */
2478/* 12.1 The default xml namespace Statement {{{ */
2479/* XXX: DefaultXMLNamespaceStatement
2480 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2481 ;
2482
2483Statement__
2484 : DefaultXMLNamespaceStatement { $$ = $1; }
2485 ; */
2486/* }}} */
2487@end
2488
2489/* JavaScript FTL: Array Comprehensions {{{ */
2490Comprehension
2491 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2492 ;
2493
2494ComprehensionFor
2495 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2496 ;
2497/* }}} */
2498/* JavaScript FTL: for each {{{ */
2499IterationStatement
2500 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2501 ;
2502/* }}} */
2503
2504/* JavaScript FTW: Array Comprehensions {{{ */
2505PrimaryExpression
2506 : ArrayComprehension
2507 ;
2508
2509ArrayComprehension
2510 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2511 ;
2512
2513Comprehension
2514 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2515 ;
2516
2517ComprehensionTail
2518 : { $$ = NULL; }
2519 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2520 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2521 ;
2522
2523ComprehensionFor
2524 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2525 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2526 ;
2527
2528ComprehensionIf
2529 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2530 ;
2531/* }}} */
2532/* JavaScript FTW: Coalesce Operator {{{ */
2533ConditionalExpression
2534 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2535 ;
2536/* }}} */
2537/* JavaScript FTW: Named Arguments {{{ */
2538ArgumentList
2539 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2540 ;
2541/* }}} */
2542/* JavaScript FTW: Ruby Blocks {{{ */
2543RubyProcParameterList_
2544 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2545 | { $$ = NULL; }
2546 ;
2547
2548RubyProcParameterList
2549 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2550 | LexOf { $$ = NULL; }
2551 ;
2552
2553RubyProcParameters
2554 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2555 | "||" { $$ = NULL; }
2556 ;
2557
2558RubyProcParametersOpt
2559 : RubyProcParameters[pass] { $$ = $pass; }
2560 | { $$ = NULL; }
2561 ;
2562
2563RubyProcExpression
2564 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2565 ;
2566
2567PrimaryExpression
2568 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2569 ;
2570
2571RubyBlockExpression_
2572 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2573 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2574 ;
2575
2576RubyBlockExpression
2577 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2578 | RubyBlockExpression_[pass] { $$ = $pass; }
2579 ;
2580/* }}} */
2581
2582%%
2583
2584bool CYDriver::Parse(CYMark mark) {
2585 mark_ = mark;
2586 CYLocal<CYPool> local(&pool_);
2587 cy::parser parser(*this);
2588#ifdef YYDEBUG
2589 parser.set_debug_level(debug_);
2590#endif
2591 return parser.parse() != 0;
2592}
2593
2594void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2595 if (!strict_)
2596 return;
2597
2598 CYDriver::Error error;
2599 error.warning_ = true;
2600 error.location_ = location;
2601 error.message_ = message;
2602 errors_.push_back(error);
2603}
2604
2605void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2606 CYDriver::Error error;
2607 error.warning_ = false;
2608 error.location_ = location;
2609 error.message_ = message;
2610 driver.errors_.push_back(error);
2611}