]> git.saurik.com Git - cycript.git/blob - Cycript.yy.in
bb5f96343902e5baf65c62e9dc31927d41340ac9
[cycript.git] / Cycript.yy.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 cyscanner driver.scanner_
24 #define YYSTACKEXPANDABLE 1
25 }
26
27 %code requires {
28 #include "Driver.hpp"
29 #include "Parser.hpp"
30 #include "Stack.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 typedef struct {
44 bool newline_;
45 hi::Value highlight_;
46
47 union {
48 bool bool_;
49
50 CYArgument *argument_;
51 CYAssignment *assignment_;
52 CYBoolean *boolean_;
53 CYClause *clause_;
54 cy::Syntax::Catch *catch_;
55 CYComment *comment_;
56 CYComprehension *comprehension_;
57 CYDeclaration *declaration_;
58 CYDeclarations *declarations_;
59 CYElement *element_;
60 CYExpression *expression_;
61 CYFalse *false_;
62 CYFinally *finally_;
63 CYForInitialiser *for_;
64 CYForInInitialiser *forin_;
65 CYFunctionParameter *functionParameter_;
66 CYIdentifier *identifier_;
67 CYInfix *infix_;
68 CYLiteral *literal_;
69 CYMember *member_;
70 CYModule *module_;
71 CYNull *null_;
72 CYNumber *number_;
73 CYParenthetical *parenthetical_;
74 CYProgram *program_;
75 CYProperty *property_;
76 CYPropertyName *propertyName_;
77 CYRubyProc *rubyProc_;
78 CYStatement *statement_;
79 CYString *string_;
80 CYThis *this_;
81 CYTrue *true_;
82 CYWord *word_;
83
84 @begin C
85 CYTypeModifier *modifier_;
86 CYTypeSpecifier *specifier_;
87 CYTypedIdentifier *typedIdentifier_;
88 CYTypedParameter *typedParameter_;
89 @end
90
91 @begin ObjectiveC
92 CYClassName *className_;
93 CYClassField *classField_;
94 CYMessage *message_;
95 CYMessageParameter *messageParameter_;
96 CYProtocol *protocol_;
97 CYSelectorPart *selector_;
98 @end
99
100 @begin E4X
101 CYAttribute *attribute_;
102 CYPropertyIdentifier *propertyIdentifier_;
103 CYSelector *selector_;
104 @end
105 };
106 } YYSTYPE;
107
108 #define YYSTYPE YYSTYPE
109 }
110
111 %code provides {
112 int cylex(YYSTYPE *, CYLocation *, void *);
113 }
114
115 %name-prefix "cy"
116
117 %language "C++"
118
119 %initial-action {
120 @$.begin.filename = @$.end.filename = &driver.filename_;
121 };
122
123 %locations
124 %defines
125
126 %define api.location.type { CYLocation }
127
128 //%glr-parser
129 //%expect 1
130
131 %error-verbose
132
133 %parse-param { CYDriver &driver }
134 %lex-param { void *cyscanner }
135
136 /* Token Declarations {{{ */
137 @begin E4X
138 %token XMLCDATA
139 %token XMLComment
140 %token XMLPI
141
142 %token XMLAttributeValue
143 %token XMLName
144 %token XMLTagCharacters
145 %token XMLText
146 %token XMLWhitespace
147 @end
148
149 @begin E4X
150 %token LeftRight "<>"
151 %token LeftSlashRight "</>"
152
153 %token SlashRight "/>"
154 %token LeftSlash "</"
155
156 %token ColonColon "::"
157 %token PeriodPeriod ".."
158 @end
159
160 @begin E4X ObjectiveC
161 %token At "@"
162 %token Pound "#"
163 @end
164
165 %token Ampersand "&"
166 %token AmpersandAmpersand "&&"
167 %token AmpersandEqual "&="
168 %token Carrot "^"
169 %token CarrotEqual "^="
170 %token Equal "="
171 %token EqualEqual "=="
172 %token EqualEqualEqual "==="
173 %token EqualRight "=>"
174 %token EqualRight_ "\n=>"
175 %token Exclamation "!"
176 %token ExclamationEqual "!="
177 %token ExclamationEqualEqual "!=="
178 %token Hyphen "-"
179 %token HyphenEqual "-="
180 %token HyphenHyphen "--"
181 %token HyphenHyphen_ "\n--"
182 %token HyphenRight "->"
183 %token Left "<"
184 %token LeftEqual "<="
185 %token LeftLeft "<<"
186 %token LeftLeftEqual "<<="
187 %token Percent "%"
188 %token PercentEqual "%="
189 %token Period "."
190 %token PeriodPeriodPeriod "..."
191 %token Pipe "|"
192 %token PipeEqual "|="
193 %token PipePipe "||"
194 %token Plus "+"
195 %token PlusEqual "+="
196 %token PlusPlus "++"
197 %token PlusPlus_ "\n++"
198 %token Right ">"
199 %token RightEqual ">="
200 %token RightRight ">>"
201 %token RightRightEqual ">>="
202 %token RightRightRight ">>>"
203 %token RightRightRightEqual ">>>="
204 %token Slash "/"
205 %token SlashEqual "/="
206 %token Star "*"
207 %token StarEqual "*="
208 %token Tilde "~"
209
210 %token Colon ":"
211 %token Comma ","
212 %token Question "?"
213 %token SemiColon ";"
214 %token NewLine "\n"
215
216 %token <comment_> Comment
217
218 %token OpenParen "("
219 %token CloseParen ")"
220
221 %token OpenBrace "{"
222 %token OpenBrace_ "\n{"
223 %token OpenBrace__ ";{"
224 %token CloseBrace "}"
225
226 %token OpenBracket "["
227 %token CloseBracket "]"
228
229 %token AtError "@error"
230
231 @begin Java
232 %token AtClass "@class"
233 @end
234
235 @begin C
236 %token Typedef "typedef"
237 %token Unsigned "unsigned"
238 %token Signed "signed"
239 %token Extern "extern"
240 @end
241
242 @begin C
243 %token AtEncode "@encode"
244 @end
245
246 @begin ObjectiveC
247 %token AtImplementation "@implementation"
248 %token AtImplementation_ ";@implementation"
249 %token AtImport "@import"
250 %token AtEnd "@end"
251 %token AtSelector "@selector"
252 %token AtNull "@null"
253 %token AtYes "@YES"
254 %token AtNo "@NO"
255 %token AtTrue "@true"
256 %token AtFalse "@false"
257 %token Yes "YES"
258 %token No "NO"
259 @end
260
261 %token False "false"
262 %token Null "null"
263 %token True "true"
264
265 %token Break "break"
266 %token Case "case"
267 %token Catch "catch"
268 %token Class "class"
269 %token Const "const"
270 %token Continue "continue"
271 %token Debugger "debugger"
272 %token Default "default"
273 %token Delete "delete"
274 %token Do "do"
275 %token Else "else"
276 %token Enum "enum"
277 %token Export "export"
278 %token Extends "extends"
279 %token Finally "finally"
280 %token For "for"
281 %token Function "function"
282 %token Function_ ";function"
283 %token If "if"
284 %token Import "import"
285 %token In "in"
286 %token In_ "!in"
287 %token InstanceOf "instanceof"
288 %token New "new"
289 %token Return "return"
290 %token Super "super"
291 %token Switch "switch"
292 %token This "this"
293 %token Throw "throw"
294 %token Try "try"
295 %token TypeOf "typeof"
296 %token Var "var"
297 %token Void "void"
298 %token While "while"
299 %token With "with"
300
301 %token Abstract "abstract"
302 %token Await "await"
303 %token Boolean "boolean"
304 %token Byte "byte"
305 %token Char "char"
306 %token Double "double"
307 %token Final "final"
308 %token Float "float"
309 %token Goto "goto"
310 %token Implements "implements"
311 %token Int "int"
312 %token Interface "interface"
313 %token Let "let"
314 %token Long "long"
315 %token Native "native"
316 %token Package "package"
317 %token Private "private"
318 %token Protected "protected"
319 %token Public "public"
320 %token Short "short"
321 %token Static "static"
322 %token Synchronized "synchronized"
323 %token Throws "throws"
324 %token Transient "transient"
325 %token Volatile "volatile"
326 %token Yield "yield"
327
328 %token Auto "auto"
329 %token Each "each"
330 %token Of "of"
331
332 @begin E4X
333 %token Namespace "namespace"
334 %token XML "xml"
335 @end
336
337 %token AutoComplete
338
339 %token <identifier_> Identifier_
340 %token <number_> NumericLiteral
341 %token <string_> StringLiteral
342 %token <literal_> RegularExpressionLiteral
343
344 %type <expression_> AdditiveExpression
345 %type <argument_> ArgumentList_
346 %type <argument_> ArgumentList
347 %type <argument_> ArgumentListOpt
348 %type <argument_> Arguments
349 %type <expression_> ArrayComprehension
350 %type <expression_> ArrayInitialiser
351 %type <literal_> ArrayLiteral
352 %type <expression_> ArrowFunction
353 %type <functionParameter_> ArrowParameters
354 %type <expression_> AssignmentExpression
355 %type <identifier_> Binding
356 %type <identifier_> BindingIdentifier
357 %type <expression_> BitwiseANDExpression
358 %type <statement_> Block_
359 %type <statement_> Block
360 %type <boolean_> BooleanLiteral
361 %type <declaration_> BindingElement
362 %type <expression_> BitwiseORExpression
363 %type <expression_> BitwiseXORExpression
364 %type <statement_> BreakStatement
365 %type <statement_> BreakableStatement
366 %type <expression_> CallExpression_
367 %type <expression_> CallExpression
368 %type <clause_> CaseBlock
369 %type <clause_> CaseClause
370 %type <clause_> CaseClausesOpt
371 %type <catch_> CatchOpt
372 %type <expression_> Comprehension
373 %type <comprehension_> ComprehensionFor
374 %type <comprehension_> ComprehensionIf
375 %type <comprehension_> ComprehensionTail
376 %type <expression_> ConditionalExpression
377 %type <statement_> ContinueStatement
378 %type <statement_> ConciseBody
379 %type <statement_> DebuggerStatement
380 %type <statement_> Declaration__
381 %type <statement_> Declaration_
382 %type <statement_> Declaration
383 %type <clause_> DefaultClause
384 %type <expression_> Element
385 %type <expression_> ElementOpt
386 %type <element_> ElementList
387 %type <element_> ElementListOpt
388 %type <statement_> ElseStatementOpt
389 %type <statement_> EmptyStatement
390 %type <expression_> EqualityExpression
391 %type <expression_> Expression
392 %type <expression_> ExpressionOpt
393 %type <statement_> ExpressionStatement
394 %type <finally_> FinallyOpt
395 %type <for_> ForStatementInitialiser
396 %type <forin_> ForInStatementInitialiser
397 %type <declaration_> FormalParameter
398 %type <functionParameter_> FormalParameterList_
399 %type <functionParameter_> FormalParameterList
400 %type <functionParameter_> FormalParameterListOpt
401 %type <statement_> FunctionBody
402 %type <statement_> FunctionDeclaration
403 %type <expression_> FunctionExpression
404 %type <identifier_> Identifier
405 %type <identifier_> IdentifierOpt
406 %type <identifier_> IdentifierType
407 %type <word_> IdentifierName
408 %type <statement_> IfStatement
409 %type <expression_> Initialiser
410 %type <expression_> InitialiserOpt
411 %type <statement_> IterationStatement
412 %type <statement_> LabelledStatement
413 %type <expression_> LeftHandSideExpression
414 %type <statement_> LetStatement
415 %type <statement_> LexicalDeclaration
416 %type <literal_> Literal
417 %type <literal_> ValueLiteral
418 %type <expression_> LogicalANDExpression
419 %type <expression_> LogicalORExpression
420 %type <member_> MemberAccess
421 %type <expression_> MemberExpression_
422 %type <expression_> MemberExpression
423 %type <module_> Module
424 %type <expression_> MultiplicativeExpression
425 %type <expression_> NewExpression
426 %type <null_> NullLiteral
427 %type <literal_> ObjectLiteral
428 %type <parenthetical_> Parenthetical
429 %type <expression_> PostfixExpression
430 %type <expression_> PrimaryExpression
431 %type <statement_> Program
432 %type <statement_> ProgramBody
433 %type <statement_> ProgramBodyOpt
434 %type <propertyName_> PropertyName_
435 %type <propertyName_> PropertyName
436 %type <property_> PropertyDefinition
437 %type <property_> PropertyDefinitionList_
438 %type <property_> PropertyDefinitionList
439 %type <property_> PropertyDefinitionListOpt
440 %type <expression_> RelationalExpression
441 %type <statement_> ReturnStatement
442 %type <rubyProc_> RubyProcExpression
443 %type <functionParameter_> RubyProcParameterList_
444 %type <functionParameter_> RubyProcParameterList
445 %type <functionParameter_> RubyProcParameters
446 %type <functionParameter_> RubyProcParametersOpt
447 %type <expression_> ShiftExpression
448 %type <declaration_> SingleNameBinding
449 %type <statement_> Statement__
450 %type <statement_> Statement_
451 %type <statement_> Statement
452 %type <statement_> StatementList
453 %type <statement_> StatementListOpt
454 %type <statement_> StatementListItem
455 %type <statement_> SwitchStatement
456 %type <statement_> ThrowStatement
457 %type <statement_> TryStatement
458 %type <expression_> UnaryExpression_
459 %type <expression_> UnaryExpression
460 %type <declaration_> VariableDeclaration
461 %type <declarations_> VariableDeclarationList_
462 %type <declarations_> VariableDeclarationList
463 %type <statement_> VariableStatement
464 %type <statement_> WithStatement
465 %type <word_> Word
466 @begin ObjectiveC
467 %type <word_> WordOpt
468 @end
469 %type <expression_> Variable
470
471 @begin C
472 %type <specifier_> IntegerType
473 %type <specifier_> IntegerTypeOpt
474 %type <typedIdentifier_> PrefixedType
475 %type <specifier_> PrimitiveType
476 %type <typedIdentifier_> SuffixedType
477 %type <typedIdentifier_> TypeSignifier
478 %type <modifier_> TypeQualifierLeft
479 %type <typedIdentifier_> TypeQualifierRight
480 %type <typedIdentifier_> TypedIdentifier
481 %type <typedParameter_> TypedParameterList_
482 %type <typedParameter_> TypedParameterList
483 %type <typedParameter_> TypedParameterListOpt
484 @end
485
486 @begin ObjectiveC
487 %type <expression_> BoxableExpression
488 %type <statement_> CategoryStatement
489 %type <expression_> ClassExpression
490 %type <classField_> ClassFieldListOpt
491 %type <classField_> ClassFields
492 %type <statement_> ClassStatement
493 %type <expression_> ClassSuperOpt
494 %type <message_> ClassMessageDeclaration
495 %type <message_> ClassMessageDeclarationListOpt
496 %type <className_> ClassName
497 %type <className_> ClassNameOpt
498 %type <protocol_> ClassProtocolListOpt
499 %type <protocol_> ClassProtocols
500 %type <protocol_> ClassProtocolsOpt
501 %type <expression_> MessageExpression
502 %type <messageParameter_> MessageParameter
503 %type <messageParameter_> MessageParameters
504 %type <messageParameter_> MessageParameterList
505 %type <messageParameter_> MessageParameterListOpt
506 %type <bool_> MessageScope
507 %type <argument_> SelectorCall_
508 %type <argument_> SelectorCall
509 %type <selector_> SelectorExpression_
510 %type <selector_> SelectorExpression
511 %type <selector_> SelectorExpressionOpt
512 %type <argument_> SelectorList
513 %type <word_> SelectorWordOpt
514 %type <typedIdentifier_> TypeOpt
515 %type <argument_> VariadicCall
516 @end
517
518 @begin E4X
519 %type <propertyIdentifier_> PropertyIdentifier_
520 %type <selector_> PropertySelector_
521 %type <selector_> PropertySelector
522 %type <identifier_> QualifiedIdentifier_
523 %type <identifier_> QualifiedIdentifier
524 %type <identifier_> WildcardIdentifier
525 %type <identifier_> XMLComment
526 %type <identifier_> XMLCDATA
527 %type <identifier_> XMLElement
528 %type <identifier_> XMLElementContent
529 %type <identifier_> XMLMarkup
530 %type <identifier_> XMLPI
531
532 %type <attribute_> AttributeIdentifier
533 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
534 %type <expression_> PropertyIdentifier
535 %type <expression_> XMLListInitialiser
536 %type <expression_> XMLInitialiser
537 @end
538 /* }}} */
539 /* Token Priorities {{{ */
540 %nonassoc ""
541 %left "++" "--"
542
543 %nonassoc "if"
544 %nonassoc "else"
545 /* }}} */
546
547 %start Program
548
549 %%
550
551 /* Lexer State {{{ */
552 LexPushInOn
553 : { driver.in_.push(true); }
554 ;
555
556 LexPushInOff
557 : { driver.in_.push(false); }
558 ;
559
560 LexPopIn
561 : { driver.in_.pop(); }
562 ;
563
564 LexSetRegExp
565 : { driver.SetCondition(CYDriver::RegExpCondition); }
566 ;
567
568 LexNoBrace
569 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
570 ;
571
572 LexNoFunction
573 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); }
574 ;
575
576 LexNoAtImplementation :
577 @begin ObjectiveC
578 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); }
579 @end
580 ;
581
582 LexSetStatement
583 : LexNoBrace LexNoFunction LexNoAtImplementation
584 ;
585 /* }}} */
586 /* Virtual Tokens {{{ */
587 BRACE
588 : "{"
589 | "\n{"
590 ;
591
592 Var_
593 : "var"
594 ;
595 /* }}} */
596
597 /* 7.6 Identifier Names and Identifiers {{{ */
598 IdentifierName
599 : Word { $$ = $1; }
600 ;
601
602 NewLineOpt
603 : "\n"
604 |
605 ;
606
607 Word
608 : Identifier { $$ = $1; }
609
610 | "auto" { $$ = CYNew CYWord("auto"); }
611 | "break" NewLineOpt { $$ = CYNew CYWord("break"); }
612 | "case" { $$ = CYNew CYWord("case"); }
613 | "catch" { $$ = CYNew CYWord("catch"); }
614 | "class" { $$ = CYNew CYWord("class"); }
615 | "const" { $$ = CYNew CYWord("const"); }
616 | "continue" NewLineOpt { $$ = CYNew CYWord("continue"); }
617 | "debugger" { $$ = CYNew CYWord("debugger"); }
618 | "default" { $$ = CYNew CYWord("default"); }
619 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
620 | "do" { $$ = CYNew CYWord("do"); }
621 | "else" { $$ = CYNew CYWord("else"); }
622 | "enum" { $$ = CYNew CYWord("enum"); }
623 | "export" { $$ = CYNew CYWord("export"); }
624 | "extends" { $$ = CYNew CYWord("extends"); }
625 | "false" { $$ = CYNew CYWord("false"); }
626 | "finally" { $$ = CYNew CYWord("finally"); }
627 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
628 | "function" { $$ = CYNew CYWord("function"); }
629 | "if" { $$ = CYNew CYWord("if"); }
630 | "import" { $$ = CYNew CYWord("import"); }
631 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
632 | "!in" { $$ = CYNew CYWord("in"); }
633 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
634
635 // XXX: as it currently is not an Identifier
636 | "let" { $$ = CYNew CYIdentifier("let"); }
637
638 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
639 | "null" { $$ = CYNew CYWord("null"); }
640 | "return" NewLineOpt { $$ = CYNew CYWord("return"); }
641 | "super" { $$ = CYNew CYWord("super"); }
642 | "switch" { $$ = CYNew CYWord("switch"); }
643 | "this" { $$ = CYNew CYWord("this"); }
644 | "throw" NewLineOpt { $$ = CYNew CYWord("throw"); }
645 | "true" { $$ = CYNew CYWord("true"); }
646 | "try" { $$ = CYNew CYWord("try"); }
647 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
648 | "var" { $$ = CYNew CYWord("var"); }
649 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
650 | "while" { $$ = CYNew CYWord("while"); }
651 | "with" { $$ = CYNew CYWord("with"); }
652 ;
653
654 @begin ObjectiveC
655 WordOpt
656 : Word { $$ = $1; }
657 | { $$ = NULL; }
658 ;
659 @end
660
661 IdentifierType
662 : Identifier_ { $$ = $1; }
663
664 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
665 | "await" { $$ = CYNew CYIdentifier("await"); }
666 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
667 | "byte" { $$ = CYNew CYIdentifier("byte"); }
668 | "double" { $$ = CYNew CYIdentifier("double"); }
669 | "final" { $$ = CYNew CYIdentifier("final"); }
670 | "float" { $$ = CYNew CYIdentifier("float"); }
671 | "goto" { $$ = CYNew CYIdentifier("goto"); }
672 | "implements" { $$ = CYNew CYIdentifier("implements"); }
673 | "interface" { $$ = CYNew CYIdentifier("interface"); }
674 | "native" { $$ = CYNew CYIdentifier("native"); }
675 | "package" { $$ = CYNew CYIdentifier("package"); }
676 | "private" { $$ = CYNew CYIdentifier("private"); }
677 | "protected" { $$ = CYNew CYIdentifier("protected"); }
678 | "public" { $$ = CYNew CYIdentifier("public"); }
679 | "static" { $$ = CYNew CYIdentifier("static"); }
680 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
681 | "throws" { $$ = CYNew CYIdentifier("throws"); }
682 | "transient" { $$ = CYNew CYIdentifier("transient"); }
683
684 // XXX: currently I only have this as Word
685 // | "let" { $$ = CYNew CYIdentifier("let"); }
686
687 | "yield" NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
688
689 | "each" { $$ = CYNew CYIdentifier("each"); }
690 | "of" { $$ = CYNew CYIdentifier("of"); }
691 ;
692
693 Identifier
694 : IdentifierType
695 | "char" { $$ = CYNew CYIdentifier("char"); }
696 | "int" { $$ = CYNew CYIdentifier("int"); }
697 | "long" { $$ = CYNew CYIdentifier("long"); }
698 | "short" { $$ = CYNew CYIdentifier("short"); }
699 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
700 @begin C
701 | "extern" { $$ = CYNew CYIdentifier("extern"); }
702 | "signed" { $$ = CYNew CYIdentifier("signed"); }
703 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
704 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
705 @end
706 @begin ObjectiveC
707 | "NO" { $$ = CYNew CYIdentifier("NO"); }
708 | "YES" { $$ = CYNew CYIdentifier("YES"); }
709 @end
710 ;
711
712 IdentifierOpt
713 : Identifier { $$ = $1; }
714 | { $$ = NULL; }
715 ;
716 /* }}} */
717
718 /* 7.8 Literals {{{ */
719 Literal
720 : NullLiteral { $$ = $1; }
721 | ValueLiteral { $$ = $1; }
722 ;
723
724 ValueLiteral
725 : BooleanLiteral { $$ = $1; }
726 | NumericLiteral { $$ = $1; }
727 | StringLiteral { $$ = $1; }
728 | RegularExpressionLiteral { $$ = $1; }
729 ;
730 /* }}} */
731 /* 7.8.1 Null Literals {{{ */
732 NullLiteral
733 : "null" { $$ = CYNew CYNull(); }
734 ;
735 /* }}} */
736 /* 7.8.2 Boolean Literals {{{ */
737 BooleanLiteral
738 : "true" { $$ = CYNew CYTrue(); }
739 | "false" { $$ = CYNew CYFalse(); }
740 ;
741 /* }}} */
742
743 /* 7.9 Automatic Semicolon Insertion {{{ */
744 StrictSemi
745 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
746 ;
747
748 Terminator
749 : ";"
750 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !yyla.value.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
751 ;
752
753 TerminatorOpt
754 : ";"
755 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
756 ;
757 /* }}} */
758
759 /* 11.1 Primary Expressions {{{ */
760 Parenthetical
761 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
762 ;
763
764 Variable
765 : Identifier { $$ = CYNew CYVariable($1); }
766 ;
767
768 PrimaryExpression
769 : "this" { $$ = CYNew CYThis(); }
770 | Variable { $$ = $1; }
771 | Literal { $$ = $1; }
772 | ArrayInitialiser { $$ = $1; }
773 | ObjectLiteral { $$ = $1; }
774 | Parenthetical { $$ = $1; }
775 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
776 ;
777 /* }}} */
778 /* 11.1.4 Array Initializer {{{ */
779 ArrayInitialiser
780 : ArrayLiteral { $$ = $1; }
781 | ArrayComprehension { $$ = $1; }
782 ;
783 /* }}} */
784 /* 11.1.4.1 Array Literal {{{ */
785 ArrayLiteral
786 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
787 ;
788
789 Element
790 : AssignmentExpression { $$ = $1; }
791 ;
792
793 ElementOpt
794 : Element { $$ = $1; }
795 | LexSetRegExp { $$ = NULL; }
796 ;
797
798 ElementList
799 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
800 | Element { $$ = CYNew CYElement($1, NULL); }
801 ;
802
803 ElementListOpt
804 : ElementList { $$ = $1; }
805 | LexSetRegExp { $$ = NULL; }
806 ;
807 /* }}} */
808 /* 11.1.4.2 Array Comprehension {{{ */
809 ArrayComprehension
810 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
811 ;
812
813 Comprehension
814 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
815 ;
816
817 ComprehensionTail
818 : { $$ = NULL; }
819 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
820 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
821 ;
822
823 ComprehensionFor
824 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
825 ;
826
827 ComprehensionIf
828 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
829 ;
830 /* }}} */
831 /* 11.1.5 Object Initialiser {{{ */
832 ObjectLiteral
833 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
834 ;
835
836 PropertyDefinitionList_
837 : "," PropertyDefinitionList { $$ = $2; }
838 | "," LexSetRegExp { $$ = NULL; }
839 | { $$ = NULL; }
840 ;
841
842 PropertyDefinitionList
843 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
844 ;
845
846 PropertyDefinitionListOpt
847 : PropertyDefinitionList { $$ = $1; }
848 | LexSetRegExp { $$ = NULL; }
849 ;
850
851 PropertyDefinition
852 // XXX: this should be IdentifierName
853 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
854 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
855 //| MethodDefinition
856 ;
857
858 PropertyName_
859 : IdentifierName { $$ = $1; }
860 | StringLiteral { $$ = $1; }
861 | NumericLiteral { $$ = $1; }
862 ;
863
864 PropertyName
865 : LexSetRegExp PropertyName_ { $$ = $2; }
866 ;
867 /* }}} */
868
869 /* 11.2 Left-Hand-Side Expressions {{{ */
870 MemberAccess
871 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
872 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
873 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
874 ;
875
876 MemberExpression_
877 : MemberExpression { $$ = $1; }
878 //| "super" { $$ = $1; }
879 ;
880
881 MemberExpression
882 : LexSetRegExp PrimaryExpression { $$ = $2; }
883 | LexSetRegExp FunctionExpression { $$ = $2; }
884 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
885 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
886 ;
887
888 NewExpression
889 : MemberExpression { $$ = $1; }
890 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
891 ;
892
893 CallExpression_
894 : MemberExpression_
895 | CallExpression
896 ;
897
898 CallExpression
899 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
900 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
901 ;
902
903 Arguments
904 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
905 ;
906
907 ArgumentList_
908 : "," ArgumentList { $$ = $2; }
909 | { $$ = NULL; }
910 ;
911
912 ArgumentList
913 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
914 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
915 ;
916
917 ArgumentListOpt
918 : ArgumentList { $$ = $1; }
919 | LexSetRegExp { $$ = NULL; }
920 ;
921
922 LeftHandSideExpression
923 : NewExpression { $$ = $1; }
924 | CallExpression { $$ = $1; }
925 ;
926 /* }}} */
927 /* 11.3 Postfix Expressions {{{ */
928 PostfixExpression
929 : %prec "" LeftHandSideExpression { $$ = $1; }
930 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
931 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
932 ;
933 /* }}} */
934 /* 11.4 Unary Operators {{{ */
935 UnaryExpression_
936 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
937 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
938 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
939 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
940 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
941 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
942 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
943 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
944 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
945 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
946 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
947 ;
948
949 UnaryExpression
950 : PostfixExpression { $$ = $1; }
951 | LexSetRegExp UnaryExpression_ { $$ = $2; }
952 ;
953 /* }}} */
954 /* 11.5 Multiplicative Operators {{{ */
955 MultiplicativeExpression
956 : UnaryExpression { $$ = $1; }
957 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
958 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
959 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
960 ;
961 /* }}} */
962 /* 11.6 Additive Operators {{{ */
963 AdditiveExpression
964 : MultiplicativeExpression { $$ = $1; }
965 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
966 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
967 ;
968 /* }}} */
969 /* 11.7 Bitwise Shift Operators {{{ */
970 ShiftExpression
971 : AdditiveExpression { $$ = $1; }
972 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
973 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
974 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
975 ;
976 /* }}} */
977 /* 11.8 Relational Operators {{{ */
978 RelationalExpression
979 : ShiftExpression { $$ = $1; }
980 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
981 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
982 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
983 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
984 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
985 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
986 ;
987 /* }}} */
988 /* 11.9 Equality Operators {{{ */
989 EqualityExpression
990 : RelationalExpression { $$ = $1; }
991 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
992 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
993 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
994 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
995 ;
996 /* }}} */
997 /* 11.10 Binary Bitwise Operators {{{ */
998 BitwiseANDExpression
999 : EqualityExpression { $$ = $1; }
1000 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1001 ;
1002
1003 BitwiseXORExpression
1004 : BitwiseANDExpression { $$ = $1; }
1005 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1006 ;
1007
1008 BitwiseORExpression
1009 : BitwiseXORExpression { $$ = $1; }
1010 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1011 ;
1012 /* }}} */
1013 /* 11.11 Binary Logical Operators {{{ */
1014 LogicalANDExpression
1015 : BitwiseORExpression { $$ = $1; }
1016 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1017 ;
1018
1019 LogicalORExpression
1020 : LogicalANDExpression { $$ = $1; }
1021 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1022 ;
1023 /* }}} */
1024 /* 11.12 Conditional Operator ( ? : ) {{{ */
1025 ConditionalExpression
1026 : LogicalORExpression { $$ = $1; }
1027 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1028 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1029 ;
1030 /* }}} */
1031 /* 11.13 Assignment Operators {{{ */
1032 AssignmentExpression
1033 : ConditionalExpression { $$ = $1; }
1034 | ArrowFunction { $$ = $1; }
1035 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1036 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1037 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1038 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1039 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1040 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1041 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1042 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1043 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1044 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1045 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1046 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1047 ;
1048 /* }}} */
1049 /* 11.14 Comma Operator {{{ */
1050 Expression
1051 : AssignmentExpression { $$ = $1; }
1052 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1053 ;
1054
1055 ExpressionOpt
1056 : Expression { $$ = $1; }
1057 | LexSetRegExp { $$ = NULL; }
1058 ;
1059 /* }}} */
1060
1061 /* 12 Statements {{{ */
1062 Statement__
1063 : Block { $$ = $1; }
1064 | VariableStatement { $$ = $1; }
1065 | EmptyStatement { $$ = $1; }
1066 | IfStatement { $$ = $1; }
1067 | BreakableStatement { $$ = $1; }
1068 | ContinueStatement { $$ = $1; }
1069 | BreakStatement { $$ = $1; }
1070 | ReturnStatement { $$ = $1; }
1071 | WithStatement { $$ = $1; }
1072 | LabelledStatement { $$ = $1; }
1073 | ThrowStatement { $$ = $1; }
1074 | TryStatement { $$ = $1; }
1075 | DebuggerStatement { $$ = $1; }
1076 ;
1077
1078 Statement_
1079 : LexSetRegExp Statement__ { $$ = $2; }
1080 | ExpressionStatement { $$ = $1; }
1081 ;
1082
1083 Statement
1084 : LexSetStatement Statement_ { $$ = $2; }
1085 ;
1086
1087 Declaration__
1088 : FunctionDeclaration { $$ = $1; }
1089 | LexicalDeclaration { $$ = $1; }
1090 ;
1091
1092 Declaration_
1093 : LexSetRegExp Declaration__ { $$ = $2; }
1094 ;
1095
1096 Declaration
1097 : LexSetStatement Declaration_ { $$ = $2; }
1098 ;
1099
1100 BreakableStatement
1101 : IterationStatement { $$ = $1; }
1102 | SwitchStatement { $$ = $1; }
1103 ;
1104 /* }}} */
1105 /* 12.1 Block {{{ */
1106 Block_
1107 : BRACE StatementListOpt "}" { $$ = $2; }
1108 ;
1109
1110 Block
1111 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1112 ;
1113
1114 StatementList
1115 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1116 ;
1117
1118 StatementListOpt
1119 : StatementList { $$ = $1; }
1120 | LexSetStatement LexSetRegExp { $$ = NULL; }
1121 ;
1122
1123 StatementListItem
1124 : Statement { $$ = $1; }
1125 | Declaration { $$ = $1; }
1126 ;
1127 /* }}} */
1128
1129 /* 12.2 Declarations {{{ */
1130 BindingIdentifier
1131 : Identifier { $$ = $1; }
1132 ;
1133
1134 Binding
1135 : BindingIdentifier
1136 ;
1137
1138 // XXX: BindingPattern
1139 /* }}} */
1140 /* 12.2.1 Let and Const Declarations {{{ */
1141 LexicalDeclaration
1142 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1143 ;
1144
1145 LetOrConst
1146 : "let"
1147 | "const"
1148 ;
1149 /* }}} */
1150 /* 12.2.2 Variable Statement {{{ */
1151 VariableStatement
1152 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1153 ;
1154
1155 VariableDeclarationList_
1156 : "," VariableDeclarationList { $$ = $2; }
1157 | { $$ = NULL; }
1158 ;
1159
1160 VariableDeclarationList
1161 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1162 ;
1163
1164 VariableDeclaration
1165 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1166 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1167 ;
1168
1169 Initialiser
1170 : "=" AssignmentExpression { $$ = $2; }
1171 ;
1172
1173 InitialiserOpt
1174 : Initialiser { $$ = $1; }
1175 | { $$ = NULL; }
1176 ;
1177 /* }}} */
1178 /* 12.2.4 Destructuring Binding Patterns {{{ */
1179 // XXX: *
1180
1181 BindingElement
1182 : SingleNameBinding { $$ = $1; }
1183 ;
1184
1185 SingleNameBinding
1186 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1187 ;
1188 /* }}} */
1189
1190 /* 12.3 Empty Statement {{{ */
1191 EmptyStatement
1192 : ";" { $$ = CYNew CYEmpty(); }
1193 ;
1194 /* }}} */
1195 /* 12.4 Expression Statement {{{ */
1196 ExpressionStatement
1197 : Expression Terminator { $$ = CYNew CYExpress($1); }
1198 ;
1199 /* }}} */
1200 /* 12.5 The if Statement {{{ */
1201 ElseStatementOpt
1202 : "else" Statement { $$ = $2; }
1203 | %prec "if" { $$ = NULL; }
1204 ;
1205
1206 IfStatement
1207 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1208 ;
1209 /* }}} */
1210
1211 /* 12.6.1 The do-while Statement {{{ */
1212 IterationStatement
1213 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1214 ;
1215 /* }}} */
1216 /* 12.6.2 The while Statement {{{ */
1217 IterationStatement
1218 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1219 ;
1220 /* }}} */
1221 /* 12.6.3 The for Statement {{{ */
1222 IterationStatement
1223 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1224 ;
1225
1226 ForStatementInitialiser
1227 : ExpressionOpt { $$ = $1; }
1228 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1229 ;
1230 /* }}} */
1231 /* 12.6.4 The for-in and for-of Statements {{{ */
1232 IterationStatement
1233 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1234 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1235 ;
1236
1237 ForInStatementInitialiser
1238 : LeftHandSideExpression { $$ = $1; }
1239 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1240 ;
1241 /* }}} */
1242
1243 /* 12.7 The continue Statement {{{ */
1244 ContinueStatement
1245 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1246 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1247 ;
1248 /* }}} */
1249 /* 12.8 The break Statement {{{ */
1250 BreakStatement
1251 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1252 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1253 ;
1254 /* }}} */
1255 /* 12.9 The return Statement {{{ */
1256 ReturnStatement
1257 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1258 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1259 ;
1260 /* }}} */
1261 /* 12.10 The with Statement {{{ */
1262 WithStatement
1263 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1264 ;
1265 /* }}} */
1266
1267 /* 12.11 The switch Statement {{{ */
1268 SwitchStatement
1269 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1270 ;
1271
1272 CaseBlock
1273 : BRACE CaseClausesOpt "}" { $$ = $2; }
1274 ;
1275
1276 CaseClause
1277 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1278 ;
1279
1280 CaseClausesOpt
1281 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1282 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1283 | { $$ = NULL; }
1284 ;
1285
1286 DefaultClause
1287 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1288 ;
1289 /* }}} */
1290 /* 12.12 Labelled Statements {{{ */
1291 LabelledStatement
1292 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1293 ;
1294 /* }}} */
1295 /* 12.13 The throw Statement {{{ */
1296 ThrowStatement
1297 : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); }
1298 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1299 ;
1300 /* }}} */
1301 /* 12.14 The try Statement {{{ */
1302 TryStatement
1303 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1304 ;
1305
1306 CatchOpt
1307 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1308 | { $$ = NULL; }
1309 ;
1310
1311 FinallyOpt
1312 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1313 | { $$ = NULL; }
1314 ;
1315 /* }}} */
1316 /* 12.14 The debugger Statement {{{ */
1317 DebuggerStatement
1318 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1319 ;
1320 /* }}} */
1321
1322 /* 13.1 Function Definitions {{{ */
1323 FunctionDeclaration
1324 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1325 ;
1326
1327 FunctionExpression
1328 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1329 ;
1330
1331 FormalParameterList_
1332 : "," FormalParameterList { $$ = $2; }
1333 | { $$ = NULL; }
1334 ;
1335
1336 FormalParameterList
1337 // XXX: : FunctionRestParameter { $$ = $1; }
1338 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1339 ;
1340
1341 FormalParameterListOpt
1342 : FormalParameterList
1343 | { $$ = NULL; }
1344 ;
1345
1346 /* XXX: FunctionRestParameter
1347 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1348 ;*/
1349
1350 FormalParameter
1351 : BindingElement { $$ = $1; }
1352 ;
1353
1354 FunctionBody
1355 : StatementListOpt { $$ = $1; }
1356 ;
1357 /* }}} */
1358 /* 13.2 Arrow Function Definitions {{{ */
1359 ArrowFunction
1360 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1361 ;
1362
1363 ArrowParameters
1364 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1365 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1366 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1367 ;
1368
1369 ConciseBody
1370 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1371 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1372 ;
1373 /* }}} */
1374 /* 14 Program {{{ */
1375 Program
1376 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1377 ;
1378
1379 ProgramBody
1380 : StatementList { $$ = $1; }
1381 ;
1382
1383 ProgramBodyOpt
1384 : ProgramBody { $$ = $1; }
1385 | LexSetStatement LexSetRegExp { $$ = NULL; }
1386 ;
1387 /* }}} */
1388
1389 @begin C
1390 /* Cycript (C): Type Encoding {{{ */
1391 TypeSignifier
1392 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1393 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1394 ;
1395
1396 SuffixedType
1397 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1398 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1399 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1400 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1401 | TypeSignifier { $$ = $1; }
1402 | { $$ = CYNew CYTypedIdentifier(@$); }
1403 ;
1404
1405 PrefixedType
1406 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1407 ;
1408
1409 TypeQualifierLeft
1410 : { $$ = NULL; }
1411 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1412 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1413 ;
1414
1415 TypeQualifierRight
1416 : PrefixedType { $$ = $1; }
1417 | SuffixedType { $$ = $1; }
1418 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1419 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1420 ;
1421
1422 IntegerType
1423 : "int" { $$ = CYNew CYTypeVariable("int"); }
1424 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1425 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1426 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1427 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1428 ;
1429
1430 IntegerTypeOpt
1431 : IntegerType { $$ = $1; }
1432 | { $$ = CYNew CYTypeVariable("int"); }
1433 ;
1434
1435 PrimitiveType
1436 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1437 | IntegerType { $$ = $1; }
1438 | "void" { $$ = CYNew CYTypeVoid(); }
1439 | "char" { $$ = CYNew CYTypeVariable("char"); }
1440 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1441 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1442 ;
1443
1444 TypedIdentifier
1445 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1446 ;
1447
1448 PrimaryExpression
1449 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1450 ;
1451 /* }}} */
1452 @end
1453
1454 @begin ObjectiveC
1455 /* Cycript (Objective-C): @class Declaration {{{ */
1456 ClassSuperOpt
1457 /* XXX: why the hell did I choose MemberExpression? */
1458 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1459 | { $$ = NULL; }
1460 ;
1461
1462 ClassFieldListOpt
1463 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1464 | LexSetRegExp { $$ = NULL; }
1465 ;
1466
1467 ClassFields
1468 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1469 ;
1470
1471 MessageScope
1472 : "+" { $$ = false; }
1473 | "-" { $$ = true; }
1474 ;
1475
1476 TypeOpt
1477 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1478 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1479 ;
1480
1481 MessageParameter
1482 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1483 ;
1484
1485 MessageParameterList
1486 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1487 ;
1488
1489 MessageParameterListOpt
1490 : MessageParameterList { $$ = $1; }
1491 | { $$ = NULL; }
1492 ;
1493
1494 MessageParameters
1495 : MessageParameterList { $$ = $1; }
1496 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1497 ;
1498
1499 ClassMessageDeclaration
1500 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1501 ;
1502
1503 ClassMessageDeclarationListOpt
1504 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1505 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1506 | { $$ = NULL; }
1507 ;
1508
1509 ClassName
1510 : Identifier { $$ = $1; }
1511 | "(" AssignmentExpression ")" { $$ = $2; }
1512 ;
1513
1514 ClassNameOpt
1515 : ClassName { $$ = $1; }
1516 | { $$ = NULL; }
1517 ;
1518
1519 // XXX: this should be AssignmentExpressionNoRight
1520 ClassProtocols
1521 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1522 ;
1523
1524 ClassProtocolsOpt
1525 : "," ClassProtocols { $$ = $2; }
1526 | { $$ = NULL; }
1527 ;
1528
1529 ClassProtocolListOpt
1530 : "<" ClassProtocols ">" { $$ = $2; }
1531 | { $$ = NULL; }
1532 ;
1533
1534 ClassExpression
1535 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1536 ;
1537
1538 ClassStatement
1539 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1540 ;
1541
1542 CategoryName
1543 : "(" WordOpt ")"
1544 ;
1545
1546 CategoryStatement
1547 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1548 ;
1549
1550 PrimaryExpression
1551 : ClassExpression { $$ = $1; }
1552 ;
1553
1554 Statement__
1555 : ClassStatement { $$ = $1; }
1556 | CategoryStatement { $$ = $1; }
1557 ;
1558 /* }}} */
1559 /* Cycript (Objective-C): Send Message {{{ */
1560 VariadicCall
1561 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1562 | { $$ = NULL; }
1563 ;
1564
1565 SelectorWordOpt
1566 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1567 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1568 ;
1569
1570 SelectorCall_
1571 : SelectorCall { $$ = $1; }
1572 | VariadicCall { $$ = $1; }
1573 ;
1574
1575 SelectorCall
1576 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1577 ;
1578
1579 SelectorList
1580 : SelectorCall { $$ = $1; }
1581 | Word { $$ = CYNew CYArgument($1, NULL); }
1582 ;
1583
1584 MessageExpression
1585 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1586 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1587 ;
1588
1589 SelectorExpression_
1590 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1591 ;
1592
1593 SelectorExpression
1594 : SelectorExpression_ { $$ = $1; }
1595 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1596 ;
1597
1598 SelectorExpressionOpt
1599 : SelectorExpression_ { $$ = $1; }
1600 | { $$ = NULL; }
1601 ;
1602
1603 PrimaryExpression
1604 : MessageExpression { $$ = $1; }
1605 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1606 ;
1607 /* }}} */
1608 @end
1609
1610 /* Cycript: @import Directive {{{ */
1611 Module
1612 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1613 | Word { $$ = CYNew CYModule($1); }
1614 ;
1615
1616 Declaration__
1617 : "@import" Module { $$ = CYNew CYImport($2); }
1618 ;
1619 /* }}} */
1620
1621 @begin ObjectiveC
1622 /* Cycript (Objective-C): Boxed Expressions {{{ */
1623 BoxableExpression
1624 : NullLiteral { $$ = $1; }
1625 | BooleanLiteral { $$ = $1; }
1626 | NumericLiteral { $$ = $1; }
1627 | StringLiteral { $$ = $1; }
1628 | ArrayLiteral { $$ = $1; }
1629 | ObjectLiteral { $$ = $1; }
1630 | Parenthetical { $$ = $1; }
1631 | "YES" { $$ = CYNew CYTrue(); }
1632 | "NO" { $$ = CYNew CYFalse(); }
1633 ;
1634
1635 PrimaryExpression
1636 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1637 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1638 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1639 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1640 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1641 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1642 ;
1643 /* }}} */
1644 /* Cycript (Objective-C): Block Expressions {{{ */
1645 PrimaryExpression
1646 : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); }
1647 ;
1648 /* }}} */
1649 /* Cycript (Objective-C): Instance Literals {{{ */
1650 PrimaryExpression
1651 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1652 ;
1653 /* }}} */
1654 @end
1655
1656 @begin C
1657 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1658 LeftHandSideExpression
1659 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1660 ;
1661
1662 UnaryExpression_
1663 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1664 ;
1665
1666 MemberAccess
1667 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1668 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1669 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1670 ;
1671 /* }}} */
1672 /* Cycript (C): auto Compatibility {{{ */
1673 Var_
1674 : "auto"
1675 ;
1676 /* }}} */
1677 /* Cycript (C): Lambda Expressions {{{ */
1678 TypedParameterList_
1679 : "," TypedParameterList { $$ = $2; }
1680 | { $$ = NULL; }
1681 ;
1682
1683 TypedParameterList
1684 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1685 ;
1686
1687 TypedParameterListOpt
1688 : TypedParameterList { $$ = $1; }
1689 | { $$ = NULL; }
1690 ;
1691
1692 PrimaryExpression
1693 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1694 ;
1695 /* }}} */
1696 /* Cycript (C): Type Definitions {{{ */
1697 Statement__
1698 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1699 ;
1700 /* }}} */
1701 /* Cycript (C): extern "C" {{{ */
1702 Statement__
1703 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) error(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
1704 ;
1705 /* }}} */
1706
1707 @end
1708
1709 /* YUI: Documentation Comments {{{ */
1710 Statement__
1711 : Comment { $$ = $1; }
1712 ;
1713 /* }}} */
1714
1715 @begin E4X
1716 /* Lexer State {{{ */
1717 LexPushRegExp
1718 : { driver.PushCondition(CYDriver::RegExpCondition); }
1719 ;
1720
1721 LexPushXMLContent
1722 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1723 ;
1724
1725 LexPushXMLTag
1726 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1727 ;
1728
1729 LexPop
1730 : { driver.PopCondition(); }
1731 ;
1732
1733 LexSetXMLContent
1734 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1735 ;
1736
1737 LexSetXMLTag
1738 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1739 ;
1740 /* }}} */
1741 /* Virtual Tokens {{{ */
1742 XMLWhitespaceOpt
1743 : XMLWhitespace
1744 |
1745 ;
1746 /* }}} */
1747
1748 /* 8.1 Context Keywords {{{ */
1749 Identifier
1750 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1751 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1752 ;
1753 /* }}} */
1754 /* 8.3 XML Initialiser Input Elements {{{ */
1755 XMLMarkup
1756 : XMLComment { $$ = $1; }
1757 | XMLCDATA { $$ = $1; }
1758 | XMLPI { $$ = $1; }
1759 ;
1760 /* }}} */
1761
1762 /* 11.1 Primary Expressions {{{ */
1763 PrimaryExpression
1764 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1765 | XMLInitialiser { $$ = $1; }
1766 | XMLListInitialiser { $$ = $1; }
1767 ;
1768
1769 PropertyIdentifier
1770 : AttributeIdentifier { $$ = $1; }
1771 | QualifiedIdentifier { $$ = $1; }
1772 | WildcardIdentifier { $$ = $1; }
1773 ;
1774 /* }}} */
1775 /* 11.1.1 Attribute Identifiers {{{ */
1776 AttributeIdentifier
1777 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1778 ;
1779
1780 PropertySelector_
1781 : PropertySelector { $$ = $1; }
1782 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1783 ;
1784
1785 PropertySelector
1786 : Identifier { $$ = CYNew CYSelector($1); }
1787 | WildcardIdentifier { $$ = $1; }
1788 ;
1789 /* }}} */
1790 /* 11.1.2 Qualified Identifiers {{{ */
1791 QualifiedIdentifier_
1792 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1793 | QualifiedIdentifier { $$ = $1; }
1794 ;
1795
1796 QualifiedIdentifier
1797 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1798 ;
1799 /* }}} */
1800 /* 11.1.3 Wildcard Identifiers {{{ */
1801 WildcardIdentifier
1802 : "*" { $$ = CYNew CYWildcard(); }
1803 ;
1804 /* }}} */
1805 /* 11.1.4 XML Initialiser {{{ */
1806 XMLInitialiser
1807 : XMLMarkup { $$ = $1; }
1808 | XMLElement { $$ = $1; }
1809 ;
1810
1811 XMLElement
1812 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1813 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1814 ;
1815
1816 XMLTagContent
1817 : LexPushXMLTag XMLTagName XMLAttributes
1818 ;
1819
1820 XMLExpression
1821 : BRACE LexPushRegExp Expression LexPop "}"
1822 ;
1823
1824 XMLTagName
1825 : XMLExpression
1826 | XMLName
1827 ;
1828
1829 XMLAttributes_
1830 : XMLAttributes_ XMLAttribute
1831 |
1832 ;
1833
1834 XMLAttributes
1835 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1836 | XMLAttributes_ XMLWhitespaceOpt
1837 ;
1838
1839 XMLAttributeValue_
1840 : XMLExpression
1841 | XMLAttributeValue
1842 ;
1843
1844 XMLAttribute
1845 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1846 ;
1847
1848 XMLElementContent
1849 : XMLExpression XMLElementContentOpt
1850 | XMLMarkup XMLElementContentOpt
1851 | XMLText XMLElementContentOpt
1852 | XMLElement XMLElementContentOpt
1853 ;
1854
1855 XMLElementContentOpt
1856 : XMLElementContent
1857 |
1858 ;
1859 /* }}} */
1860 /* 11.1.5 XMLList Initialiser {{{ */
1861 XMLListInitialiser
1862 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1863 ;
1864 /* }}} */
1865
1866 /* 11.2 Left-Hand-Side Expressions {{{ */
1867 PropertyIdentifier_
1868 : Identifier { $$ = $1; }
1869 | PropertyIdentifier { $$ = $1; }
1870 ;
1871
1872 MemberAccess
1873 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1874 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1875 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1876 ;
1877 /* }}} */
1878 /* 12.1 The default xml namespace Statement {{{ */
1879 /* XXX: DefaultXMLNamespaceStatement
1880 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1881 ;
1882
1883 Statement__
1884 : DefaultXMLNamespaceStatement { $$ = $1; }
1885 ; */
1886 /* }}} */
1887 @end
1888
1889 /* JavaScript 1.7: Array Comprehensions {{{ */
1890 Comprehension
1891 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1892 ;
1893
1894 ComprehensionFor
1895 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1896 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1897 ;
1898 /* }}} */
1899 /* JavaScript 1.7: for each {{{ */
1900 IterationStatement
1901 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1902 ;
1903 /* }}} */
1904 /* JavaScript 1.7: let Statements {{{ */
1905 LetStatement
1906 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1907 ;
1908
1909 Statement__
1910 : LetStatement
1911 ;
1912 /* }}} */
1913
1914 /* JavaScript FTW: Ruby Blocks {{{ */
1915 RubyProcParameterList_
1916 : "," RubyProcParameterList { $$ = $2; }
1917 | { $$ = NULL; }
1918 ;
1919
1920 RubyProcParameterList
1921 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1922 | { $$ = NULL; }
1923 ;
1924
1925 RubyProcParameters
1926 : "|" RubyProcParameterList "|" { $$ = $2; }
1927 | "||" { $$ = NULL; }
1928 ;
1929
1930 RubyProcParametersOpt
1931 : RubyProcParameters
1932 | { $$ = NULL; }
1933 ;
1934
1935 RubyProcExpression
1936 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1937 ;
1938
1939 PrimaryExpression
1940 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1941 ;
1942
1943 CallExpression
1944 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
1945 ;
1946 /* }}} */
1947
1948 %%