BOO-996, BOO-995: Added "then" keyword to replace "else" semantic in looping construc...
[boo.git] / src / Boo.Lang.Parser / wsaboo.g
blob7ab99df39a6b432feab7b0cdea06179be124a00e
1 // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
2 // All rights reserved.
3 // 
4 // Redistribution and use in source and binary forms, with or without modification,
5 // are permitted provided that the following conditions are met:
6 // 
7 //     * Redistributions of source code must retain the above copyright notice,
8 //     this list of conditions and the following disclaimer.
9 //     * Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //     * Neither the name of the Rodrigo B. de Oliveira nor the names of its
13 //     contributors may be used to endorse or promote products derived from this
14 //     software without specific prior written permission.
15 // 
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 options
29         language = "CSharp";
30         namespace = "Boo.Lang.Parser";
34 using Boo.Lang.Compiler.Ast;
35 using Boo.Lang.Parser.Util;
36 using System.Globalization;
39 class WSABooParserBase extends Parser;
40 options
42         k = 2;
43         exportVocab = WSABoo; 
44         defaultErrorHandler = true;
46 tokens
47 {       
48         ELIST; // expression list
49         DLIST; // declaration list
50         ESEPARATOR; // expression separator (imaginary token)
51         ABSTRACT="abstract";
52         AND="and";
53         AS="as";
54         BREAK="break";
55         CONTINUE="continue";
56         CALLABLE="callable";
57         CAST="cast";
58         CHAR="char";
59         CLASS="class";
60         CONSTRUCTOR="constructor";      
61         DEF="def";
62         DESTRUCTOR="destructor";
63         DO="do";        
64         ELIF="elif";
65         ELSE="else";
66         END="end";
67         ENSURE="ensure";
68         ENUM="enum";
69         EVENT="event";
70         EXCEPT="except";
71         FAILURE="failure";
72         FINAL="final";  
73         FROM="from";    
74         FOR="for";
75         FALSE="false";
76         GET="get";
77         GOTO="goto";
78         IMPORT="import";
79         INTERFACE="interface";  
80         INTERNAL="internal";
81         IS="is";        
82         ISA="isa";      
83         IF="if";        
84         IN="in";        
85         NOT="not";      
86         NULL="null";
87         OF="of";
88         OR="or";
89         OVERRIDE="override";    
90         NAMESPACE="namespace";
91         PUBLIC="public";
92         PROTECTED="protected";
93         PRIVATE="private";
94         RAISE="raise";
95         REF="ref";
96         RETURN="return";
97         SET="set";      
98         SELF="self";
99         SUPER="super";
100         STATIC="static";
101         STRUCT="struct";
102         THEN="then";
103         TRY="try";
104         TRANSIENT="transient";
105         TRUE="true";
106         TYPEOF="typeof";
107         UNLESS="unless";
108         VIRTUAL="virtual";
109         PARTIAL="partial";
110         WHILE="while";
111         YIELD="yield";
114 {               
115         protected System.Text.StringBuilder _sbuilder = new System.Text.StringBuilder();
116         
117         protected AttributeCollection _attributes = new AttributeCollection();
118         
119         protected TypeMemberModifiers _modifiers = TypeMemberModifiers.None;
121         protected bool _inArray;
122         
123         protected void ResetMemberData()
124         {
125                 _modifiers = TypeMemberModifiers.None;
126         }
128         protected void AddAttributes(AttributeCollection target)
129         {
130                 target.Extend(_attributes);
131                 _attributes.Clear();
132         }
133         
134         static bool IsMethodInvocationExpression(Expression e)
135         {
136                 return NodeType.MethodInvocationExpression == e.NodeType;
137         }
139         protected bool IsValidMacroArgument(int token)
140         {
141                 return LPAREN != token && LBRACK != token;
142         } 
145 protected
146 start[CompileUnit cu] returns [Module module]
148         module = new Module();          
149         module.LexicalInfo = new LexicalInfo(getFilename(), 1, 1);
150         
151         cu.Modules.Add(module);
153         parse_module[module]
154         (EOF)?
156         
157 protected
158 parse_module[Module module]
161         (eos)?
162         docstring[module]
163         (eos)?
164         (namespace_directive[module])?
165         (import_directive[module])*
166         (type_member[module.Members])*  
167         globals[module]
168         (assembly_attribute[module] eos)*
170                         
171 protected docstring[Node node]:
172         (
173                 doc:TRIPLE_QUOTED_STRING { node.Documentation = DocStringFormatter.Format(doc.getText()); }
174                 (eos)?
175         )?
176         ;
177                         
178 protected
179 eos : EOF | (options { greedy = true; }: (EOS | NEWLINE))+;
181 protected
182 import_directive[Module container]
183         {
184                 IToken id;
185                 Import usingNode = null;
186         }: 
187         IMPORT id=identifier
188         {
189                 usingNode = new Import(SourceLocationFactory.ToLexicalInfo(id));
190                 usingNode.Namespace = id.getText();
191                 container.Imports.Add(usingNode);
192         }
193         (
194                 FROM
195                         (
196                                         id=identifier |
197                                         dqs:DOUBLE_QUOTED_STRING { id=dqs; } |
198                                         sqs:SINGLE_QUOTED_STRING { id=sqs; }
199                         )
200                 {
201                         usingNode.AssemblyReference = new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(id));
202                         usingNode.AssemblyReference.Name = id.getText();
203                 }                               
204         )?
205         (
206                 AS alias:ID
207                 {
208                         usingNode.Alias = new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(alias));
209                         usingNode.Alias.Name = alias.getText();
210                 }
211         )?
212         eos
213         ;
215 protected
216 namespace_directive[Module container]
217         {
218                 IToken id;
219                 NamespaceDeclaration p = null;
220         }:
221         t:NAMESPACE id=identifier
222         {
223                 p = new NamespaceDeclaration(SourceLocationFactory.ToLexicalInfo(t));
224                 p.Name = id.getText();
225                 container.Namespace = p; 
226         }
227         eos
228         docstring[p]
229         ;
230                         
231 protected
232 type_member[TypeMemberCollection container]:
233         attributes
234         modifiers
235         (
236                 type_definition[container] |
237                 method[container]
238         )
239         ;
241 protected
242 type_definition [TypeMemberCollection container]:
243         (
244                 class_definition[container] |
245                 interface_definition[container] |
246                 enum_definition[container] |
247                 callable_definition[container]
248         )                       
249         ;
250         
251 protected
252 callable_definition [TypeMemberCollection container]
253         {
254                 CallableDefinition cd = null;
255                 TypeReference returnType = null;
256                 GenericParameterDeclarationCollection genericParameters = null;
257         }:
258         CALLABLE id:ID
259         {
260                 cd = new CallableDefinition(SourceLocationFactory.ToLexicalInfo(id));
261                 cd.Name = id.getText();
262                 cd.Modifiers = _modifiers;
263                 AddAttributes(cd.Attributes);
264                 container.Add(cd);
265                 genericParameters = cd.GenericParameters;
266         }
267         (
268                 (LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK) |
269                 (OF generic_parameter_declaration[genericParameters])
270         )?
271         LPAREN parameter_declaration_list[cd.Parameters] RPAREN
272         (AS returnType=type_reference { cd.ReturnType=returnType; })?                   
273         eos
274         docstring[cd]
275         ;
277 protected
278 enum_definition [TypeMemberCollection container]
279         {
280                 EnumDefinition ed = null;
281         }:
282         ENUM id:ID { ed = new EnumDefinition(SourceLocationFactory.ToLexicalInfo(id)); }
283         begin_with_doc[ed]
284         {
285                 ed.Name = id.getText();
286                 ed.Modifiers = _modifiers;
287                 AddAttributes(ed.Attributes);
288                 container.Add(ed);
289         }
290         (
291                 (enum_member[ed])+
292         )
293         end[ed]
294         ;
295         
296 protected
297 enum_member [EnumDefinition container]
298         {       
299                 EnumMember em = null;   
300                 IntegerLiteralExpression initializer = null;
301                 bool negative = false;          
302         }: 
303         attributes
304         id:ID (ASSIGN (SUBTRACT { negative = true; })? initializer=integer_literal)?
305         {
306                 em = new EnumMember(SourceLocationFactory.ToLexicalInfo(id));
307                 em.Name = id.getText();
308                 em.Initializer = initializer;
309                 if (negative && null != initializer)
310                 {
311                         initializer.Value *= -1;
312                 }
313                 AddAttributes(em.Attributes);
314                 container.Members.Add(em);
315         }
316         eos
317         docstring[em]
318         ;
319                         
320 protected
321 attributes
322         {
323                 _attributes.Clear();
324         }:
325         (
326                 LBRACK
327                 (
328                         attribute
329                         (
330                                 COMMA
331                                 attribute
332                         )*
333                 )?
334                 RBRACK          
335                 (eos)?
336         )*
337         ;
338                         
339 protected
340 attribute
341         {               
342                 antlr.IToken id = null;
343                 Boo.Lang.Compiler.Ast.Attribute attr = null;
344         }:      
345         id=identifier
346         {
347                 attr = new Boo.Lang.Compiler.Ast.Attribute(SourceLocationFactory.ToLexicalInfo(id), id.getText());
348                 _attributes.Add(attr);
349         } 
350         (
351                 LPAREN
352                 argument_list[attr]
353                 RPAREN
354         )?
355         ;
356         
357 protected
358 assembly_attribute[Module module]
359         {
360                 antlr.IToken id = null;
361                 Boo.Lang.Compiler.Ast.Attribute attr = null;
362         }:
363         ASSEMBLY_ATTRIBUTE_BEGIN
364         id=identifier { attr = new Boo.Lang.Compiler.Ast.Attribute(SourceLocationFactory.ToLexicalInfo(id), id.getText()); }
365         (
366                 LPAREN
367                 argument_list[attr]
368                 RPAREN
369         )?
370         RBRACK
371         { module.AssemblyAttributes.Add(attr); }
372         ;
373                         
374 protected
375 class_definition [TypeMemberCollection container]
376         {
377                 TypeDefinition td = null;
378                 TypeReferenceCollection baseTypes = null;
379                 TypeMemberCollection members = null;
380                 GenericParameterDeclarationCollection genericParameters = null;
381         }:
382         (
383                 CLASS { td = new ClassDefinition(); } |
384                 STRUCT { td = new StructDefinition(); }
385         )
386         id:ID
387         {               
388                 td.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id);
389                 td.Name = id.getText();
390                 td.Modifiers = _modifiers;
391                 AddAttributes(td.Attributes);
392                 container.Add(td);
393                 baseTypes = td.BaseTypes;
394                 members = td.Members;
395                 genericParameters = td.GenericParameters;
396         }
397         (
398                 (LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK) |
399                 (OF generic_parameter_declaration[genericParameters])
400         )?
401         (base_types[baseTypes])?
402         begin_with_doc[td]                                      
403         (type_definition_member[members])*
404         end[td]
405         ;
406         
407 type_definition_member[TypeMemberCollection container]
410         attributes
411         modifiers
412         (                                               
413                 method[container] |
414                 event_declaration[container] |
415                 field_or_property[container] |
416                 type_definition[container]
417         )
419                         
420 protected
421 interface_definition [TypeMemberCollection container]
422         {
423                 InterfaceDefinition itf = null;
424                 TypeMemberCollection members = null;
425                 GenericParameterDeclarationCollection genericParameters = null;
426         } :
427         INTERFACE id:ID
428         {
429                 itf = new InterfaceDefinition(SourceLocationFactory.ToLexicalInfo(id));
430                 itf.Name = id.getText();
431                 itf.Modifiers = _modifiers;
432                 AddAttributes(itf.Attributes);
433                 container.Add(itf);
434                 members = itf.Members;
435                 genericParameters = itf.GenericParameters;
436         }
437         (
438                 (LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK) |
439                 (OF generic_parameter_declaration[genericParameters])
440         )?
441         (base_types[itf.BaseTypes])?
442         begin_with_doc[itf]
443         (
444                 attributes
445                 (
446                         interface_method[members] |
447                         event_declaration[members] |
448                         interface_property[members]
449                 )
450         )*
451         end[itf]
452         ;
453                         
454 protected
455 base_types[TypeReferenceCollection container]
456         {
457                 TypeReference tr = null;
458         }:
459         LPAREN 
460         (
461                 tr=type_reference { container.Add(tr); }
462                 (COMMA tr=type_reference { container.Add(tr); })*
463         )?
464         RPAREN
465         ;
466                         
467 protected
468 interface_method [TypeMemberCollection container]
469         {
470                 Method m = null;
471                 TypeReference rt = null;
472         }: 
473         DEF id:ID
474         {
475                 m = new Method(SourceLocationFactory.ToLexicalInfo(id));
476                 m.Name = id.getText();
477                 AddAttributes(m.Attributes);
478                 container.Add(m);
479         }
480         LPAREN parameter_declaration_list[m.Parameters] RPAREN
481         (AS rt=type_reference { m.ReturnType=rt; })?                    
482         (
483                 (eos docstring[m]) | (empty_block[m] (eos)?)
484         )
485         ;
486                         
487 protected
488 interface_property [TypeMemberCollection container]
489         {
490                 IToken id = null;
491                 Property p = null;
492                 TypeReference tr = null;
493                 ParameterDeclarationCollection parameters = null;
494         }:
495         (id1:ID {id=id1;} | s:SELF {id=s;})
496         {
497                 p = new Property(SourceLocationFactory.ToLexicalInfo(id));
498                 p.Name = id.getText();
499                 AddAttributes(p.Attributes);
500                 container.Add(p);
501                 parameters = p.Parameters;
502         }
503         ((LBRACK|LPAREN) parameter_declaration_list[parameters] (RBRACK|RPAREN))?
504         (AS tr=type_reference)?
505         {
506                 p.Type = tr;
507         }
508         begin_with_doc[p]
509                 (interface_property_accessor[p])+
510         end[p]
511         ; 
512                         
513 protected
514 interface_property_accessor[Property p]
515         {
516                 Method m = null;
517         }
518         :
519         attributes
520         (
521                 { null == p.Getter }?
522                 (
523                         gt:GET { m = p.Getter = new Method(SourceLocationFactory.ToLexicalInfo(gt)); m.Name = "get"; }
524                 )
525                 |
526                 { null == p.Setter }?
527                 (
528                         st:SET { m = p.Setter = new Method(SourceLocationFactory.ToLexicalInfo(st)); m.Name = "set"; }
529                 )                               
530         )
531         (
532                 eos | empty_block[m]
533         )
534         {
535                 AddAttributes(m.Attributes);
536         }
537         ;
538                         
539 protected
540 empty_block[Node node]: 
541                 begin
542                         eos
543                 end[node]
544                 ;
545                 
546 protected
547 event_declaration [TypeMemberCollection container]
548         {
549                 Event e = null;
550                 TypeReference tr = null;
551         }:
552         t:EVENT
553         id:ID AS tr=type_reference eos
554         {
555                 e = new Event(SourceLocationFactory.ToLexicalInfo(id), id.getText(), tr);
556                 e.Modifiers = _modifiers;
557                 AddAttributes(e.Attributes);
558                 container.Add(e);
559         }
560         docstring[e]
561         ;
563 protected
564 explicit_member_info returns [ExplicitMemberInfo emi]
565         {
566                 emi = null; _sbuilder.Length = 0;
567         }:
568         (ID DOT)=>(
569                 (
570                         (id:ID DOT)
571                         {
572                                 emi = new ExplicitMemberInfo(SourceLocationFactory.ToLexicalInfo(id));
573                                 _sbuilder.Append(id.getText());
574                         }
575                         (
576                                 (id2:ID DOT)
577                                 {
578                                         _sbuilder.Append('.');
579                                         _sbuilder.Append(id2.getText());
580                                 }
581                         )*
582                 )
583         )
584         {
585                 if (emi != null)
586                 {
587                         emi.InterfaceType = new SimpleTypeReference(emi.LexicalInfo);
588                         emi.InterfaceType.Name = _sbuilder.ToString();
589                 }
590         }
591         ;
593 protected
594 method [TypeMemberCollection container]
595         {
596                 Method m = null;
597                 TypeReference rt = null;
598                 TypeReference it = null;
599                 ExplicitMemberInfo emi = null;
600                 ParameterDeclarationCollection parameters = null;
601                 GenericParameterDeclarationCollection genericParameters = null;
602                 Block body = null;
603                 StatementCollection statements = null;
604         }: 
605         t:DEF
606         (
607                 (emi=explicit_member_info)? id:ID {
608                         if (emi != null)
609                         {
610                                 m = new Method(emi.LexicalInfo);
611                         }
612                         else
613                         {
614                                 m = new Method(SourceLocationFactory.ToLexicalInfo(id));
615                         }
616                         m.Name = id.getText();
617                         m.ExplicitInfo  = emi;
618                 }
619                 |
620                 c:CONSTRUCTOR { m = new Constructor(SourceLocationFactory.ToLexicalInfo(c)); } |
621                 d:DESTRUCTOR { m = new Destructor(SourceLocationFactory.ToLexicalInfo(d)); }
622         )       
623         {
624                 m.Modifiers = _modifiers;
625                 AddAttributes(m.Attributes);
626                 parameters = m.Parameters;
627                 genericParameters = m.GenericParameters;
628                 body = m.Body;
629                 statements = body.Statements;
630         }
631         (
632                 (
633                         LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK
634                 )
635                 |
636                 (
637                         OF generic_parameter_declaration[genericParameters]
638                 )
639         )?
640         LPAREN parameter_declaration_list[parameters] RPAREN
641                         attributes { AddAttributes(m.ReturnTypeAttributes); }
642                         (AS rt=type_reference { m.ReturnType = rt; })?
643                         begin_block_with_doc[m, body]
644                                 block[statements]
645                         end[body]
646         { 
647                 container.Add(m);
648         }
649         ;       
651 protected
652 property_header:        
653         ((ID|SELF) (DOT ID)*)
654         (
655                 LBRACK |
656                 LPAREN |
657                 ((AS type_reference)? COLON)
658         )
659         ;
660         
661 protected
662 field_or_property [TypeMemberCollection container]
663         {
664                 IToken id = null;
665                 TypeMember tm = null;
666                 TypeReference tr = null;
667                 Property p = null;
668                 Field field = null;
669                 ExplicitMemberInfo emi = null;
670                 Expression initializer = null;
671                 ParameterDeclarationCollection parameters = null;
672         }: 
673         (property_header)=>(
674                 (emi=explicit_member_info)? (id1:ID {id=id1;}| s:SELF {id=s;})
675                 (               
676                         
677                         {
678                                 if (emi != null)
679                                         p = new Property(emi.LexicalInfo);
680                                 else
681                                         p = new Property(SourceLocationFactory.ToLexicalInfo(id));
682                                 p.Name = id.getText();
683                                 p.ExplicitInfo = emi;
684                                 AddAttributes(p.Attributes);
685                                 parameters = p.Parameters;
686                         }
687                         ((LBRACK|LPAREN) parameter_declaration_list[parameters] (RBRACK|RPAREN))?
688                         (AS tr=type_reference)?
689                         {                                                       
690                                 p.Type = tr;
691                                 tm = p;
692                                 tm.Modifiers = _modifiers;
693                         }               
694                         begin_with_doc[p]
695                                 (property_accessor[p])+
696                         end[p]
697                 )
698         )
699         { container.Add(tm); }
700         |
701         (
702                 id2:ID
703                 {
704                         tm = field = new Field(SourceLocationFactory.ToLexicalInfo(id2));
705                         field.Name = id2.getText();
706                         field.Modifiers = _modifiers;
707                         AddAttributes(field.Attributes);
708                 }
709                 (               
710                         (AS tr=type_reference { field.Type = tr; })?
711                         (
712                                 (
713                                         ASSIGN initializer=declaration_initializer
714                                         { field.Initializer = initializer;      }
715                                 ) |
716                                 eos
717                         )
718                         docstring[field]
719                 )
720         )
721         { container.Add(tm); }
723         
724 declaration_initializer returns [Expression e]
726         e = null;
728         (slicing_expression (COLON|DO|DEF))=>(e=slicing_expression e=method_invocation_block[e]) |
729         (e=array_or_expression eos) |
730         (e=callable_expression)
733 protected
734 property_accessor[Property p]
735         {               
736                 Method m = null;
737                 Block body = null;
738         }:
739         attributes
740         modifiers
741         (
742                 { null == p.Getter }?
743                 (
744                         gt:GET
745                         {
746                                 p.Getter = m = new Method(SourceLocationFactory.ToLexicalInfo(gt));             
747                                 m.Name = "get";
748                         }
749                 )
750                 |
751                 { null == p.Setter }?
752                 (
753                         st:SET
754                         {
755                                 p.Setter = m = new Method(SourceLocationFactory.ToLexicalInfo(st));
756                                 m.Name = "set";
757                         }
758                 )
759         )
760         {
761                 AddAttributes(m.Attributes);
762                 m.Modifiers = _modifiers;
763                 body = m.Body;
764         }
765         compound_stmt[body]
766         ;
767         
768 protected
769 globals[Module container]:      
770         (eos)?
771         (stmt[container.Globals.Statements])*
772         ;
773         
774 protected
775 block[StatementCollection container]:
776         (eos)?
777         (                       
778                 stmt[container]
779         )*
780         ; 
781         
782 protected
783 modifiers
785         _modifiers = TypeMemberModifiers.None;
787         (
788         STATIC { _modifiers |= TypeMemberModifiers.Static; } |
789         PUBLIC { _modifiers |= TypeMemberModifiers.Public; } |
790         PROTECTED { _modifiers |= TypeMemberModifiers.Protected; } |
791         PRIVATE { _modifiers |= TypeMemberModifiers.Private; } |
792         INTERNAL { _modifiers |= TypeMemberModifiers.Internal; } |                      
793         FINAL { _modifiers |= TypeMemberModifiers.Final; } |
794         TRANSIENT { _modifiers |= TypeMemberModifiers.Transient; } |
795         OVERRIDE { _modifiers |= TypeMemberModifiers.Override; } |
796         ABSTRACT { _modifiers |= TypeMemberModifiers.Abstract; } |
797         VIRTUAL { _modifiers |= TypeMemberModifiers.Virtual; } |
798         PARTIAL { _modifiers |= TypeMemberModifiers.Partial; }  
799         )*
802 protected
803 parameter_modifier returns [ParameterModifiers pm]
804         {
805                 pm = ParameterModifiers.None;
806         }:
807         (
808                 REF { pm = ParameterModifiers.Ref; }
809         )
810         ;
812 protected       
813 parameter_declaration_list[ParameterDeclarationCollection c]
814         {
815                 bool variableArguments = false;
816         }: 
817         (variableArguments=parameter_declaration[c]
818         ( {!variableArguments}?(COMMA variableArguments=parameter_declaration[c]) )* )?
819         { c.VariableNumber = variableArguments; }
820         ;
822 protected
823 parameter_declaration[ParameterDeclarationCollection c]
824         returns [bool variableArguments]
825         {               
826                 IToken id = null;
827                 TypeReference tr = null;
828                 ParameterModifiers pm = ParameterModifiers.None;
829                 variableArguments = false;
830         }: 
831         attributes
832         (
833                 (
834                         MULTIPLY { variableArguments=true; }
835                         id1:ID (AS tr=array_type_reference)?
836                         { id = id1; }
837                 )
838                 |
839                 (
840                         (pm=parameter_modifier)?
841                         id2:ID (AS tr=type_reference)?
842                         { id = id2; }
843                 )
844         )
845         {
846                 ParameterDeclaration pd = new ParameterDeclaration(SourceLocationFactory.ToLexicalInfo(id));
847                 pd.Name = id.getText();
848                 pd.Type = tr;
849                 pd.Modifiers = pm;
850                 AddAttributes(pd.Attributes);
851                 c.Add(pd);
852         } 
853         ;
854         
855 protected       
856 callable_parameter_declaration_list[ParameterDeclarationCollection c]:
857         (callable_parameter_declaration[c]
858         (COMMA callable_parameter_declaration[c])*)?
859         ;
861 protected
862 callable_parameter_declaration[ParameterDeclarationCollection c]
863         {               
864                 TypeReference tr = null;
865                 ParameterModifiers pm = ParameterModifiers.None;
866         }: 
867         (
868                 (pm=parameter_modifier)?
869                 (tr=type_reference)
870         )
871         {
872                 ParameterDeclaration pd = new ParameterDeclaration(tr.LexicalInfo);
873                 pd.Name = "arg" + c.Count;
874                 pd.Type = tr;
875                 pd.Modifiers = pm;
876                 c.Add(pd);
877         } 
878         ;
879         
880 protected
881 generic_parameter_declaration_list[GenericParameterDeclarationCollection c]:
882         generic_parameter_declaration[c]
883         (
884                 COMMA generic_parameter_declaration[c]
885         )*
886         ;
888 protected 
889 generic_parameter_declaration[GenericParameterDeclarationCollection c]:
890         id:ID 
891         {
892                 GenericParameterDeclaration gpd = new GenericParameterDeclaration(SourceLocationFactory.ToLexicalInfo(id));
893                 gpd.Name = id.getText();
894                 c.Add(gpd);
895         }
896         ;
897         
898 protected
899 callable_type_reference returns [CallableTypeReference ctr]
900         {
901                 ctr = null;
902                 TypeReference tr = null;
903                 ParameterDeclarationCollection parameters = null;
904         }:      
905         c:CALLABLE LPAREN
906         {
907                 ctr = new CallableTypeReference(SourceLocationFactory.ToLexicalInfo(c));
908                 parameters = ctr.Parameters;
909         }
910         callable_parameter_declaration_list[parameters]
911         RPAREN
912         (AS tr=type_reference { 
913                 ctr.ReturnType = tr; 
914                 }
915         )?
916         ;
917         
918 protected
919 array_type_reference returns [ArrayTypeReference atr]
920         {
921                 TypeReference tr = null;
922                 atr = null;
923                 IntegerLiteralExpression rank = null;
924         }:
925         lparen:LPAREN
926         {
927                 atr = new ArrayTypeReference(SourceLocationFactory.ToLexicalInfo(lparen));
928         }
929         (
930                 tr=type_reference { atr.ElementType = tr; }
931                 (COMMA rank=integer_literal { atr.Rank = rank; })?
932         )
933         rparen:RPAREN
934         ;
936 protected
937 type_reference_list [TypeReferenceCollection container]
938         {
939                 TypeReference tr = null;
940         }:
941         tr=type_reference { container.Add(tr); }
942         (options { greedy=true; }:
943                 COMMA tr=type_reference { container.Add(tr); }
944         )*
947 protected
948 splice_type_reference returns [SpliceTypeReference tr]
950         tr = null;
951         Expression e = null;
953         begin:SPLICE_BEGIN e=atom
954         {
955                 tr = new SpliceTypeReference(SourceLocationFactory.ToLexicalInfo(begin), e);
956         }
959 protected
960 type_reference returns [TypeReference tr]
961         {
962                 tr = null;
963                 IToken id = null;
964                 TypeReferenceCollection arguments = null;
965                 GenericTypeDefinitionReference gtdr = null;
966         }: 
967         tr=splice_type_reference
968         |
969         tr=array_type_reference
970         |
971         (CALLABLE LPAREN)=>(tr=callable_type_reference)
972         |
973         (
974                 id=type_name
975                 (
976                         (
977                                 LBRACK (OF)? 
978                                 (
979                                         (
980                                                 MULTIPLY
981                                                 {
982                                                         gtdr = new GenericTypeDefinitionReference(SourceLocationFactory.ToLexicalInfo(id));
983                                                         gtdr.Name = id.getText();
984                                                         gtdr.GenericPlaceholders = 1;
985                                                         tr = gtdr;                                                                              
986                                                 }
987                                                 ( 
988                                                         COMMA MULTIPLY
989                                                         {
990                                                                 gtdr.GenericPlaceholders++;
991                                                         }
992                                                 )*
993                                                 RBRACK
994                                         )
995                                         |
996                                         (
997                                                 {
998                                                         GenericTypeReference gtr = new GenericTypeReference(SourceLocationFactory.ToLexicalInfo(id), id.getText());
999                                                         arguments = gtr.GenericArguments;
1000                                                         tr = gtr;
1001                                                 }
1002                                                 type_reference_list[arguments]
1003                                                 RBRACK
1004                                         )
1005                                 )
1006                         )
1007                         |
1008                         (
1009                                 OF MULTIPLY
1010                                 {
1011                                         gtdr = new GenericTypeDefinitionReference(SourceLocationFactory.ToLexicalInfo(id));
1012                                         gtdr.Name = id.getText();
1013                                         gtdr.GenericPlaceholders = 1;
1014                                         tr = gtdr;
1015                                 }
1016                         )
1017                         |
1018                         (
1019                                 OF tr=type_reference
1020                                 {
1021                                         GenericTypeReference gtr = new GenericTypeReference(SourceLocationFactory.ToLexicalInfo(id), id.getText());
1022                                         gtr.GenericArguments.Add(tr);
1023                                         tr = gtr;
1024                                 }
1025                         )
1026                         |
1027                         {
1028                                 SimpleTypeReference str = new SimpleTypeReference(SourceLocationFactory.ToLexicalInfo(id));
1029                                 str.Name = id.getText();
1030                                 tr = str;
1031                         }
1032                 )
1033                 (NULLABLE_SUFFIX {
1034                                 GenericTypeReference ntr = new GenericTypeReference(tr.LexicalInfo, "System.Nullable");
1035                                 ntr.GenericArguments.Add(tr);
1036                                 tr = ntr;
1037                         }
1038                 )?
1039         )
1040         ;
1042         
1043 protected
1044 type_name returns [IToken id]
1045         {
1046                 id = null;
1047         }:
1048         id=identifier | c:CALLABLE { id=c; } | ch:CHAR { id=ch; }
1049         ;
1051 protected
1052 begin: COLON;
1054 protected
1055 begin_with_doc[Node node]: COLON (eos docstring[node])?;
1056         
1057 protected
1058 begin_block_with_doc[Node node, Block block]:
1059         begin:COLON (eos docstring[node])?
1060         {
1061                 block.LexicalInfo = SourceLocationFactory.ToLexicalInfo(begin);
1062         }
1063         ;
1065 protected
1066 end[Node node] :
1067         t:END { node.EndSourceLocation = SourceLocationFactory.ToSourceLocation(t); }
1068         (eos)?
1069         ;
1071 protected
1072 compound_stmt[Block b]
1074         StatementCollection statements = null;
1076                 begin:COLON
1077                 {
1078                         b.LexicalInfo = SourceLocationFactory.ToLexicalInfo(begin);
1079                         statements = b.Statements;
1080                 }
1081                         block[statements]
1082                 end[b]
1083                 ;
1084                 
1085 protected
1086 closure_macro_stmt returns [MacroStatement returnValue]
1087         {
1088                 returnValue = null;
1089                 MacroStatement macro = new MacroStatement();
1090         }:
1091         id:ID expression_list[macro.Arguments]
1092         {
1093                 macro.Name = id.getText();
1094                 macro.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id);            
1095                 returnValue = macro;
1096         }
1099                 
1100 protected
1101 macro_stmt returns [MacroStatement returnValue]
1102         {
1103                 returnValue = null;
1104                 MacroStatement macro = new MacroStatement();
1105                 StatementModifier modifier = null;
1106         }:
1107         id:ID expression_list[macro.Arguments]
1108         (
1109                 compound_stmt[macro.Block] |
1110                 eos |
1111                 modifier=stmt_modifier eos { macro.Modifier = modifier; }
1112         )
1113         {
1114                 macro.Name = id.getText();
1115                 macro.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id);
1116                 
1117                 returnValue = macro;
1118         }
1121 protected
1122 goto_stmt returns [GotoStatement stmt]
1123         {
1124                 stmt = null;
1125         }:
1126         token:GOTO label:ID
1127         {
1128                 stmt = new GotoStatement(SourceLocationFactory.ToLexicalInfo(token),
1129                                         new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(label), label.getText()));
1130         }
1131         ;
1132         
1133 protected
1134 label_stmt returns [LabelStatement stmt]
1135         {
1136                 stmt = null;
1137         }:
1138         token:COLON label:ID
1139         {
1140                 stmt = new LabelStatement(SourceLocationFactory.ToLexicalInfo(token), label.getText());
1141         }
1142         ;
1144 protected
1145 stmt [StatementCollection container]
1146         {
1147                 Statement s = null;
1148                 StatementModifier m = null;
1149         }:              
1150         (                
1151                 s=for_stmt |
1152                 s=while_stmt |
1153                 s=if_stmt |
1154                 s=unless_stmt |
1155                 s=try_stmt |
1156                 (atom (NEWLINE)+ DOT)=>(s=expression_stmt eos) |
1157                 (ID (expression)?)=>{IsValidMacroArgument(LA(2))}? s=macro_stmt |
1158                 (slicing_expression (ASSIGN|(COLON|DO|DEF)))=> s=assignment_or_method_invocation_with_block_stmt |
1159                 s=return_stmt |
1160                 (declaration COMMA)=> s=unpack_stmt |
1161                 s=declaration_stmt |
1162                 (               
1163                         (
1164                                 s=goto_stmt |
1165                                 s=label_stmt |
1166                                 s=yield_stmt |
1167                                 s=break_stmt |
1168                                 s=continue_stmt |                               
1169                                 s=raise_stmt |
1170                                 s=expression_stmt                               
1171                         )
1172                         (                       
1173                                 m=stmt_modifier { s.Modifier = m; }
1174                         )?
1175                         eos
1176                 )
1177         )
1178         {
1179                 if (null != s)
1180                 {
1181                         container.Add(s);
1182                 }
1183         }
1184         ;               
1186 protected
1187 stmt_modifier returns [StatementModifier m]
1188         {
1189                 m = null;
1190                 Expression e = null;
1191                 IToken t = null;
1192                 StatementModifierType type = StatementModifierType.None;
1193         }:
1194         (
1195                 i:IF { t = i; type = StatementModifierType.If; } |
1196                 u:UNLESS { t = u; type = StatementModifierType.Unless; } |
1197                 w:WHILE { t = w; type = StatementModifierType.While; }
1198         )
1199         e=boolean_expression
1200         {
1201                 m = new StatementModifier(SourceLocationFactory.ToLexicalInfo(t));
1202                 m.Type = type;
1203                 m.Condition = e;
1204         }
1205         ;
1206         
1207 protected
1208 callable_or_expression returns [Expression e]
1209         {
1210                 e = null;
1211         }:
1212         e=callable_expression|
1213         e=array_or_expression
1214         ;
1215         
1217 protected
1218 closure_parameters_test:
1219         (parameter_modifier)?
1220         (ID (AS type_reference)?)
1221         (COMMA ID (AS type_reference)?)*
1222         BITWISE_OR
1223         ;
1224         
1225 protected
1226 internal_closure_stmt[Block block]
1227         {
1228                 Statement stmt = null;
1229                 StatementModifier modifier = null;
1230         }:
1231         (
1232                 stmt=return_expression_stmt |
1233                 (
1234                         (
1235                                 (declaration COMMA)=>stmt=unpack |
1236                                 {IsValidMacroArgument(LA(2))}? stmt=closure_macro_stmt | 
1237                                 stmt=closure_expression_stmt |
1238                                 stmt=raise_stmt |
1239                                 stmt=yield_stmt                 
1240                         )
1241                         (modifier=stmt_modifier { stmt.Modifier = modifier; })?         
1242                 )
1243         )
1244         {
1245                 if (null != stmt)
1246                 {
1247                         block.Add(stmt);
1248                 }
1249         }
1250         ;
1252 protected
1253 closure_expression_stmt returns [Statement s]
1255         s = null;
1256         Expression e = null;
1258         e=array_or_expression
1259         { s = new ExpressionStatement(e); }
1260 ;       
1262 protected
1263 closure_expression returns [Expression e]
1264         {
1265                 e = null;
1266                 BlockExpression cbe = null;
1267                 ParameterDeclarationCollection parameters = null;
1268                 Block body = null;
1269         }:
1270         anchorBegin:LBRACE
1271                 {
1272                         e = cbe = new BlockExpression(SourceLocationFactory.ToLexicalInfo(anchorBegin));
1273                         cbe.Annotate("inline");
1274                         parameters = cbe.Parameters;
1275                         body = cbe.Body;
1276                 }
1277                 
1278                 (
1279                         (closure_parameters_test)=>(
1280                                 parameter_declaration_list[parameters]
1281                                 BITWISE_OR
1282                         ) |
1283                 )
1284                 (
1285                         internal_closure_stmt[body]
1286                         (
1287                                 eos
1288                                 (internal_closure_stmt[body])?
1289                         )*
1290                 )
1291         anchorEnd:RBRACE
1292         ;
1293         
1294 protected
1295 callable_expression returns [Expression e]
1297         e = null;
1298         Block body = null;
1299         BlockExpression cbe = null;
1300         TypeReference rt = null;
1301         IToken anchor = null;
1303         (COLON)=>(
1304                 { body = new Block(); }
1305                 compound_stmt[body]
1306                 { e = new BlockExpression(body.LexicalInfo, body); }
1307         )
1308         |(
1309                 (
1310                         (doAnchor:DO { anchor = doAnchor; }) |
1311                         (defAnchor:DEF { anchor = defAnchor; })
1312                 )
1313                 {
1314                         e = cbe = new BlockExpression(SourceLocationFactory.ToLexicalInfo(anchor));
1315                         body = cbe.Body;
1316                 }
1317                 (
1318                         LPAREN parameter_declaration_list[cbe.Parameters] RPAREN
1319                         (AS rt=type_reference { cbe.ReturnType = rt; })?
1320                 )?
1321                         compound_stmt[body]
1322         )
1324         
1325 protected
1326 try_stmt returns [TryStatement s]
1327         {
1328                 s = null;               
1329                 Block eblock = null;
1330                 Block lastBlock = null;
1331         }:
1332         t:TRY { s = new TryStatement(SourceLocationFactory.ToLexicalInfo(t)); } begin
1333                 {s.ProtectedBlock = new Block();} block[s.ProtectedBlock.Statements] { lastBlock = s.ProtectedBlock; }
1334         (EXCEPT|FAILURE|ENSURE)=>
1335         (
1336                 lastBlock = exception_handler[s]
1337         )*
1338         (
1339                 ftoken:FAILURE { eblock = new Block(SourceLocationFactory.ToLexicalInfo(ftoken)); } begin
1340                         block[eblock.Statements]
1341                 { s.FailureBlock = lastBlock = eblock; }
1342         )?
1343         (
1344                 etoken:ENSURE { eblock = new Block(SourceLocationFactory.ToLexicalInfo(etoken)); } begin
1345                         block[eblock.Statements]
1346                 { s.EnsureBlock = lastBlock = eblock; }
1347         )?
1348         end[lastBlock]
1349         ;
1350         
1351 protected
1352 exception_handler [TryStatement t] returns [Block lastBlock]
1353         {
1354                 ExceptionHandler eh = null;             
1355                 TypeReference tr = null;
1356                 Expression e = null;
1357                 lastBlock = null;
1358         }:
1359         c:EXCEPT (x:ID)? (AS tr=type_reference)? ((IF|u:UNLESS) e=expression)? begin
1360         {
1361                 eh = new ExceptionHandler(SourceLocationFactory.ToLexicalInfo(c));
1362                 
1363                 eh.Declaration = new Declaration();
1364                 eh.Declaration.Type = tr;
1365                 
1366                 if (x != null)
1367                 {
1368                         eh.Declaration.LexicalInfo = SourceLocationFactory.ToLexicalInfo(x);
1369                         eh.Declaration.Name = x.getText();              
1370                 }
1371                 else
1372                 {
1373                         eh.Declaration.Name = null;
1374                         eh.Flags |= ExceptionHandlerFlags.Anonymous;
1375                 }
1376                 if (tr != null)
1377                 {
1378                         eh.Declaration.LexicalInfo = tr.LexicalInfo;
1379                 }
1380                 else if (x != null)
1381                 {
1382                         eh.Declaration.LexicalInfo = eh.LexicalInfo;
1383                 }
1384                 if(tr == null)
1385                 {
1386                         eh.Flags |= ExceptionHandlerFlags.Untyped;
1387                 }
1388                 if (e != null)
1389                 {
1390                         if(u != null)
1391                         {
1392                                 UnaryExpression not = new UnaryExpression(SourceLocationFactory.ToLexicalInfo(u));
1393                                 not.Operator = UnaryOperatorType.LogicalNot;
1394                                 not.Operand = e;
1395                                 e = not;
1396                         }
1397                         eh.FilterCondition = e;
1398                         eh.Flags |= ExceptionHandlerFlags.Filter;
1399                 }
1400                 eh.Block = new Block(SourceLocationFactory.ToLexicalInfo(c));
1401         }               
1402         block[eh.Block.Statements]
1403         {
1404                 lastBlock = eh.Block;
1405                 t.ExceptionHandlers.Add(eh);
1406         }
1407         ;
1408         
1409 protected
1410 raise_stmt returns [RaiseStatement s]
1411         {
1412                 s = null;
1413                 Expression e = null;
1414         }:
1415         t:RAISE (e=expression)?
1416         {
1417                 s = new RaiseStatement(SourceLocationFactory.ToLexicalInfo(t));
1418                 s.Exception = e;
1419         }
1420         ;
1421         
1422 protected
1423 declaration_stmt returns [DeclarationStatement s]
1424         {
1425                 s = null;
1426                 TypeReference tr = null;
1427                 Expression initializer = null;
1428                 StatementModifier m = null;
1429         }:
1430         id:ID AS tr=type_reference
1431         (
1432                 (ASSIGN initializer=declaration_initializer) |
1433                 ((m=stmt_modifier)? eos)
1434         )
1435         {
1436                 Declaration d = new Declaration(SourceLocationFactory.ToLexicalInfo(id));
1437                 d.Name = id.getText();
1438                 d.Type = tr;
1439                 
1440                 s = new DeclarationStatement(d.LexicalInfo);
1441                 s.Declaration = d;
1442                 s.Initializer = initializer;
1443                 s.Modifier = m;
1444         }
1445         ;
1447 protected
1448 expression_stmt returns [ExpressionStatement s]
1449         {
1450                 s = null;
1451                 Expression e = null;
1452         }:
1453         e=assignment_expression
1454         {
1455                 s = new ExpressionStatement(e);
1456         }
1457         ;       
1458 protected
1459 return_expression_stmt returns [ReturnStatement s]
1460         {
1461                 s = null;
1462                 Expression e = null;
1463                 StatementModifier modifier = null;
1464         }:
1465         r:RETURN (e=array_or_expression)?
1466         (modifier=stmt_modifier)?
1467         {
1468                 s = new ReturnStatement(SourceLocationFactory.ToLexicalInfo(r));
1469                 s.Modifier = modifier;
1470                 s.Expression = e;
1471         }
1472         ;
1474 protected
1475 return_stmt returns [ReturnStatement s]
1476         {
1477                 s = null;
1478                 Expression e = null;
1479                 StatementModifier modifier = null;
1480         }:
1481         r:RETURN 
1482                 (
1483                         (
1484                                 e=array_or_expression
1485                                 (
1486                                         (COLON|DO)=>e=method_invocation_block[e] |
1487                                         ((modifier=stmt_modifier)? eos)
1488                                 )
1489                         ) |
1490                         (
1491                                 e=callable_expression
1492                         ) |
1493                         (
1494                                 (modifier=stmt_modifier)?
1495                                 eos
1496                         )
1497                 )
1498         {
1499                 s = new ReturnStatement(SourceLocationFactory.ToLexicalInfo(r));
1500                 s.Modifier = modifier;
1501                 s.Expression = e;
1502         }
1503         ;
1505 protected
1506 yield_stmt returns [YieldStatement s]
1507         {
1508                 s = null;
1509                 Expression e = null;
1510         }:
1511         yt:YIELD (e=array_or_expression)?
1512         {
1513                 s = new YieldStatement(SourceLocationFactory.ToLexicalInfo(yt));
1514                 s.Expression = e;
1515         }
1516         ;
1518 protected
1519 break_stmt returns [BreakStatement s]
1520         { s = null; }:
1521         b:BREAK
1522         { s = new BreakStatement(SourceLocationFactory.ToLexicalInfo(b)); }
1523         ;
1525 protected
1526 continue_stmt returns [Statement s]
1527         { s = null; }:
1528         c:CONTINUE
1529         { s = new ContinueStatement(SourceLocationFactory.ToLexicalInfo(c)); }
1530         ;
1531         
1532 protected
1533 unless_stmt returns [UnlessStatement us]
1534         {
1535                 us = null;
1536                 Expression condition = null;
1537         }:
1538         u:UNLESS condition=expression
1539         {
1540                 us = new UnlessStatement(SourceLocationFactory.ToLexicalInfo(u));
1541                 us.Condition = condition;
1542         }
1543         compound_stmt[us.Block]
1544         ;
1546 protected
1547 for_stmt returns [ForStatement fs]
1548         {
1549                 fs = null;
1550                 Expression iterator = null;
1551                 DeclarationCollection declarations = null;
1552                 Block body = null;
1553                 Block lastBlock = null;
1554         }:
1555         f:FOR
1556         {
1557                 fs = new ForStatement(SourceLocationFactory.ToLexicalInfo(f));
1558                 declarations = fs.Declarations;
1559                 lastBlock = body = fs.Block;
1560         }
1561                 declaration_list[declarations] IN iterator=array_or_expression
1562                 { fs.Iterator = iterator; }
1563                 begin block[body.Statements]
1564         (
1565                 or:OR { lastBlock = fs.OrBlock = new Block(SourceLocationFactory.ToLexicalInfo(or)); }
1566                 begin block[fs.OrBlock.Statements]
1567         )?
1568         (
1569                 et:THEN { lastBlock = fs.ThenBlock = new Block(SourceLocationFactory.ToLexicalInfo(et)); }
1570                 begin block[fs.ThenBlock.Statements]
1571         )?
1572         end[lastBlock]
1573         ;
1574                 
1575 protected
1576 while_stmt returns [WhileStatement ws]
1577         {
1578                 ws = null;
1579                 Expression e = null;
1580                 Block lastBlock = null;
1581         }:
1582         w:WHILE e=expression
1583         {
1584                 ws = new WhileStatement(SourceLocationFactory.ToLexicalInfo(w));
1585                 ws.Condition = e;
1586                 lastBlock = ws.Block;
1587         }
1588                 begin block[ws.Block.Statements]
1589         (
1590                 or:OR { lastBlock = ws.OrBlock = new Block(SourceLocationFactory.ToLexicalInfo(or)); }
1591                 begin block[ws.OrBlock.Statements]
1592         )?
1593         (
1594                 et:THEN { lastBlock = ws.ThenBlock = new Block(SourceLocationFactory.ToLexicalInfo(et)); }
1595                 begin block[ws.ThenBlock.Statements]
1596         )?
1597         end[lastBlock]
1598         ;
1599                 
1600 protected
1601 if_stmt returns [IfStatement returnValue]
1602         {
1603                 returnValue = null;
1604                 
1605                 IfStatement s = null;
1606                 Expression e = null;
1607                 Block lastBlock = null;
1608         }:
1609         it:IF e=expression
1610         {
1611                 returnValue = s = new IfStatement(SourceLocationFactory.ToLexicalInfo(it));
1612                 s.Condition = e;
1613                 lastBlock = s.TrueBlock = new Block();
1614         }
1615         begin block[s.TrueBlock.Statements]
1616         (
1617                 ei:ELIF e=expression
1618                 {
1619                         s.FalseBlock = new Block();
1620                         
1621                         IfStatement elif = new IfStatement(SourceLocationFactory.ToLexicalInfo(ei));
1622                         lastBlock = elif.TrueBlock = new Block();
1623                         elif.Condition = e;
1624                         
1625                         s.FalseBlock.Add(elif);
1626                         s = elif;
1627                 }
1628                 begin block[s.TrueBlock.Statements]
1629         )*
1630         (
1631                 et:ELSE { lastBlock = s.FalseBlock = new Block(SourceLocationFactory.ToLexicalInfo(et)); }
1632                 begin block[s.FalseBlock.Statements]
1633         )?
1634         end[lastBlock]
1635         ;
1636                 
1637 protected
1638 unpack_stmt returns [UnpackStatement s]
1639         {
1640                 s = null;
1641                 StatementModifier m = null;
1642         }:      
1643         s=unpack (m=stmt_modifier)? eos
1644         {
1645                 s.Modifier = m;
1646         }
1647 ;               
1649 protected
1650 unpack returns [UnpackStatement s]
1652         Declaration d = null;
1653         s = new UnpackStatement();
1654         Expression e = null;
1656         d=declaration COMMA { s.Declarations.Add(d); }
1657         (declaration_list[s.Declarations])?
1658         t:ASSIGN e=array_or_expression
1659         {
1660                 s.Expression = e;
1661                 s.LexicalInfo = SourceLocationFactory.ToLexicalInfo(t);
1662         }
1664         
1666                 
1667 protected
1668 declaration_list[DeclarationCollection dc]
1669         {
1670                 Declaration d = null;
1671         }:
1672         d=declaration { dc.Add(d); }
1673         (COMMA d=declaration { dc.Add(d); })*
1674         ;
1675                 
1676 protected
1677 declaration returns [Declaration d]
1678         {
1679                 d = null;
1680                 TypeReference tr = null;
1681         }:
1682         id:ID (AS tr=type_reference)?
1683         {
1684                 d = new Declaration(SourceLocationFactory.ToLexicalInfo(id));
1685                 d.Name = id.getText();
1686                 d.Type = tr;
1687         }
1688         ;
1689         
1690 protected
1691 array_or_expression returns [Expression e]
1692         {
1693                 e = null;
1694                 ArrayLiteralExpression tle = null;
1695         } :
1696                 (
1697                         // tupla vazia: , ou (,)
1698                         c:COMMA { e = new ArrayLiteralExpression(SourceLocationFactory.ToLexicalInfo(c)); }
1699                 ) |
1700                 (
1701                         e=expression
1702                         ( options { greedy=true; }:
1703                                 t:COMMA
1704                                 {                                       
1705                                         tle = new ArrayLiteralExpression(e.LexicalInfo);
1706                                         tle.Items.Add(e);               
1707                                 }
1708                                 ( options { greedy=true; }:
1709                                         e=expression { tle.Items.Add(e); }
1710                                         ( options { greedy=true; }:
1711                                                 COMMA
1712                                                 e=expression { tle.Items.Add(e); }
1713                                         )*
1714                                         (COMMA)?
1715                                 )?
1716                                 {
1717                                         e = tle;
1718                                 }
1719                         )?
1720                 )
1721         ;
1722                         
1723 protected
1724 expression returns [Expression e]
1725         {
1726                 e = null;
1727                 
1728                 ExtendedGeneratorExpression mge = null;
1729                 GeneratorExpression ge = null;
1730         } :
1731         e=boolean_expression
1732                 
1733         ( options { greedy = true; } :
1734                 f:FOR
1735                 {
1736                         ge = new GeneratorExpression(SourceLocationFactory.ToLexicalInfo(f));
1737                         ge.Expression = e;
1738                         e = ge;
1739                 }
1740                 generator_expression_body[ge]
1741                 (
1742                         f2:FOR
1743                         {
1744                                 if (null == mge)
1745                                 {
1746                                         mge = new ExtendedGeneratorExpression(SourceLocationFactory.ToLexicalInfo(f));
1747                                         mge.Items.Add(ge);
1748                                         e = mge;
1749                                 }
1750                                 
1751                                 ge = new GeneratorExpression(SourceLocationFactory.ToLexicalInfo(f2));
1752                                 mge.Items.Add(ge);
1753                         }
1754                         generator_expression_body[ge]
1755                 )*
1756         )?
1759 generator_expression_body[GeneratorExpression ge]
1761         StatementModifier filter = null;
1762         Expression iterator = null;
1763         DeclarationCollection declarations = null == ge ? null : ge.Declarations;
1765         declaration_list[declarations]
1766         IN
1767         iterator=boolean_expression { ge.Iterator = iterator; }
1768         (
1769                 filter=stmt_modifier { ge.Filter = filter; }
1770         )?
1772         
1773 protected
1774 boolean_expression returns [Expression e]
1775         {
1776                 e = null;
1777                 Expression r = null;
1778         }
1779         :
1780         (
1781                 e=boolean_term
1782                 (
1783                         ot:OR
1784                         r=boolean_term
1785                         {
1786                                 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(ot));
1787                                 be.Operator = BinaryOperatorType.Or;
1788                                 be.Left = e;
1789                                 be.Right = r;
1790                                 e = be;
1791                         }
1792                 )*
1793         )
1794         ;
1796 protected
1797 boolean_term returns [Expression e]
1798         {
1799                 e = null;
1800                 Expression r = null;
1801         }
1802         :
1803         e=not_expression
1804         (
1805                 at:AND
1806                 r=not_expression
1807                 {
1808                         BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(at));
1809                         be.Operator = BinaryOperatorType.And;
1810                         be.Left = e;
1811                         be.Right = r; 
1812                         e = be;
1813                 }
1814         )*
1815         ;
1816         
1817 protected
1818 method_invocation_block[Expression e] returns [MethodInvocationExpression mi]
1820         Expression block = null;
1821         mi = null;
1823         block=callable_expression
1824         {
1825                 mi = e as MethodInvocationExpression;
1826                 if (null == mi) 
1827                 {
1828                         mi = new MethodInvocationExpression(e.LexicalInfo, e);
1829                 }
1830                 mi.Arguments.Add(block);
1831         }
1833         
1834 ast_literal_expression returns [QuasiquoteExpression e]
1836         Node node = null;
1837         e = null;
1839         begin:QQ_BEGIN
1840         { e = new QuasiquoteExpression(SourceLocationFactory.ToLexicalInfo(begin)); }
1841         (
1842                 (expression QQ_END)=>node=expression { e.Node = node; }
1843                 | ((eos)? ast_literal_block[e])
1844         )
1845         end:QQ_END
1846         { e.EndSourceLocation = SourceLocationFactory.ToSourceLocation(end); }
1849 type_definition_member_prediction:
1850         attributes
1851         modifiers
1852         (CLASS|INTERFACE|STRUCT|DEF|EVENT|(ID (AS|ASSIGN)))
1855 ast_literal_block[QuasiquoteExpression e]
1857         // TODO: either cache or construct these objects on demand
1858         TypeMemberCollection collection = new TypeMemberCollection();
1859         Block block = new Block();
1860         StatementCollection statements = block.Statements;
1861         Node node = null;
1862 }: 
1863         (type_definition_member_prediction)=>(
1864                 type_definition_member[collection]
1865                 { e.Node = collection[0]; }
1866         )
1867         | (
1868                 (stmt[statements])+
1869                 {
1870                         if (block.Statements.Count > 0)
1871                         {
1872                                 e.Node = block.Statements.Count > 1 ? block : block.Statements[0];
1873                         }
1874                 }
1875         )
1879 protected
1880 assignment_or_method_invocation_with_block_stmt returns [Statement stmt]
1881         {
1882                 stmt = null;
1883                 Expression lhs = null;
1884                 Expression rhs = null;
1885                 StatementModifier modifier = null;
1886                 BinaryOperatorType binaryOperator = BinaryOperatorType.None;
1887                 IToken token = null;
1888         }:
1889         lhs=slicing_expression
1890         (
1891                 (COLON|DO)=>(
1892                         lhs=method_invocation_block[lhs]
1893                         { stmt = new ExpressionStatement(lhs); }
1894                 ) |
1895                 (
1896                         (
1897                         op:ASSIGN { token = op; binaryOperator = OperatorParser.ParseAssignment(op.getText()); }
1898                                 (
1899                                         (COLON|DEF|DO)=>rhs=callable_expression |
1900                                         (
1901                                                 rhs=array_or_expression
1902                                                 (               
1903                                                         (COLON|DO)=>rhs=method_invocation_block[rhs] |
1904                                                         (modifier=stmt_modifier eos) |
1905                                                         eos
1906                                                 )                                       
1907                                         )
1908                                 )
1909                         )
1910                         {
1911                                 stmt = new ExpressionStatement(
1912                                                 new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token),
1913                                                         binaryOperator,
1914                                                         lhs, rhs));
1915                                 stmt.Modifier = modifier;
1916                         }
1917                 )
1918         )
1919         ;
1920         
1921 protected
1922 not_expression returns [Expression e]
1923         {
1924                 e = null;
1925         }
1926         :
1927         (
1928                 (nt:NOT e=not_expression) |
1929                 e=assignment_expression
1930         )
1931         {
1932                 if (nt != null)
1933                 {
1934                         UnaryExpression ue = new UnaryExpression(SourceLocationFactory.ToLexicalInfo(nt));
1935                         ue.Operator = UnaryOperatorType.LogicalNot;
1936                         ue.Operand = e;
1937                         e = ue;
1938                 }
1939         }
1940         ;
1941         
1942 protected
1943 assignment_expression returns [Expression e]
1944         {
1945                 e = null;
1946                 Expression r=null;
1947                 IToken token = null;
1948                 BinaryOperatorType binaryOperator = BinaryOperatorType.None;
1949         }:
1950         e=conditional_expression
1951         (
1952                 options { greedy = true; }:
1953                 
1954                 (
1955                         (
1956                                 op:ASSIGN {
1957                                         token = op;
1958                                         binaryOperator = OperatorParser.ParseAssignment(op.getText());
1959                                 }
1960                         ) |
1961                         (
1962                                 ipbo:INPLACE_BITWISE_OR {
1963                                         token = ipbo;
1964                                         binaryOperator = BinaryOperatorType.InPlaceBitwiseOr;
1965                                 }
1966                         ) |
1967                         (
1968                                 ipba:INPLACE_BITWISE_AND {
1969                                         token = ipba;
1970                                         binaryOperator = BinaryOperatorType.InPlaceBitwiseAnd;
1971                                 }
1972                         ) |
1973                         (
1974                                 ipsl:INPLACE_SHIFT_LEFT {
1975                                         token = ipsl;
1976                                         binaryOperator = BinaryOperatorType.InPlaceShiftLeft;
1977                                 }
1978                         ) |
1979                         (
1980                                 ipsr:INPLACE_SHIFT_RIGHT {
1981                                         token = ipsr;
1982                                         binaryOperator = BinaryOperatorType.InPlaceShiftRight;
1983                                 }
1984                         )
1985                 )
1986                 r=assignment_expression
1987                 {
1988                         BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
1989                         be.Operator = binaryOperator;
1990                         be.Left = e;
1991                         be.Right = r;
1992                         e = be;
1993                 }
1994         )?
1995         ;
1996         
1997 protected
1998 conditional_expression returns [Expression e]
1999         {
2000                 e = null;               
2001                 Expression r = null;
2002                 BinaryOperatorType op = BinaryOperatorType.None;
2003                 IToken token = null;
2004                 TypeReference tr = null;
2005         }:
2006         e=sum
2007         ( options { greedy = true; } :
2008          (
2009           (
2010                  (
2011                         (t:CMP_OPERATOR { op = OperatorParser.ParseComparison(t.getText()); token = t; } ) |
2012                         (tgt:GREATER_THAN { op = BinaryOperatorType.GreaterThan; token = tgt; } ) |
2013                         (tlt:LESS_THAN { op = BinaryOperatorType.LessThan; token = tlt; }) |
2014                         (tnot:IS NOT { op = BinaryOperatorType.ReferenceInequality; token = tnot; }) |
2015                         (tis:IS { op = BinaryOperatorType.ReferenceEquality; token = tis; }) |
2016                         (tnint:NOT IN { op = BinaryOperatorType.NotMember; token = tnint; }) |
2017                         (tin:IN { op = BinaryOperatorType.Member; token = tin; } )
2018                  )
2019                  r=sum
2020           ) |
2021           (
2022                 tisa:ISA
2023                 tr=type_reference
2024                 {
2025                         op = BinaryOperatorType.TypeTest;
2026                         token = tisa;
2027                         r = new TypeofExpression(tr.LexicalInfo, tr);
2028                 }
2029           )
2030         )
2031         {
2032                 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2033                 be.Operator = op;
2034                 be.Left = e;
2035                 be.Right = r;
2036                 e = be;
2037         }
2038         )*
2039         ;
2041 protected
2042 sum returns [Expression e]
2043         {
2044                 e = null;
2045                 Expression r = null;
2046                 IToken op = null;
2047                 BinaryOperatorType bOperator = BinaryOperatorType.None;
2048         }:
2049         e=term
2050         ( options { greedy = true; } :
2051                 (
2052                         add:ADD { op=add; bOperator = BinaryOperatorType.Addition; } |
2053                         sub:SUBTRACT { op=sub; bOperator = BinaryOperatorType.Subtraction; } |
2054                         bitor:BITWISE_OR { op=bitor; bOperator = BinaryOperatorType.BitwiseOr; } |
2055                         eo:EXCLUSIVE_OR { op=eo; bOperator = BinaryOperatorType.ExclusiveOr; }
2056                 )
2057                 r=term
2058                 {
2059                         BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(op));
2060                         be.Operator = bOperator;
2061                         be.Left = e;
2062                         be.Right = r;
2063                         e = be;
2064                 }
2065         )*
2066         ;
2068 protected
2069 term returns [Expression e]
2070         {
2071                 e = null;
2072                 Expression r = null;
2073                 IToken token = null;
2074                 BinaryOperatorType op = BinaryOperatorType.None; 
2075         }:
2076         e=factor
2077         ( options { greedy = true; } :
2078                 (
2079                  m:MULTIPLY { op=BinaryOperatorType.Multiply; token=m; } |
2080                  d:DIVISION { op=BinaryOperatorType.Division; token=d; } |
2081                  md:MODULUS { op=BinaryOperatorType.Modulus; token=md; } |
2082                  ba:BITWISE_AND { op=BinaryOperatorType.BitwiseAnd; token=ba; }
2083                  )
2084                 r=factor
2085                 {
2086                         BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2087                         be.Operator = op;
2088                         be.Left = e;
2089                         be.Right = r;
2090                         e = be;
2091                 }
2092         )*
2093         ;
2094         
2095 protected
2096 factor returns [Expression e]
2097         {
2098                 e = null;
2099                 Expression r = null;
2100                 IToken token = null;
2101                 BinaryOperatorType op = BinaryOperatorType.None;
2102         }:
2103         e=exponentiation
2104         (options { greedy = true; }:
2105                 (
2106                 shl:SHIFT_LEFT { op=BinaryOperatorType.ShiftLeft; token = shl; } |
2107                 shr:SHIFT_RIGHT { op=BinaryOperatorType.ShiftRight; token = shr; }
2108                 )
2109                 r=exponentiation
2110                 {
2111                         BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2112                         be.Operator = op;
2113                         be.Left = e;
2114                         be.Right = r;
2115                         e = be;
2116                 }
2117         )*
2118         ;
2119         
2120 protected
2121 exponentiation returns [Expression e]
2122         {
2123                 e = null;
2124                 Expression r = null;
2125                 TypeReference tr = null;
2126         }:
2127         e=unary_expression
2128         (
2129                 t:AS
2130                 tr=type_reference
2131                 {
2132                         TryCastExpression ae = new TryCastExpression(SourceLocationFactory.ToLexicalInfo(t));
2133                         ae.Target = e;
2134                         ae.Type = tr;
2135                         e = ae; 
2136                 }
2137         )?
2138         
2139         ( options { greedy = true; }:
2140                 token:EXPONENTIATION
2141                 r=exponentiation
2142                 {
2143                         BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2144                         be.Operator = BinaryOperatorType.Exponentiation;
2145                         be.Left = e;
2146                         be.Right = r;
2147                         e = be;
2148                 }
2149         )*
2150         ;
2151         
2152         
2153 protected
2154 unary_expression returns [Expression e]
2155         {
2156                         e = null;
2157                         IToken op = null;
2158                         UnaryOperatorType uOperator = UnaryOperatorType.None;
2159         }: 
2160         (
2161                 (
2162                         (
2163                                 sub:SUBTRACT { op = sub; uOperator = UnaryOperatorType.UnaryNegation; } |
2164                                 inc:INCREMENT { op = inc; uOperator = UnaryOperatorType.Increment; } |
2165                                 dec:DECREMENT { op = dec; uOperator = UnaryOperatorType.Decrement; } |
2166                                 oc:ONES_COMPLEMENT { op = oc; uOperator = UnaryOperatorType.OnesComplement; }
2167                         )
2168                         e=unary_expression
2169                 ) |
2170                 (
2171                         e=slicing_expression
2172                         (
2173                                 postinc:INCREMENT { op = postinc; uOperator = UnaryOperatorType.PostIncrement; } |
2174                                 postdec:DECREMENT { op = postdec; uOperator = UnaryOperatorType.PostDecrement; }
2175                         )?
2176                 )
2177         )
2178         {
2179                 if (null != op)
2180                 {
2181                         UnaryExpression ue = new UnaryExpression(SourceLocationFactory.ToLexicalInfo(op));
2182                         ue.Operator = uOperator;
2183                         ue.Operand = e;
2184                         e = ue; 
2185                 }
2186         }
2187         ;
2189 protected
2190 atom returns [Expression e]
2191         {
2192                 e = null;
2193         }:      
2194         (
2195                 e=literal |     
2196                 (CHAR LPAREN)=>e=char_literal |
2197                 e=reference_expression |
2198                 e=paren_expression |
2199                 e=cast_expression |
2200                 e=typeof_expression |
2201                 e=splice_expression
2202         )
2205 protected
2206 splice_expression returns [Expression e]
2208         e = null;
2210         begin:SPLICE_BEGIN e=atom
2211         {
2212                 e = new SpliceExpression(SourceLocationFactory.ToLexicalInfo(begin), e);
2213         }
2215         
2216 protected
2217 char_literal returns [Expression e]
2219         e = null;
2221         CHAR LPAREN
2222         ( 
2223                 t:SINGLE_QUOTED_STRING 
2224                 {
2225                         e = new CharLiteralExpression(SourceLocationFactory.ToLexicalInfo(t), t.getText());
2226                 }
2227                 |
2228                 i:INT
2229                 {
2230                         e = new CharLiteralExpression(SourceLocationFactory.ToLexicalInfo(i), (char) PrimitiveParser.ParseInt(i));
2231                 }
2232         )
2233         RPAREN
2235         
2236 protected
2237 cast_expression returns [Expression e]
2238         {
2239                 e = null;
2240                 TypeReference tr = null;
2241                 Expression target = null;
2242         }:
2243         t:CAST LPAREN tr=type_reference COMMA target=expression RPAREN
2244         {
2245                 e = new CastExpression(SourceLocationFactory.ToLexicalInfo(t), target, tr);
2246         }
2247         ;
2248         
2249 protected
2250 typeof_expression returns [Expression e]
2251         {
2252                 e = null;
2253                 TypeReference tr = null;
2254         }:
2255         t:TYPEOF LPAREN tr=type_reference RPAREN
2256         {
2257                 e = new TypeofExpression(SourceLocationFactory.ToLexicalInfo(t), tr);
2258         }
2259         ;
2260         
2262 protected
2263 reference_expression returns [ReferenceExpression e]
2265         e = null;
2266         IToken t = null;
2268         (
2269                 id:ID { t = id; } |
2270                 ch:CHAR { t = ch; }
2271         )
2272         {
2273                 e = new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(t));
2274                 e.Name = t.getText();
2275         }       
2277         
2278 protected
2279 paren_expression returns [Expression e]
2281         e = null;
2282         Expression condition = null;
2283         Expression falseValue = null;
2285     (LPAREN OF)=>e=typed_array
2286         |
2287         (
2288                 lparen:LPAREN
2289                 e=array_or_expression
2290                 (
2291                         IF condition=boolean_expression
2292                         ELSE falseValue=array_or_expression
2293                         {
2294                                 ConditionalExpression ce = new ConditionalExpression(SourceLocationFactory.ToLexicalInfo(lparen));
2295                                 ce.Condition = condition;
2296                                 ce.TrueValue = e;
2297                                 ce.FalseValue = falseValue;
2298                                 
2299                                 e = ce;
2300                         }
2301                 )?
2302                 RPAREN
2303         )
2306 protected
2307 typed_array returns [Expression e]
2308         {
2309                 e = null;
2310                 ArrayLiteralExpression tle = null;
2311                 TypeReference tr = null;
2312                 Expression item = null;
2313         }:
2314         t:LPAREN
2315         OF tr=type_reference COLON
2316         {
2317                 e = tle = new ArrayLiteralExpression(SourceLocationFactory.ToLexicalInfo(t));
2318                 tle.Type = new ArrayTypeReference(tr.LexicalInfo, tr);
2319         }
2320         (
2321                 COMMA
2322                 |
2323                 (
2324                         item=expression { tle.Items.Add(item); }
2325                         (
2326                                 COMMA
2327                                 item=expression { tle.Items.Add(item); }
2328                         )*
2329                         (COMMA)?
2330                 )
2331         )
2332         RPAREN
2334         
2335 protected
2336 method_invocation_with_block returns [Statement s]
2337         {
2338                 s = null;
2339                 MethodInvocationExpression mie = null;
2340                 Expression block = null;
2341         }:
2342         RPAREN
2343         (
2344                 block=callable_expression
2345                 {
2346                         mie.Arguments.Add(block);
2347                 }
2348         )?
2349         ;
2350         
2351 protected
2352 member returns [IToken name]
2353         {
2354                 name = null;
2355         }:
2356         id:ID { name=id; } |
2357         set:SET { name=set; } |
2358         get:GET { name=get; } |
2359         t1:INTERNAL { name=t1; } |
2360         t2:PUBLIC { name=t2; } |
2361         t3:PROTECTED { name=t3; } |
2362         r:REF { name=r; }
2363         ;
2364         
2365 protected
2366 slice[SlicingExpression se]
2367         {
2368                 Expression begin = null;
2369                 Expression end = null;
2370                 Expression step = null;
2371         } :
2372         (
2373                 ( 
2374                         // [:
2375                         COLON { begin = OmittedExpression.Default; }
2376                         (
2377                                 // [:end]
2378                                 end=expression
2379                                 |
2380                                 (
2381                                         // [::step]
2382                                         COLON { end = OmittedExpression.Default; }
2383                                         step=expression
2384                                 )
2385                                 |
2386                                 // [:]
2387                         )                       
2388                 ) |
2389                 // [begin
2390                 begin=expression
2391                 (
2392                         // [begin:
2393                         COLON
2394                         (
2395                                 end=expression | { end = OmittedExpression.Default; } 
2396                         )
2397                         (
2398                                 COLON
2399                                 step=expression
2400                         )?
2401                 )?
2402         )
2403         {
2404         
2405                 se.Indices.Add(new Slice(begin, end, step));
2406         }
2407         ;
2408         
2409 protected
2410 member_reference_expression[Expression target] returns [Expression e]
2411         {
2412                 e = null;
2413                 IToken memberName = null;
2414         }:
2415         memberName=member
2416         {
2417                 MemberReferenceExpression mre = new MemberReferenceExpression(SourceLocationFactory.ToLexicalInfo(memberName));
2418                 mre.Target = target;
2419                 mre.Name = memberName.getText();
2420                 e = mre;
2421         }
2424 protected
2425 slicing_expression returns [Expression e]
2426         {
2427                 e = null;
2428                 SlicingExpression se = null;
2429                 MethodInvocationExpression mce = null;
2430                 TypeReference genericArgument = null;
2431                 TypeReferenceCollection genericArguments = null;
2432         } :
2433         e=atom
2434         ( options { greedy=true; }:
2435                 (
2436                         lbrack:LBRACK
2437                         (
2438                                 (
2439                                         OF
2440                                         {
2441                                                 GenericReferenceExpression gre = new GenericReferenceExpression(SourceLocationFactory.ToLexicalInfo(lbrack));
2442                                                 gre.Target = e;
2443                                                 e = gre;
2444                                                 genericArguments = gre.GenericArguments;
2445                                         }
2446                                         type_reference_list[genericArguments]                                   
2447                                 )
2448                                 |                               
2449                                 {
2450                                         se = new SlicingExpression(SourceLocationFactory.ToLexicalInfo(lbrack));                                
2451                                         se.Target = e;
2452                                         e = se;
2453                                 }
2454                                 slice[se] (COMMA slice[se])*
2455                         )
2456                         RBRACK
2457                 )
2458                 |
2459                 (
2460                         oft:OF genericArgument=type_reference
2461                         {
2462                                 GenericReferenceExpression gre = new GenericReferenceExpression(SourceLocationFactory.ToLexicalInfo(oft));
2463                                 gre.Target = e;
2464                                 e = gre;
2465                                 gre.GenericArguments.Add(genericArgument);
2466                         }
2467                 )
2468                 |
2469                 ((NEWLINE)+ DOT)=>(
2470                         ((NEWLINE)+ DOT)
2471                         e=member_reference_expression[e]
2472                 )
2473                 |
2474                 (
2475                         DOT (NEWLINE)*
2476                         e=member_reference_expression[e]
2477                 )
2478                 |
2479                 (
2480                         lparen:LPAREN
2481                                 {
2482                                         mce = new MethodInvocationExpression(SourceLocationFactory.ToLexicalInfo(lparen));
2483                                         mce.Target = e;
2484                                         e = mce;
2485                                 }
2486                                 (
2487                                         method_invocation_argument[mce] 
2488                                         (
2489                                                 COMMA
2490                                                 method_invocation_argument[mce]
2491                                         )*
2492                                 )?
2493                         RPAREN
2494                 )
2495         )*
2496         ;
2497         
2498 protected
2499 method_invocation_argument[MethodInvocationExpression mie]
2500         {
2501                 Expression arg = null;
2502         }:
2503         (
2504                 t:MULTIPLY arg=expression
2505                 {
2506                         if (null != arg)
2507                         {
2508                                 mie.Arguments.Add(
2509                                         new UnaryExpression(
2510                                                 SourceLocationFactory.ToLexicalInfo(t),
2511                                                 UnaryOperatorType.Explode,
2512                                                 arg));
2513                         }
2514                 }
2515         ) |
2516         argument[mie]
2517         ;
2518         
2519 protected
2520 literal returns [Expression e]
2521         {
2522                 e = null;
2523         }:
2524         (
2525                 e=integer_literal |
2526                 e=string_literal |
2527                 e=list_literal |
2528                 (hash_literal_test)=>e=hash_literal |
2529                 e=closure_expression |
2530                 e=ast_literal_expression |
2531                 e=re_literal |
2532                 e=bool_literal |
2533                 e=null_literal |
2534                 e=self_literal |
2535                 e=super_literal |
2536                 e=double_literal |
2537                 e=timespan_literal
2538         )
2539         ;
2540                 
2541 protected
2542 self_literal returns [SelfLiteralExpression e] { e = null; }:
2543         t:SELF { e = new SelfLiteralExpression(SourceLocationFactory.ToLexicalInfo(t)); }
2544         ;
2545         
2546 protected
2547 super_literal returns [SuperLiteralExpression e] { e = null; }:
2548         t:SUPER { e = new SuperLiteralExpression(SourceLocationFactory.ToLexicalInfo(t)); }
2549         ;
2550                 
2551 protected
2552 null_literal returns [NullLiteralExpression e] { e = null; }:
2553         t:NULL { e = new NullLiteralExpression(SourceLocationFactory.ToLexicalInfo(t)); }
2554         ;
2555                 
2556 protected
2557 bool_literal returns [BoolLiteralExpression e] { e = null; }:
2558         t:TRUE
2559         {
2560                 e = new BoolLiteralExpression(SourceLocationFactory.ToLexicalInfo(t));
2561                 e.Value = true;
2562         } |
2563         f:FALSE
2564         {
2565                 e = new BoolLiteralExpression(SourceLocationFactory.ToLexicalInfo(f));
2566                 e.Value = false;
2567         }
2568         ;
2570 protected
2571 integer_literal returns [IntegerLiteralExpression e] 
2572         {
2573                 e = null;
2574                 string val;
2575         } :
2576         (neg:SUBTRACT)?
2577         (
2578                 i:INT
2579                 {
2580                         val = i.getText();
2581                         if (neg != null) val = neg.getText() + val;
2582                         e = PrimitiveParser.ParseIntegerLiteralExpression(i, val, false);
2583                 }
2584                 |
2585                 l:LONG
2586                 {
2587                         val = l.getText();
2588                         val = val.Substring(0, val.Length-1);
2589                         if (neg != null) val = neg.getText() + val;
2590                         e = PrimitiveParser.ParseIntegerLiteralExpression(l, val, true);
2591                 }
2592         )
2593         ;
2594         
2595 protected
2596 string_literal returns [Expression e]
2597         {
2598                 e = null;
2599         }:
2600         e=expression_interpolation |    
2601         dqs:DOUBLE_QUOTED_STRING
2602         {
2603                 e = new StringLiteralExpression(SourceLocationFactory.ToLexicalInfo(dqs), dqs.getText());
2604         } |
2605         sqs:SINGLE_QUOTED_STRING
2606         {
2607                 e = new StringLiteralExpression(SourceLocationFactory.ToLexicalInfo(sqs), sqs.getText());
2608         } |
2609         tqs:TRIPLE_QUOTED_STRING
2610         {
2611                 e = new StringLiteralExpression(SourceLocationFactory.ToLexicalInfo(tqs), tqs.getText());
2612         }
2613         ;
2614         
2615 protected
2616 expression_interpolation returns [ExpressionInterpolationExpression e]
2617         {
2618                 e = null;
2619                 Expression param = null;        
2620         }:
2621         separator:ESEPARATOR
2622         {
2623                 LexicalInfo info = SourceLocationFactory.ToLexicalInfo(separator);
2624                 e = new ExpressionInterpolationExpression(info);                
2625         }
2626         (  options { greedy = true; } :
2627                 
2628                 ESEPARATOR              
2629                 param=expression { if (null != param) { e.Expressions.Add(param); } }
2630                 ESEPARATOR
2631         )*
2632         ;
2633         
2635 protected
2636 list_literal returns [Expression e]
2637         {
2638                 e = null;
2639                 ListLiteralExpression lle = null;
2640                 Expression item = null;
2641         }:
2642         lbrack:LBRACK
2643         (
2644                 (
2645                         item=expression
2646                         (
2647                                 {
2648                                         e = lle = new ListLiteralExpression(SourceLocationFactory.ToLexicalInfo(lbrack));
2649                                         lle.Items.Add(item);
2650                                 }
2651                                 (  options { greedy = true; } :
2652                                         COMMA item=expression { lle.Items.Add(item); }
2653                                 )*
2654                         )
2655                         (COMMA)?
2656                 )
2657                 |
2658                 { e = new ListLiteralExpression(SourceLocationFactory.ToLexicalInfo(lbrack)); }
2659         )
2660         RBRACK
2661         ;
2662         
2663 protected
2664 hash_literal_test:
2665         LBRACE  (RBRACE|(expression COLON))
2666         ;
2667                 
2668 protected
2669 hash_literal returns [HashLiteralExpression dle]
2670         {
2671                 dle = null;
2672                 ExpressionPair pair = null;
2673         }:
2674         lbrace:LBRACE { dle = new HashLiteralExpression(SourceLocationFactory.ToLexicalInfo(lbrace)); }
2675         (
2676                 pair=expression_pair                    
2677                 { dle.Items.Add(pair); }
2678                 (
2679                         COMMA
2680                         pair=expression_pair
2681                         { dle.Items.Add(pair); }
2682                 )*
2683                 (COMMA)?
2684         )?
2685         RBRACE
2686         ;
2687                 
2688 protected
2689 expression_pair returns [ExpressionPair ep]
2690         {
2691                 ep = null;
2692                 Expression key = null;
2693                 Expression value = null;
2694         }:
2695         key=expression t:COLON value=expression
2696         { ep = new ExpressionPair(SourceLocationFactory.ToLexicalInfo(t), key, value); }
2697         ;
2698                 
2699 protected
2700 re_literal returns [RELiteralExpression re] { re = null; }:
2701         value:RE_LITERAL
2702         { re = new RELiteralExpression(SourceLocationFactory.ToLexicalInfo(value), value.getText()); }
2703         ;
2704         
2705 protected
2706 double_literal returns [DoubleLiteralExpression rle]
2707         {
2708                 rle = null;
2709                 string val;
2710         }:
2711         (neg:SUBTRACT)?
2712         value:DOUBLE
2713         {
2714                 val = value.getText();
2715                 if (neg != null) val = neg.getText() + val;
2716                 rle = new DoubleLiteralExpression(SourceLocationFactory.ToLexicalInfo(value), PrimitiveParser.ParseDouble(val));
2717         }
2718         |
2719         single:FLOAT
2720         {
2721                 val = single.getText();
2722                 val = val.Substring(0, val.Length-1);
2723                 if (neg != null) val = neg.getText() + val;
2724                 rle = new DoubleLiteralExpression(SourceLocationFactory.ToLexicalInfo(single), PrimitiveParser.ParseDouble(val, true), true);
2725         }
2726         ;
2727         
2728 protected
2729 timespan_literal returns [TimeSpanLiteralExpression tsle] { tsle = null; }:
2730         (neg:SUBTRACT)?
2731         value:TIMESPAN
2732         {
2733                 string val = value.getText();
2734                 if (neg != null) val = neg.getText() + val;
2735                 tsle = new TimeSpanLiteralExpression(SourceLocationFactory.ToLexicalInfo(value), PrimitiveParser.ParseTimeSpan(val)); 
2736         }
2737         ;
2739 protected
2740 expression_list[ExpressionCollection ec]
2741         {
2742                 Expression e = null;
2743         } :
2744         (
2745                 e=expression { ec.Add(e); }
2746                 (
2747                         COMMA
2748                         e=expression { ec.Add(e); }
2749                 )*
2750         )?
2751         ;
2752         
2753 protected
2754 argument_list[INodeWithArguments node]:
2755         (
2756                 argument[node] 
2757                 (
2758                         COMMA
2759                         argument[node]
2760                 )*
2761         )?
2762         ;
2763         
2764 protected
2765 argument[INodeWithArguments node]
2766         {               
2767                 Expression value = null;
2768         }:
2769         (ID COLON)=>(
2770                 id:ID colon:COLON value=expression
2771                 {
2772                         node.NamedArguments.Add(
2773                                 new ExpressionPair(
2774                                         SourceLocationFactory.ToLexicalInfo(colon),
2775                                         new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(id), id.getText()),
2776                                         value));
2777                 }
2778         ) |
2779         (
2780                 value=expression
2781                 { if (null != value) { node.Arguments.Add(value); } }
2782         )
2783         ;
2785 protected
2786 identifier returns [IToken value]
2787         {
2788                 value = null; _sbuilder.Length = 0;
2789                 IToken id2 = null;
2790         }:
2791         id1:ID
2792         {                                       
2793                 _sbuilder.Append(id1.getText());
2794                 value = id1;
2795         }                               
2796         ( options { greedy = true; } :
2797                 DOT
2798                 id2=member
2799                 { _sbuilder.Append('.'); _sbuilder.Append(id2.getText()); }
2800         )*
2801         { value.setText(_sbuilder.ToString()); }
2802         ;        
2804 using Boo.Lang.Parser.Util;
2806 class WSABooLexer extends Lexer;
2807 options
2809         testLiterals = false;
2810         exportVocab = WSABoo;   
2811         k = 3;
2812         charVocabulary='\u0003'..'\uFFFE';
2813         caseSensitiveLiterals=true;
2814         // without inlining some bitset tests, ANTLR couldn't do unicode;
2815         // They need to make ANTLR generate smaller bitsets;
2816         codeGenBitsetTestThreshold=20;
2819         protected int _skipWhitespaceRegion = 0;
2820         
2821         TokenStreamRecorder _erecorder;
2822         
2823         antlr.TokenStreamSelector _selector;
2824         
2825         internal void Initialize(antlr.TokenStreamSelector selector, int tabSize, antlr.TokenCreator tokenCreator)
2826         {
2827                 setTabSize(tabSize);
2828                 setTokenCreator(tokenCreator);
2829                 
2830                 _selector = selector;
2831                 _erecorder = new TokenStreamRecorder(selector);
2832         }
2833         
2834         internal antlr.TokenStream CreateExpressionLexer()
2835         {
2836                 WSABooExpressionLexer lexer = new WSABooExpressionLexer(getInputState());
2837                 lexer.setTabSize(getTabSize());
2838                 lexer.setTokenCreator(tokenCreator);
2839                 return lexer;
2840         }
2842         internal static bool IsDigit(char ch)
2843         {
2844                 return ch >= '0' && ch <= '9';
2845         }
2846         
2847         bool SkipWhitespace
2848         {
2849                 get
2850                 {
2851                         return _skipWhitespaceRegion > 0;
2852                 }
2853         }
2855         void Enqueue(antlr.IToken token, string text)
2856         {
2857                 token.setText(text);
2858                 _erecorder.Enqueue(makeESEPARATOR());
2859                 _erecorder.Enqueue(token);
2860                 _erecorder.Enqueue(makeESEPARATOR());
2861         }
2862         
2863         antlr.IToken makeESEPARATOR()
2864         {
2865                 return makeToken(ESEPARATOR);
2866         }
2868         internal void EnterSkipWhitespaceRegion()
2869         {
2870                 ++_skipWhitespaceRegion;
2871         }       
2873         internal void LeaveSkipWhitespaceRegion()
2874         {
2875                 --_skipWhitespaceRegion;
2876         }
2879 ID options { testLiterals = true; }:
2880         (ID_PREFIX)? ID_LETTER (ID_LETTER | DIGIT)*
2881         ;
2882         
2883 LINE_CONTINUATION:
2884         '\\'! NEWLINE
2885         { $setType(Token.SKIP); }
2886         ;
2887         
2888 INT : 
2889         ("0x"(HEXDIGIT)+)(('l' | 'L') { $setType(LONG); })? |
2890         DIGIT_GROUP
2891         (('e'|'E')('+'|'-')? DIGIT_GROUP)?
2892         (
2893                 ('l' | 'L') { $setType(LONG); } |
2894                 (('f' | 'F') { $setType(FLOAT); }) |
2895                 (
2896                         (
2897                                 {WSABooLexer.IsDigit(LA(2))}? 
2898                                 (
2899                                         '.' REVERSE_DIGIT_GROUP
2900                                         (('e'|'E')('+'|'-')? DIGIT_GROUP)?
2901                                 )
2902                                 (
2903                                         (('f' | 'F') { $setType(FLOAT); }) |
2904                                         { $setType(DOUBLE); }
2905                                 )
2906                         )?
2907                         (("ms" | 's' | 'm' | 'h' | 'd') { $setType(TIMESPAN); })?
2908                 )
2909         )
2911   
2912 DOT : '.' 
2913         (
2914                 REVERSE_DIGIT_GROUP (('e'|'E')('+'|'-')? DIGIT_GROUP)?
2915                 (
2916                         (('f' | 'F')  { $setType(FLOAT); }) |
2917                         (("ms" | 's' | 'm' | 'h' | 'd') { $setType(TIMESPAN); }) |
2918                         {$setType(DOUBLE);}
2919                 )
2920         )?
2923 COLON : ':';
2925 BITWISE_OR: '|' ('=' { $setType(INPLACE_BITWISE_OR); })?;
2927 BITWISE_AND: '&' ('=' { $setType(INPLACE_BITWISE_AND); })?;
2929 EXCLUSIVE_OR: '^' ('=' { $setType(ASSIGN); })?;
2931 LPAREN : '(' { EnterSkipWhitespaceRegion(); };
2932         
2933 RPAREN : ')' { LeaveSkipWhitespaceRegion(); };
2935 protected
2936 ASSEMBLY_ATTRIBUTE_BEGIN: "assembly:";
2938 LBRACK : '[' { EnterSkipWhitespaceRegion(); }
2939         (
2940                 ("assembly:")=> "assembly:" { $setType(ASSEMBLY_ATTRIBUTE_BEGIN); } |
2941         )
2942         ;
2944 RBRACK : ']' { LeaveSkipWhitespaceRegion(); };
2946 LBRACE : '{' { EnterSkipWhitespaceRegion(); };
2947         
2948 RBRACE : '}' { LeaveSkipWhitespaceRegion(); };
2950 SPLICE_BEGIN : "$";
2952 QQ_BEGIN: "[|"; 
2954 QQ_END: "|]";
2956 INCREMENT: "++";
2958 DECREMENT: "--";
2960 ADD: ('+') ('=' { $setType(ASSIGN); })?;
2962 SUBTRACT: ('-') ('=' { $setType(ASSIGN); })?;
2964 MODULUS: '%';
2966 MULTIPLY: '*' ('=' { $setType(ASSIGN); })?;
2968 EXPONENTIATION: "**";
2970 DIVISION: 
2971         ("/*")=> ML_COMMENT { $setType(Token.SKIP); } |
2972         (RE_LITERAL)=> RE_LITERAL { $setType(RE_LITERAL); } |   
2973         '/' (
2974                 ('/' (~('\r'|'\n'))* { $setType(Token.SKIP); }) |                       
2975                         ('=' { $setType(ASSIGN); }) |
2976                 )
2977         ;
2979 LESS_THAN: '<';
2981 SHIFT_LEFT: "<<";
2983 INPLACE_SHIFT_LEFT: "<<=";
2985 GREATER_THAN: '>';
2987 SHIFT_RIGHT: ">>";
2989 INPLACE_SHIFT_RIGHT: ">>=";
2991 ONES_COMPLEMENT: '~';
2993 CMP_OPERATOR :  "<=" | ">=" | "!~" | "!=";
2995 ASSIGN : '=' ( ('=' | '~') { $setType(CMP_OPERATOR); } )?;
2997 COMMA : ',';
2999 protected
3000 TRIPLE_QUOTED_STRING:
3001         "\"\""!
3002         (
3003         options { greedy=false; }:              
3004                 ("${")=>                
3005                 {                                       
3006                         Enqueue(makeToken(TRIPLE_QUOTED_STRING), $getText);
3007                         $setText("");
3008                 }
3009                 ESCAPED_EXPRESSION |
3010                 ("\\$")=>'\\'! '$' |
3011                 ~('\r'|'\n') |
3012                 NEWLINE
3013         )*
3014         "\"\"\""!
3015         ;
3017 DOUBLE_QUOTED_STRING:
3018         '"'!
3019         (
3020                 {LA(1)=='"' && LA(2)=='"'}?TRIPLE_QUOTED_STRING { $setType(TRIPLE_QUOTED_STRING); }
3021                 |
3022                 (
3023                         (
3024                                 DQS_ESC |
3025                                 ("${")=>
3026                                 {                                       
3027                                         Enqueue(makeToken(DOUBLE_QUOTED_STRING), $getText);
3028                                         $setText("");
3029                                 }
3030                                 ESCAPED_EXPRESSION |
3031                                 ~('"' | '\\' | '\r' | '\n')
3032                         )*
3033                         '"'!                    
3034                 )
3035         )
3036         {
3037                 if (_erecorder.Count > 0)
3038                 {
3039                         Enqueue(makeToken(DOUBLE_QUOTED_STRING), $getText);
3040                         $setType(ESEPARATOR);
3041                         $setText("");                   
3042                         _selector.push(_erecorder);
3043                 }
3044         }
3045         ;
3046                 
3047 SINGLE_QUOTED_STRING :
3048         '\''!
3049         (
3050                 SQS_ESC |
3051                 ~('\'' | '\\' | '\r' | '\n')
3052         )*
3053         '\''!
3054         ;
3056 SL_COMMENT:
3057         "#" (~('\r'|'\n'))*
3058         { $setType(Token.SKIP); }
3059         ;
3060         
3061 protected
3062 ML_COMMENT:
3063         "/*"
3064     (
3065                 { LA(2) != '/' }? '*' |
3066                 ("/*")=>ML_COMMENT |
3067                 NEWLINE |
3068                 ~('*'|'\r'|'\n')
3069     )*
3070     "*/"
3071     { $setType(Token.SKIP); }
3072         ;   
3073                         
3074 WS :
3075         (
3076                 ' ' |
3077                 '\t' { tab(); } |
3078                 '\f'
3079         )+
3080         {
3081                 $setType(Token.SKIP);
3082         }
3083         ;
3084                 
3085 EOS: ';';
3087 X_RE_LITERAL: '@'!'/' (X_RE_CHAR)+ '/' { $setType(RE_LITERAL); };
3089 NEWLINE:
3090         (
3091                 (
3092                         '\n'
3093                         |
3094                         (
3095                         '\r' ('\n')?
3096                         )
3097                 )
3098                 { newline(); }
3099         )+
3100         {
3101                 if (SkipWhitespace)
3102                 {
3103                         $setType(Token.SKIP);
3104                 }
3105         }
3107                 
3108 protected
3109 ESCAPED_EXPRESSION : "${"!
3110         {                       
3111                 _erecorder.Enqueue(makeESEPARATOR());
3112                 if (0 == _erecorder.RecordUntil(CreateExpressionLexer(), RBRACE, LBRACE))
3113                 {       
3114                         _erecorder.Dequeue();                   
3115                 }
3116                 else
3117                 {
3118                         _erecorder.Enqueue(makeESEPARATOR());
3119                 }
3120                 refresh();
3121         } 
3122         ;
3124 protected
3125 DQS_ESC : '\\'! ( SESC | '"' | '$') ;   
3126         
3127 protected
3128 SQS_ESC : '\\'! ( SESC | '\'' );
3130 protected
3131 SESC : 
3132                                 ( 'r'! {$setText("\r"); }) |
3133                                 ( 'n'! {$setText("\n"); }) |
3134                                 ( 't'! {$setText("\t"); }) |
3135                                 ( 'a'! {text.Length = _begin; text.Append("\a"); }) |
3136                                 ( 'b'! {text.Length = _begin; text.Append("\b"); }) |
3137                                 ( 'f'! {text.Length = _begin; text.Append("\f"); }) |
3138                                 ( '0'! {text.Length = _begin; text.Append("\0"); }) |
3139                                 ( 'u'!
3140                                         HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT
3141                                         {
3142                                                 char ch = (char)int.Parse(text.ToString(_begin, 4), System.Globalization.NumberStyles.HexNumber);
3143                                                 text.Length = _begin;
3144                                                 text.Append(ch);
3145                                         }
3146                                 ) |
3147                                 ( '\\'! {$setText("\\"); });
3148                                 
3150 protected
3151 RE_LITERAL : '/' (RE_CHAR)+ '/';
3153 protected
3154 RE_CHAR : RE_ESC | ~('/' | '\\' | '\r' | '\n' | ' ' | '\t' );
3156 protected
3157 X_RE_CHAR: RE_CHAR | ' ' | '\t';
3159 protected
3160 RE_ESC : '\\' (                         
3161                                 '+' |
3162                                 '/' |
3163                                 '(' |
3164                                 ')' |
3165                                 '|' |
3166                                 '.' |
3167                                 '*' |
3168                                 '?' |
3169                                 '$' |
3170                                 '^' |
3171                                 '['     |
3172                                 ']' |
3173                                 '{' |
3174                                 '}' |
3175         
3176         // character scapes
3177         // ms-help://MS.NETFrameworkSDKv1.1/cpgenref/html/cpconcharacterescapes.htm
3178         
3179                                 'a' |
3180                                 'b' |
3181                                 ('c' 'A'..'Z') |
3182                                 't' |
3183                                 'r' |
3184                                 'v' |
3185                                 'f' |
3186                                 'n' |
3187                                 'e' |
3188                                 (DIGIT)+ |
3189                                 ('x' HEXDIGIT HEXDIGIT) |
3190                                 ('u' HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT) |
3191                                 '\\' |
3192                                 
3193         // character classes
3194         // ms-help://MS.NETFrameworkSDKv1.1/cpgenref/html/cpconcharacterclasses.htm
3195         // /\w\W\s\S\d\D/
3196         
3197                                 'w' |
3198                                 'W' |
3199                                 's' |
3200                                 'S' |
3201                                 'd' |
3202                                 'D' |
3203                                 'p' |
3204                                 'P' |
3205                                 
3206         // atomic zero-width assertions
3207         // ms-help://MS.NETFrameworkSDKv1.1/cpgenref/html/cpconatomiczero-widthassertions.htm
3208                                 'A' |
3209                                 'z' |
3210                                 'Z' |
3211                                 'g' |
3212                                 'B' |
3213                                 'k'                     
3214                          )
3215                          ;
3216                          
3217 protected
3218 DIGIT_GROUP : DIGIT (('_'! DIGIT DIGIT DIGIT) | DIGIT)*;
3220 protected
3221 REVERSE_DIGIT_GROUP : (DIGIT DIGIT DIGIT ({WSABooLexer.IsDigit(LA(2))}? '_'!)? | DIGIT)+;
3223 protected
3224 ID_PREFIX : '@';
3226 protected
3227 ID_LETTER : ('_' | 'a'..'z' | 'A'..'Z' | {System.Char.IsLetter(LA(1))}? '\u0080'..'\uFFFE');
3229 protected
3230 DIGIT : '0'..'9';
3232 protected
3233 HEXDIGIT : ('a'..'f' | 'A'..'F' | '0'..'9');
3235 NULLABLE_SUFFIX: '?';