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