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