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