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