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