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