1 // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without modification,
5 // are permitted provided that the following conditions are met:
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.
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.
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;
44 defaultErrorHandler = true;
48 ELIST; // expression list
49 DLIST; // declaration list
50 ESEPARATOR; // expression separator (imaginary token)
60 CONSTRUCTOR="constructor";
62 DESTRUCTOR="destructor";
79 INTERFACE="interface";
90 NAMESPACE="namespace";
92 PROTECTED="protected";
104 TRANSIENT="transient";
115 protected System.Text.StringBuilder _sbuilder = new System.Text.StringBuilder();
117 protected AttributeCollection _attributes = new AttributeCollection();
119 protected TypeMemberModifiers _modifiers = TypeMemberModifiers.None;
121 protected bool _inArray;
123 protected void ResetMemberData()
125 _modifiers = TypeMemberModifiers.None;
128 protected void AddAttributes(AttributeCollection target)
130 target.Extend(_attributes);
134 static bool IsMethodInvocationExpression(Expression e)
136 return NodeType.MethodInvocationExpression == e.NodeType;
139 protected bool IsValidMacroArgument(int token)
141 return LPAREN != token && LBRACK != token;
146 start[CompileUnit cu] returns [Module module]
148 module = new Module();
149 module.LexicalInfo = new LexicalInfo(getFilename(), 1, 1);
151 cu.Modules.Add(module);
158 parse_module[Module module]
164 (namespace_directive[module])?
165 (import_directive[module])*
166 (type_member[module.Members])*
168 (assembly_attribute[module] eos)*
171 protected docstring[Node node]:
173 doc:TRIPLE_QUOTED_STRING { node.Documentation = DocStringFormatter.Format(doc.getText()); }
179 eos : EOF | (options { greedy = true; }: (EOS | NEWLINE))+;
182 import_directive[Module container]
185 Import usingNode = null;
189 usingNode = new Import(SourceLocationFactory.ToLexicalInfo(id));
190 usingNode.Namespace = id.getText();
191 container.Imports.Add(usingNode);
197 dqs:DOUBLE_QUOTED_STRING { id=dqs; } |
198 sqs:SINGLE_QUOTED_STRING { id=sqs; }
201 usingNode.AssemblyReference = new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(id));
202 usingNode.AssemblyReference.Name = id.getText();
208 usingNode.Alias = new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(alias));
209 usingNode.Alias.Name = alias.getText();
216 namespace_directive[Module container]
219 NamespaceDeclaration p = null;
221 t:NAMESPACE id=identifier
223 p = new NamespaceDeclaration(SourceLocationFactory.ToLexicalInfo(t));
224 p.Name = id.getText();
225 container.Namespace = p;
232 type_member[TypeMemberCollection container]:
236 type_definition[container] |
242 type_definition [TypeMemberCollection container]:
244 class_definition[container] |
245 interface_definition[container] |
246 enum_definition[container] |
247 callable_definition[container]
252 callable_definition [TypeMemberCollection container]
254 CallableDefinition cd = null;
255 TypeReference returnType = null;
256 GenericParameterDeclarationCollection genericParameters = null;
260 cd = new CallableDefinition(SourceLocationFactory.ToLexicalInfo(id));
261 cd.Name = id.getText();
262 cd.Modifiers = _modifiers;
263 AddAttributes(cd.Attributes);
265 genericParameters = cd.GenericParameters;
268 (LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK) |
269 (OF generic_parameter_declaration[genericParameters])
271 LPAREN parameter_declaration_list[cd.Parameters] RPAREN
272 (AS returnType=type_reference { cd.ReturnType=returnType; })?
278 enum_definition [TypeMemberCollection container]
280 EnumDefinition ed = null;
282 ENUM id:ID { ed = new EnumDefinition(SourceLocationFactory.ToLexicalInfo(id)); }
285 ed.Name = id.getText();
286 ed.Modifiers = _modifiers;
287 AddAttributes(ed.Attributes);
297 enum_member [EnumDefinition container]
299 EnumMember em = null;
300 IntegerLiteralExpression initializer = null;
301 bool negative = false;
304 id:ID (ASSIGN (SUBTRACT { negative = true; })? initializer=integer_literal)?
306 em = new EnumMember(SourceLocationFactory.ToLexicalInfo(id));
307 em.Name = id.getText();
308 em.Initializer = initializer;
309 if (negative && null != initializer)
311 initializer.Value *= -1;
313 AddAttributes(em.Attributes);
314 container.Members.Add(em);
342 antlr.IToken id = null;
343 Boo.Lang.Compiler.Ast.Attribute attr = null;
347 attr = new Boo.Lang.Compiler.Ast.Attribute(SourceLocationFactory.ToLexicalInfo(id), id.getText());
348 _attributes.Add(attr);
358 assembly_attribute[Module module]
360 antlr.IToken id = null;
361 Boo.Lang.Compiler.Ast.Attribute attr = null;
363 ASSEMBLY_ATTRIBUTE_BEGIN
364 id=identifier { attr = new Boo.Lang.Compiler.Ast.Attribute(SourceLocationFactory.ToLexicalInfo(id), id.getText()); }
371 { module.AssemblyAttributes.Add(attr); }
375 class_definition [TypeMemberCollection container]
377 TypeDefinition td = null;
378 TypeReferenceCollection baseTypes = null;
379 TypeMemberCollection members = null;
380 GenericParameterDeclarationCollection genericParameters = null;
383 CLASS { td = new ClassDefinition(); } |
384 STRUCT { td = new StructDefinition(); }
388 td.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id);
389 td.Name = id.getText();
390 td.Modifiers = _modifiers;
391 AddAttributes(td.Attributes);
393 baseTypes = td.BaseTypes;
394 members = td.Members;
395 genericParameters = td.GenericParameters;
398 (LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK) |
399 (OF generic_parameter_declaration[genericParameters])
401 (base_types[baseTypes])?
403 (type_definition_member[members])*
407 type_definition_member[TypeMemberCollection container]
414 event_declaration[container] |
415 field_or_property[container] |
416 type_definition[container]
421 interface_definition [TypeMemberCollection container]
423 InterfaceDefinition itf = null;
424 TypeMemberCollection members = null;
425 GenericParameterDeclarationCollection genericParameters = null;
429 itf = new InterfaceDefinition(SourceLocationFactory.ToLexicalInfo(id));
430 itf.Name = id.getText();
431 itf.Modifiers = _modifiers;
432 AddAttributes(itf.Attributes);
434 members = itf.Members;
435 genericParameters = itf.GenericParameters;
438 (LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK) |
439 (OF generic_parameter_declaration[genericParameters])
441 (base_types[itf.BaseTypes])?
446 interface_method[members] |
447 event_declaration[members] |
448 interface_property[members]
455 base_types[TypeReferenceCollection container]
457 TypeReference tr = null;
461 tr=type_reference { container.Add(tr); }
462 (COMMA tr=type_reference { container.Add(tr); })*
468 interface_method [TypeMemberCollection container]
471 TypeReference rt = null;
475 m = new Method(SourceLocationFactory.ToLexicalInfo(id));
476 m.Name = id.getText();
477 AddAttributes(m.Attributes);
480 LPAREN parameter_declaration_list[m.Parameters] RPAREN
481 (AS rt=type_reference { m.ReturnType=rt; })?
483 (eos docstring[m]) | (empty_block[m] (eos)?)
488 interface_property [TypeMemberCollection container]
492 TypeReference tr = null;
493 ParameterDeclarationCollection parameters = null;
495 (id1:ID {id=id1;} | s:SELF {id=s;})
497 p = new Property(SourceLocationFactory.ToLexicalInfo(id));
498 p.Name = id.getText();
499 AddAttributes(p.Attributes);
501 parameters = p.Parameters;
503 ((LBRACK|LPAREN) parameter_declaration_list[parameters] (RBRACK|RPAREN))?
504 (AS tr=type_reference)?
509 (interface_property_accessor[p])+
514 interface_property_accessor[Property p]
521 { null == p.Getter }?
523 gt:GET { m = p.Getter = new Method(SourceLocationFactory.ToLexicalInfo(gt)); m.Name = "get"; }
526 { null == p.Setter }?
528 st:SET { m = p.Setter = new Method(SourceLocationFactory.ToLexicalInfo(st)); m.Name = "set"; }
535 AddAttributes(m.Attributes);
540 empty_block[Node node]:
547 event_declaration [TypeMemberCollection container]
550 TypeReference tr = null;
553 id:ID AS tr=type_reference eos
555 e = new Event(SourceLocationFactory.ToLexicalInfo(id), id.getText(), tr);
556 e.Modifiers = _modifiers;
557 AddAttributes(e.Attributes);
564 explicit_member_info returns [ExplicitMemberInfo emi]
566 emi = null; _sbuilder.Length = 0;
572 emi = new ExplicitMemberInfo(SourceLocationFactory.ToLexicalInfo(id));
573 _sbuilder.Append(id.getText());
578 _sbuilder.Append('.');
579 _sbuilder.Append(id2.getText());
587 emi.InterfaceType = new SimpleTypeReference(emi.LexicalInfo);
588 emi.InterfaceType.Name = _sbuilder.ToString();
594 method [TypeMemberCollection container]
597 TypeReference rt = null;
598 TypeReference it = null;
599 ExplicitMemberInfo emi = null;
600 ParameterDeclarationCollection parameters = null;
601 GenericParameterDeclarationCollection genericParameters = null;
603 StatementCollection statements = null;
607 (emi=explicit_member_info)? id:ID {
610 m = new Method(emi.LexicalInfo);
614 m = new Method(SourceLocationFactory.ToLexicalInfo(id));
616 m.Name = id.getText();
617 m.ExplicitInfo = emi;
620 c:CONSTRUCTOR { m = new Constructor(SourceLocationFactory.ToLexicalInfo(c)); } |
621 d:DESTRUCTOR { m = new Destructor(SourceLocationFactory.ToLexicalInfo(d)); }
624 m.Modifiers = _modifiers;
625 AddAttributes(m.Attributes);
626 parameters = m.Parameters;
627 genericParameters = m.GenericParameters;
629 statements = body.Statements;
633 LBRACK (OF)? generic_parameter_declaration_list[genericParameters] RBRACK
637 OF generic_parameter_declaration[genericParameters]
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]
653 ((ID|SELF) (DOT ID)*)
657 ((AS type_reference)? COLON)
662 field_or_property [TypeMemberCollection container]
665 TypeMember tm = null;
666 TypeReference tr = null;
669 ExplicitMemberInfo emi = null;
670 Expression initializer = null;
671 ParameterDeclarationCollection parameters = null;
674 (emi=explicit_member_info)? (id1:ID {id=id1;}| s:SELF {id=s;})
679 p = new Property(emi.LexicalInfo);
681 p = new Property(SourceLocationFactory.ToLexicalInfo(id));
682 p.Name = id.getText();
683 p.ExplicitInfo = emi;
684 AddAttributes(p.Attributes);
685 parameters = p.Parameters;
687 ((LBRACK|LPAREN) parameter_declaration_list[parameters] (RBRACK|RPAREN))?
688 (AS tr=type_reference)?
692 tm.Modifiers = _modifiers;
695 (property_accessor[p])+
699 { container.Add(tm); }
704 tm = field = new Field(SourceLocationFactory.ToLexicalInfo(id2));
705 field.Name = id2.getText();
706 field.Modifiers = _modifiers;
707 AddAttributes(field.Attributes);
710 (AS tr=type_reference { field.Type = tr; })?
713 ASSIGN initializer=declaration_initializer
714 { field.Initializer = initializer; }
721 { container.Add(tm); }
724 declaration_initializer returns [Expression e]
728 (slicing_expression (COLON|DO|DEF))=>(e=slicing_expression e=method_invocation_block[e]) |
729 (e=array_or_expression eos) |
730 (e=callable_expression)
734 property_accessor[Property p]
742 { null == p.Getter }?
746 p.Getter = m = new Method(SourceLocationFactory.ToLexicalInfo(gt));
751 { null == p.Setter }?
755 p.Setter = m = new Method(SourceLocationFactory.ToLexicalInfo(st));
761 AddAttributes(m.Attributes);
762 m.Modifiers = _modifiers;
769 globals[Module container]:
771 (stmt[container.Globals.Statements])*
775 block[StatementCollection container]:
785 _modifiers = TypeMemberModifiers.None;
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; }
803 parameter_modifier returns [ParameterModifiers pm]
805 pm = ParameterModifiers.None;
808 REF { pm = ParameterModifiers.Ref; }
813 parameter_declaration_list[ParameterDeclarationCollection c]
815 bool variableArguments = false;
817 (variableArguments=parameter_declaration[c]
818 ( {!variableArguments}?(COMMA variableArguments=parameter_declaration[c]) )* )?
819 { c.VariableNumber = variableArguments; }
823 parameter_declaration[ParameterDeclarationCollection c]
824 returns [bool variableArguments]
827 TypeReference tr = null;
828 ParameterModifiers pm = ParameterModifiers.None;
829 variableArguments = false;
834 MULTIPLY { variableArguments=true; }
835 id1:ID (AS tr=array_type_reference)?
840 (pm=parameter_modifier)?
841 id2:ID (AS tr=type_reference)?
846 ParameterDeclaration pd = new ParameterDeclaration(SourceLocationFactory.ToLexicalInfo(id));
847 pd.Name = id.getText();
850 AddAttributes(pd.Attributes);
856 callable_parameter_declaration_list[ParameterDeclarationCollection c]:
857 (callable_parameter_declaration[c]
858 (COMMA callable_parameter_declaration[c])*)?
862 callable_parameter_declaration[ParameterDeclarationCollection c]
864 TypeReference tr = null;
865 ParameterModifiers pm = ParameterModifiers.None;
868 (pm=parameter_modifier)?
872 ParameterDeclaration pd = new ParameterDeclaration(tr.LexicalInfo);
873 pd.Name = "arg" + c.Count;
881 generic_parameter_declaration_list[GenericParameterDeclarationCollection c]:
882 generic_parameter_declaration[c]
884 COMMA generic_parameter_declaration[c]
889 generic_parameter_declaration[GenericParameterDeclarationCollection c]:
892 GenericParameterDeclaration gpd = new GenericParameterDeclaration(SourceLocationFactory.ToLexicalInfo(id));
893 gpd.Name = id.getText();
899 callable_type_reference returns [CallableTypeReference ctr]
902 TypeReference tr = null;
903 ParameterDeclarationCollection parameters = null;
907 ctr = new CallableTypeReference(SourceLocationFactory.ToLexicalInfo(c));
908 parameters = ctr.Parameters;
910 callable_parameter_declaration_list[parameters]
912 (AS tr=type_reference {
919 array_type_reference returns [ArrayTypeReference atr]
921 TypeReference tr = null;
923 IntegerLiteralExpression rank = null;
927 atr = new ArrayTypeReference(SourceLocationFactory.ToLexicalInfo(lparen));
930 tr=type_reference { atr.ElementType = tr; }
931 (COMMA rank=integer_literal { atr.Rank = rank; })?
937 type_reference_list [TypeReferenceCollection container]
939 TypeReference tr = null;
941 tr=type_reference { container.Add(tr); }
942 (options { greedy=true; }:
943 COMMA tr=type_reference { container.Add(tr); }
948 splice_type_reference returns [SpliceTypeReference tr]
953 begin:SPLICE_BEGIN e=atom
955 tr = new SpliceTypeReference(SourceLocationFactory.ToLexicalInfo(begin), e);
960 type_reference returns [TypeReference tr]
964 TypeReferenceCollection arguments = null;
965 GenericTypeDefinitionReference gtdr = null;
967 tr=splice_type_reference
969 tr=array_type_reference
971 (CALLABLE LPAREN)=>(tr=callable_type_reference)
982 gtdr = new GenericTypeDefinitionReference(SourceLocationFactory.ToLexicalInfo(id));
983 gtdr.Name = id.getText();
984 gtdr.GenericPlaceholders = 1;
990 gtdr.GenericPlaceholders++;
998 GenericTypeReference gtr = new GenericTypeReference(SourceLocationFactory.ToLexicalInfo(id), id.getText());
999 arguments = gtr.GenericArguments;
1002 type_reference_list[arguments]
1011 gtdr = new GenericTypeDefinitionReference(SourceLocationFactory.ToLexicalInfo(id));
1012 gtdr.Name = id.getText();
1013 gtdr.GenericPlaceholders = 1;
1019 OF tr=type_reference
1021 GenericTypeReference gtr = new GenericTypeReference(SourceLocationFactory.ToLexicalInfo(id), id.getText());
1022 gtr.GenericArguments.Add(tr);
1028 SimpleTypeReference str = new SimpleTypeReference(SourceLocationFactory.ToLexicalInfo(id));
1029 str.Name = id.getText();
1034 GenericTypeReference ntr = new GenericTypeReference(tr.LexicalInfo, "System.Nullable");
1035 ntr.GenericArguments.Add(tr);
1044 type_name returns [IToken id]
1048 id=identifier | c:CALLABLE { id=c; } | ch:CHAR { id=ch; }
1055 begin_with_doc[Node node]: COLON (eos docstring[node])?;
1058 begin_block_with_doc[Node node, Block block]:
1059 begin:COLON (eos docstring[node])?
1061 block.LexicalInfo = SourceLocationFactory.ToLexicalInfo(begin);
1067 t:END { node.EndSourceLocation = SourceLocationFactory.ToSourceLocation(t); }
1072 compound_stmt[Block b]
1074 StatementCollection statements = null;
1078 b.LexicalInfo = SourceLocationFactory.ToLexicalInfo(begin);
1079 statements = b.Statements;
1086 closure_macro_stmt returns [MacroStatement returnValue]
1089 MacroStatement macro = new MacroStatement();
1091 id:ID expression_list[macro.Arguments]
1093 macro.Name = id.getText();
1094 macro.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id);
1095 returnValue = macro;
1101 macro_stmt returns [MacroStatement returnValue]
1104 MacroStatement macro = new MacroStatement();
1105 StatementModifier modifier = null;
1107 id:ID expression_list[macro.Arguments]
1109 compound_stmt[macro.Block] |
1111 modifier=stmt_modifier eos { macro.Modifier = modifier; }
1114 macro.Name = id.getText();
1115 macro.LexicalInfo = SourceLocationFactory.ToLexicalInfo(id);
1117 returnValue = macro;
1122 goto_stmt returns [GotoStatement stmt]
1128 stmt = new GotoStatement(SourceLocationFactory.ToLexicalInfo(token),
1129 new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(label), label.getText()));
1134 label_stmt returns [LabelStatement stmt]
1138 token:COLON label:ID
1140 stmt = new LabelStatement(SourceLocationFactory.ToLexicalInfo(token), label.getText());
1145 stmt [StatementCollection container]
1148 StatementModifier m = null;
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 |
1160 (declaration COMMA)=> s=unpack_stmt |
1161 s=declaration_stmt |
1173 m=stmt_modifier { s.Modifier = m; }
1187 stmt_modifier returns [StatementModifier m]
1190 Expression e = null;
1192 StatementModifierType type = StatementModifierType.None;
1195 i:IF { t = i; type = StatementModifierType.If; } |
1196 u:UNLESS { t = u; type = StatementModifierType.Unless; } |
1197 w:WHILE { t = w; type = StatementModifierType.While; }
1199 e=boolean_expression
1201 m = new StatementModifier(SourceLocationFactory.ToLexicalInfo(t));
1208 callable_or_expression returns [Expression e]
1212 e=callable_expression|
1213 e=array_or_expression
1218 closure_parameters_test:
1219 (parameter_modifier)?
1220 (ID (AS type_reference)?)
1221 (COMMA ID (AS type_reference)?)*
1226 internal_closure_stmt[Block block]
1228 Statement stmt = null;
1229 StatementModifier modifier = null;
1232 stmt=return_expression_stmt |
1235 (declaration COMMA)=>stmt=unpack |
1236 {IsValidMacroArgument(LA(2))}? stmt=closure_macro_stmt |
1237 stmt=closure_expression_stmt |
1241 (modifier=stmt_modifier { stmt.Modifier = modifier; })?
1253 closure_expression_stmt returns [Statement s]
1256 Expression e = null;
1258 e=array_or_expression
1259 { s = new ExpressionStatement(e); }
1263 closure_expression returns [Expression e]
1266 BlockExpression cbe = null;
1267 ParameterDeclarationCollection parameters = null;
1272 e = cbe = new BlockExpression(SourceLocationFactory.ToLexicalInfo(anchorBegin));
1273 cbe.Annotate("inline");
1274 parameters = cbe.Parameters;
1279 (closure_parameters_test)=>(
1280 parameter_declaration_list[parameters]
1285 internal_closure_stmt[body]
1288 (internal_closure_stmt[body])?
1295 callable_expression returns [Expression e]
1299 BlockExpression cbe = null;
1300 TypeReference rt = null;
1301 IToken anchor = null;
1304 { body = new Block(); }
1306 { e = new BlockExpression(body.LexicalInfo, body); }
1310 (doAnchor:DO { anchor = doAnchor; }) |
1311 (defAnchor:DEF { anchor = defAnchor; })
1314 e = cbe = new BlockExpression(SourceLocationFactory.ToLexicalInfo(anchor));
1318 LPAREN parameter_declaration_list[cbe.Parameters] RPAREN
1319 (AS rt=type_reference { cbe.ReturnType = rt; })?
1326 try_stmt returns [TryStatement s]
1329 Block eblock = null;
1330 Block lastBlock = null;
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)=>
1336 lastBlock = exception_handler[s]
1339 ftoken:FAILURE { eblock = new Block(SourceLocationFactory.ToLexicalInfo(ftoken)); } begin
1340 block[eblock.Statements]
1341 { s.FailureBlock = lastBlock = eblock; }
1344 etoken:ENSURE { eblock = new Block(SourceLocationFactory.ToLexicalInfo(etoken)); } begin
1345 block[eblock.Statements]
1346 { s.EnsureBlock = lastBlock = eblock; }
1352 exception_handler [TryStatement t] returns [Block lastBlock]
1354 ExceptionHandler eh = null;
1355 TypeReference tr = null;
1356 Expression e = null;
1359 c:EXCEPT (x:ID)? (AS tr=type_reference)? ((IF|u:UNLESS) e=expression)? begin
1361 eh = new ExceptionHandler(SourceLocationFactory.ToLexicalInfo(c));
1363 eh.Declaration = new Declaration();
1364 eh.Declaration.Type = tr;
1368 eh.Declaration.LexicalInfo = SourceLocationFactory.ToLexicalInfo(x);
1369 eh.Declaration.Name = x.getText();
1373 eh.Declaration.Name = null;
1374 eh.Flags |= ExceptionHandlerFlags.Anonymous;
1378 eh.Declaration.LexicalInfo = tr.LexicalInfo;
1382 eh.Declaration.LexicalInfo = eh.LexicalInfo;
1386 eh.Flags |= ExceptionHandlerFlags.Untyped;
1392 UnaryExpression not = new UnaryExpression(SourceLocationFactory.ToLexicalInfo(u));
1393 not.Operator = UnaryOperatorType.LogicalNot;
1397 eh.FilterCondition = e;
1398 eh.Flags |= ExceptionHandlerFlags.Filter;
1400 eh.Block = new Block(SourceLocationFactory.ToLexicalInfo(c));
1402 block[eh.Block.Statements]
1404 lastBlock = eh.Block;
1405 t.ExceptionHandlers.Add(eh);
1410 raise_stmt returns [RaiseStatement s]
1413 Expression e = null;
1415 t:RAISE (e=expression)?
1417 s = new RaiseStatement(SourceLocationFactory.ToLexicalInfo(t));
1423 declaration_stmt returns [DeclarationStatement s]
1426 TypeReference tr = null;
1427 Expression initializer = null;
1428 StatementModifier m = null;
1430 id:ID AS tr=type_reference
1432 (ASSIGN initializer=declaration_initializer) |
1433 ((m=stmt_modifier)? eos)
1436 Declaration d = new Declaration(SourceLocationFactory.ToLexicalInfo(id));
1437 d.Name = id.getText();
1440 s = new DeclarationStatement(d.LexicalInfo);
1442 s.Initializer = initializer;
1448 expression_stmt returns [ExpressionStatement s]
1451 Expression e = null;
1453 e=assignment_expression
1455 s = new ExpressionStatement(e);
1459 return_expression_stmt returns [ReturnStatement s]
1462 Expression e = null;
1463 StatementModifier modifier = null;
1465 r:RETURN (e=array_or_expression)?
1466 (modifier=stmt_modifier)?
1468 s = new ReturnStatement(SourceLocationFactory.ToLexicalInfo(r));
1469 s.Modifier = modifier;
1475 return_stmt returns [ReturnStatement s]
1478 Expression e = null;
1479 StatementModifier modifier = null;
1484 e=array_or_expression
1486 (COLON|DO)=>e=method_invocation_block[e] |
1487 ((modifier=stmt_modifier)? eos)
1491 e=callable_expression
1494 (modifier=stmt_modifier)?
1499 s = new ReturnStatement(SourceLocationFactory.ToLexicalInfo(r));
1500 s.Modifier = modifier;
1506 yield_stmt returns [YieldStatement s]
1509 Expression e = null;
1511 yt:YIELD (e=array_or_expression)?
1513 s = new YieldStatement(SourceLocationFactory.ToLexicalInfo(yt));
1519 break_stmt returns [BreakStatement s]
1522 { s = new BreakStatement(SourceLocationFactory.ToLexicalInfo(b)); }
1526 continue_stmt returns [Statement s]
1529 { s = new ContinueStatement(SourceLocationFactory.ToLexicalInfo(c)); }
1533 unless_stmt returns [UnlessStatement us]
1536 Expression condition = null;
1538 u:UNLESS condition=expression
1540 us = new UnlessStatement(SourceLocationFactory.ToLexicalInfo(u));
1541 us.Condition = condition;
1543 compound_stmt[us.Block]
1547 for_stmt returns [ForStatement fs]
1550 Expression iterator = null;
1551 DeclarationCollection declarations = null;
1553 Block lastBlock = null;
1557 fs = new ForStatement(SourceLocationFactory.ToLexicalInfo(f));
1558 declarations = fs.Declarations;
1559 lastBlock = body = fs.Block;
1561 declaration_list[declarations] IN iterator=array_or_expression
1562 { fs.Iterator = iterator; }
1563 begin block[body.Statements]
1565 or:OR { lastBlock = fs.OrBlock = new Block(SourceLocationFactory.ToLexicalInfo(or)); }
1566 begin block[fs.OrBlock.Statements]
1569 et:THEN { lastBlock = fs.ThenBlock = new Block(SourceLocationFactory.ToLexicalInfo(et)); }
1570 begin block[fs.ThenBlock.Statements]
1576 while_stmt returns [WhileStatement ws]
1579 Expression e = null;
1580 Block lastBlock = null;
1582 w:WHILE e=expression
1584 ws = new WhileStatement(SourceLocationFactory.ToLexicalInfo(w));
1586 lastBlock = ws.Block;
1588 begin block[ws.Block.Statements]
1590 or:OR { lastBlock = ws.OrBlock = new Block(SourceLocationFactory.ToLexicalInfo(or)); }
1591 begin block[ws.OrBlock.Statements]
1594 et:THEN { lastBlock = ws.ThenBlock = new Block(SourceLocationFactory.ToLexicalInfo(et)); }
1595 begin block[ws.ThenBlock.Statements]
1601 if_stmt returns [IfStatement returnValue]
1605 IfStatement s = null;
1606 Expression e = null;
1607 Block lastBlock = null;
1611 returnValue = s = new IfStatement(SourceLocationFactory.ToLexicalInfo(it));
1613 lastBlock = s.TrueBlock = new Block();
1615 begin block[s.TrueBlock.Statements]
1617 ei:ELIF e=expression
1619 s.FalseBlock = new Block();
1621 IfStatement elif = new IfStatement(SourceLocationFactory.ToLexicalInfo(ei));
1622 lastBlock = elif.TrueBlock = new Block();
1625 s.FalseBlock.Add(elif);
1628 begin block[s.TrueBlock.Statements]
1631 et:ELSE { lastBlock = s.FalseBlock = new Block(SourceLocationFactory.ToLexicalInfo(et)); }
1632 begin block[s.FalseBlock.Statements]
1638 unpack_stmt returns [UnpackStatement s]
1641 StatementModifier m = null;
1643 s=unpack (m=stmt_modifier)? eos
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
1661 s.LexicalInfo = SourceLocationFactory.ToLexicalInfo(t);
1668 declaration_list[DeclarationCollection dc]
1670 Declaration d = null;
1672 d=declaration { dc.Add(d); }
1673 (COMMA d=declaration { dc.Add(d); })*
1677 declaration returns [Declaration d]
1680 TypeReference tr = null;
1682 id:ID (AS tr=type_reference)?
1684 d = new Declaration(SourceLocationFactory.ToLexicalInfo(id));
1685 d.Name = id.getText();
1691 array_or_expression returns [Expression e]
1694 ArrayLiteralExpression tle = null;
1697 // tupla vazia: , ou (,)
1698 c:COMMA { e = new ArrayLiteralExpression(SourceLocationFactory.ToLexicalInfo(c)); }
1702 ( options { greedy=true; }:
1705 tle = new ArrayLiteralExpression(e.LexicalInfo);
1708 ( options { greedy=true; }:
1709 e=expression { tle.Items.Add(e); }
1710 ( options { greedy=true; }:
1712 e=expression { tle.Items.Add(e); }
1724 expression returns [Expression e]
1728 ExtendedGeneratorExpression mge = null;
1729 GeneratorExpression ge = null;
1731 e=boolean_expression
1733 ( options { greedy = true; } :
1736 ge = new GeneratorExpression(SourceLocationFactory.ToLexicalInfo(f));
1740 generator_expression_body[ge]
1746 mge = new ExtendedGeneratorExpression(SourceLocationFactory.ToLexicalInfo(f));
1751 ge = new GeneratorExpression(SourceLocationFactory.ToLexicalInfo(f2));
1754 generator_expression_body[ge]
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]
1767 iterator=boolean_expression { ge.Iterator = iterator; }
1769 filter=stmt_modifier { ge.Filter = filter; }
1774 boolean_expression returns [Expression e]
1777 Expression r = null;
1786 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(ot));
1787 be.Operator = BinaryOperatorType.Or;
1797 boolean_term returns [Expression e]
1800 Expression r = null;
1808 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(at));
1809 be.Operator = BinaryOperatorType.And;
1818 method_invocation_block[Expression e] returns [MethodInvocationExpression mi]
1820 Expression block = null;
1823 block=callable_expression
1825 mi = e as MethodInvocationExpression;
1828 mi = new MethodInvocationExpression(e.LexicalInfo, e);
1830 mi.Arguments.Add(block);
1834 ast_literal_expression returns [QuasiquoteExpression e]
1840 { e = new QuasiquoteExpression(SourceLocationFactory.ToLexicalInfo(begin)); }
1842 (expression QQ_END)=>node=expression { e.Node = node; }
1843 | ((eos)? ast_literal_block[e])
1846 { e.EndSourceLocation = SourceLocationFactory.ToSourceLocation(end); }
1849 type_definition_member_prediction:
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;
1863 (type_definition_member_prediction)=>(
1864 type_definition_member[collection]
1865 { e.Node = collection[0]; }
1870 if (block.Statements.Count > 0)
1872 e.Node = block.Statements.Count > 1 ? block : block.Statements[0];
1880 assignment_or_method_invocation_with_block_stmt returns [Statement stmt]
1883 Expression lhs = null;
1884 Expression rhs = null;
1885 StatementModifier modifier = null;
1886 BinaryOperatorType binaryOperator = BinaryOperatorType.None;
1887 IToken token = null;
1889 lhs=slicing_expression
1892 lhs=method_invocation_block[lhs]
1893 { stmt = new ExpressionStatement(lhs); }
1897 op:ASSIGN { token = op; binaryOperator = OperatorParser.ParseAssignment(op.getText()); }
1899 (COLON|DEF|DO)=>rhs=callable_expression |
1901 rhs=array_or_expression
1903 (COLON|DO)=>rhs=method_invocation_block[rhs] |
1904 (modifier=stmt_modifier eos) |
1911 stmt = new ExpressionStatement(
1912 new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token),
1915 stmt.Modifier = modifier;
1922 not_expression returns [Expression e]
1928 (nt:NOT e=not_expression) |
1929 e=assignment_expression
1934 UnaryExpression ue = new UnaryExpression(SourceLocationFactory.ToLexicalInfo(nt));
1935 ue.Operator = UnaryOperatorType.LogicalNot;
1943 assignment_expression returns [Expression e]
1947 IToken token = null;
1948 BinaryOperatorType binaryOperator = BinaryOperatorType.None;
1950 e=conditional_expression
1952 options { greedy = true; }:
1958 binaryOperator = OperatorParser.ParseAssignment(op.getText());
1962 ipbo:INPLACE_BITWISE_OR {
1964 binaryOperator = BinaryOperatorType.InPlaceBitwiseOr;
1968 ipba:INPLACE_BITWISE_AND {
1970 binaryOperator = BinaryOperatorType.InPlaceBitwiseAnd;
1974 ipsl:INPLACE_SHIFT_LEFT {
1976 binaryOperator = BinaryOperatorType.InPlaceShiftLeft;
1980 ipsr:INPLACE_SHIFT_RIGHT {
1982 binaryOperator = BinaryOperatorType.InPlaceShiftRight;
1986 r=assignment_expression
1988 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
1989 be.Operator = binaryOperator;
1998 conditional_expression returns [Expression e]
2001 Expression r = null;
2002 BinaryOperatorType op = BinaryOperatorType.None;
2003 IToken token = null;
2004 TypeReference tr = null;
2007 ( options { greedy = true; } :
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; } )
2025 op = BinaryOperatorType.TypeTest;
2027 r = new TypeofExpression(tr.LexicalInfo, tr);
2032 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2042 sum returns [Expression e]
2045 Expression r = null;
2047 BinaryOperatorType bOperator = BinaryOperatorType.None;
2050 ( options { greedy = true; } :
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; }
2059 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(op));
2060 be.Operator = bOperator;
2069 term returns [Expression e]
2072 Expression r = null;
2073 IToken token = null;
2074 BinaryOperatorType op = BinaryOperatorType.None;
2077 ( options { greedy = true; } :
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; }
2086 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2096 factor returns [Expression e]
2099 Expression r = null;
2100 IToken token = null;
2101 BinaryOperatorType op = BinaryOperatorType.None;
2104 (options { greedy = true; }:
2106 shl:SHIFT_LEFT { op=BinaryOperatorType.ShiftLeft; token = shl; } |
2107 shr:SHIFT_RIGHT { op=BinaryOperatorType.ShiftRight; token = shr; }
2111 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2121 exponentiation returns [Expression e]
2124 Expression r = null;
2125 TypeReference tr = null;
2132 TryCastExpression ae = new TryCastExpression(SourceLocationFactory.ToLexicalInfo(t));
2139 ( options { greedy = true; }:
2140 token:EXPONENTIATION
2143 BinaryExpression be = new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token));
2144 be.Operator = BinaryOperatorType.Exponentiation;
2154 unary_expression returns [Expression e]
2158 UnaryOperatorType uOperator = UnaryOperatorType.None;
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; }
2171 e=slicing_expression
2173 postinc:INCREMENT { op = postinc; uOperator = UnaryOperatorType.PostIncrement; } |
2174 postdec:DECREMENT { op = postdec; uOperator = UnaryOperatorType.PostDecrement; }
2181 UnaryExpression ue = new UnaryExpression(SourceLocationFactory.ToLexicalInfo(op));
2182 ue.Operator = uOperator;
2190 atom returns [Expression e]
2196 (CHAR LPAREN)=>e=char_literal |
2197 e=reference_expression |
2198 e=paren_expression |
2200 e=typeof_expression |
2206 splice_expression returns [Expression e]
2210 begin:SPLICE_BEGIN e=atom
2212 e = new SpliceExpression(SourceLocationFactory.ToLexicalInfo(begin), e);
2217 char_literal returns [Expression e]
2223 t:SINGLE_QUOTED_STRING
2225 e = new CharLiteralExpression(SourceLocationFactory.ToLexicalInfo(t), t.getText());
2230 e = new CharLiteralExpression(SourceLocationFactory.ToLexicalInfo(i), (char) PrimitiveParser.ParseInt(i));
2237 cast_expression returns [Expression e]
2240 TypeReference tr = null;
2241 Expression target = null;
2243 t:CAST LPAREN tr=type_reference COMMA target=expression RPAREN
2245 e = new CastExpression(SourceLocationFactory.ToLexicalInfo(t), target, tr);
2250 typeof_expression returns [Expression e]
2253 TypeReference tr = null;
2255 t:TYPEOF LPAREN tr=type_reference RPAREN
2257 e = new TypeofExpression(SourceLocationFactory.ToLexicalInfo(t), tr);
2263 reference_expression returns [ReferenceExpression e]
2273 e = new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(t));
2274 e.Name = t.getText();
2279 paren_expression returns [Expression e]
2282 Expression condition = null;
2283 Expression falseValue = null;
2285 (LPAREN OF)=>e=typed_array
2289 e=array_or_expression
2291 IF condition=boolean_expression
2292 ELSE falseValue=array_or_expression
2294 ConditionalExpression ce = new ConditionalExpression(SourceLocationFactory.ToLexicalInfo(lparen));
2295 ce.Condition = condition;
2297 ce.FalseValue = falseValue;
2307 typed_array returns [Expression e]
2310 ArrayLiteralExpression tle = null;
2311 TypeReference tr = null;
2312 Expression item = null;
2315 OF tr=type_reference COLON
2317 e = tle = new ArrayLiteralExpression(SourceLocationFactory.ToLexicalInfo(t));
2318 tle.Type = new ArrayTypeReference(tr.LexicalInfo, tr);
2324 item=expression { tle.Items.Add(item); }
2327 item=expression { tle.Items.Add(item); }
2336 method_invocation_with_block returns [Statement s]
2339 MethodInvocationExpression mie = null;
2340 Expression block = null;
2344 block=callable_expression
2346 mie.Arguments.Add(block);
2352 member returns [IToken name]
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; } |
2366 slice[SlicingExpression se]
2368 Expression begin = null;
2369 Expression end = null;
2370 Expression step = null;
2375 COLON { begin = OmittedExpression.Default; }
2382 COLON { end = OmittedExpression.Default; }
2395 end=expression | { end = OmittedExpression.Default; }
2405 se.Indices.Add(new Slice(begin, end, step));
2410 member_reference_expression[Expression target] returns [Expression e]
2413 IToken memberName = null;
2417 MemberReferenceExpression mre = new MemberReferenceExpression(SourceLocationFactory.ToLexicalInfo(memberName));
2418 mre.Target = target;
2419 mre.Name = memberName.getText();
2425 slicing_expression returns [Expression e]
2428 SlicingExpression se = null;
2429 MethodInvocationExpression mce = null;
2430 TypeReference genericArgument = null;
2431 TypeReferenceCollection genericArguments = null;
2434 ( options { greedy=true; }:
2441 GenericReferenceExpression gre = new GenericReferenceExpression(SourceLocationFactory.ToLexicalInfo(lbrack));
2444 genericArguments = gre.GenericArguments;
2446 type_reference_list[genericArguments]
2450 se = new SlicingExpression(SourceLocationFactory.ToLexicalInfo(lbrack));
2454 slice[se] (COMMA slice[se])*
2460 oft:OF genericArgument=type_reference
2462 GenericReferenceExpression gre = new GenericReferenceExpression(SourceLocationFactory.ToLexicalInfo(oft));
2465 gre.GenericArguments.Add(genericArgument);
2471 e=member_reference_expression[e]
2476 e=member_reference_expression[e]
2482 mce = new MethodInvocationExpression(SourceLocationFactory.ToLexicalInfo(lparen));
2487 method_invocation_argument[mce]
2490 method_invocation_argument[mce]
2499 method_invocation_argument[MethodInvocationExpression mie]
2501 Expression arg = null;
2504 t:MULTIPLY arg=expression
2509 new UnaryExpression(
2510 SourceLocationFactory.ToLexicalInfo(t),
2511 UnaryOperatorType.Explode,
2520 literal returns [Expression e]
2528 (hash_literal_test)=>e=hash_literal |
2529 e=closure_expression |
2530 e=ast_literal_expression |
2542 self_literal returns [SelfLiteralExpression e] { e = null; }:
2543 t:SELF { e = new SelfLiteralExpression(SourceLocationFactory.ToLexicalInfo(t)); }
2547 super_literal returns [SuperLiteralExpression e] { e = null; }:
2548 t:SUPER { e = new SuperLiteralExpression(SourceLocationFactory.ToLexicalInfo(t)); }
2552 null_literal returns [NullLiteralExpression e] { e = null; }:
2553 t:NULL { e = new NullLiteralExpression(SourceLocationFactory.ToLexicalInfo(t)); }
2557 bool_literal returns [BoolLiteralExpression e] { e = null; }:
2560 e = new BoolLiteralExpression(SourceLocationFactory.ToLexicalInfo(t));
2565 e = new BoolLiteralExpression(SourceLocationFactory.ToLexicalInfo(f));
2571 integer_literal returns [IntegerLiteralExpression e]
2581 if (neg != null) val = neg.getText() + val;
2582 e = PrimitiveParser.ParseIntegerLiteralExpression(i, val, false);
2588 val = val.Substring(0, val.Length-1);
2589 if (neg != null) val = neg.getText() + val;
2590 e = PrimitiveParser.ParseIntegerLiteralExpression(l, val, true);
2596 string_literal returns [Expression e]
2600 e=expression_interpolation |
2601 dqs:DOUBLE_QUOTED_STRING
2603 e = new StringLiteralExpression(SourceLocationFactory.ToLexicalInfo(dqs), dqs.getText());
2605 sqs:SINGLE_QUOTED_STRING
2607 e = new StringLiteralExpression(SourceLocationFactory.ToLexicalInfo(sqs), sqs.getText());
2609 tqs:TRIPLE_QUOTED_STRING
2611 e = new StringLiteralExpression(SourceLocationFactory.ToLexicalInfo(tqs), tqs.getText());
2616 expression_interpolation returns [ExpressionInterpolationExpression e]
2619 Expression param = null;
2621 separator:ESEPARATOR
2623 LexicalInfo info = SourceLocationFactory.ToLexicalInfo(separator);
2624 e = new ExpressionInterpolationExpression(info);
2626 ( options { greedy = true; } :
2629 param=expression { if (null != param) { e.Expressions.Add(param); } }
2636 list_literal returns [Expression e]
2639 ListLiteralExpression lle = null;
2640 Expression item = null;
2648 e = lle = new ListLiteralExpression(SourceLocationFactory.ToLexicalInfo(lbrack));
2649 lle.Items.Add(item);
2651 ( options { greedy = true; } :
2652 COMMA item=expression { lle.Items.Add(item); }
2658 { e = new ListLiteralExpression(SourceLocationFactory.ToLexicalInfo(lbrack)); }
2665 LBRACE (RBRACE|(expression COLON))
2669 hash_literal returns [HashLiteralExpression dle]
2672 ExpressionPair pair = null;
2674 lbrace:LBRACE { dle = new HashLiteralExpression(SourceLocationFactory.ToLexicalInfo(lbrace)); }
2676 pair=expression_pair
2677 { dle.Items.Add(pair); }
2680 pair=expression_pair
2681 { dle.Items.Add(pair); }
2689 expression_pair returns [ExpressionPair ep]
2692 Expression key = null;
2693 Expression value = null;
2695 key=expression t:COLON value=expression
2696 { ep = new ExpressionPair(SourceLocationFactory.ToLexicalInfo(t), key, value); }
2700 re_literal returns [RELiteralExpression re] { re = null; }:
2702 { re = new RELiteralExpression(SourceLocationFactory.ToLexicalInfo(value), value.getText()); }
2706 double_literal returns [DoubleLiteralExpression rle]
2714 val = value.getText();
2715 if (neg != null) val = neg.getText() + val;
2716 rle = new DoubleLiteralExpression(SourceLocationFactory.ToLexicalInfo(value), PrimitiveParser.ParseDouble(val));
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);
2729 timespan_literal returns [TimeSpanLiteralExpression tsle] { tsle = null; }:
2733 string val = value.getText();
2734 if (neg != null) val = neg.getText() + val;
2735 tsle = new TimeSpanLiteralExpression(SourceLocationFactory.ToLexicalInfo(value), PrimitiveParser.ParseTimeSpan(val));
2740 expression_list[ExpressionCollection ec]
2742 Expression e = null;
2745 e=expression { ec.Add(e); }
2748 e=expression { ec.Add(e); }
2754 argument_list[INodeWithArguments node]:
2765 argument[INodeWithArguments node]
2767 Expression value = null;
2770 id:ID colon:COLON value=expression
2772 node.NamedArguments.Add(
2774 SourceLocationFactory.ToLexicalInfo(colon),
2775 new ReferenceExpression(SourceLocationFactory.ToLexicalInfo(id), id.getText()),
2781 { if (null != value) { node.Arguments.Add(value); } }
2786 identifier returns [IToken value]
2788 value = null; _sbuilder.Length = 0;
2793 _sbuilder.Append(id1.getText());
2796 ( options { greedy = true; } :
2799 { _sbuilder.Append('.'); _sbuilder.Append(id2.getText()); }
2801 { value.setText(_sbuilder.ToString()); }
2804 using Boo.Lang.Parser.Util;
2806 class WSABooLexer extends Lexer;
2809 testLiterals = false;
2810 exportVocab = WSABoo;
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;
2821 TokenStreamRecorder _erecorder;
2823 antlr.TokenStreamSelector _selector;
2825 internal void Initialize(antlr.TokenStreamSelector selector, int tabSize, antlr.TokenCreator tokenCreator)
2827 setTabSize(tabSize);
2828 setTokenCreator(tokenCreator);
2830 _selector = selector;
2831 _erecorder = new TokenStreamRecorder(selector);
2834 internal antlr.TokenStream CreateExpressionLexer()
2836 WSABooExpressionLexer lexer = new WSABooExpressionLexer(getInputState());
2837 lexer.setTabSize(getTabSize());
2838 lexer.setTokenCreator(tokenCreator);
2842 internal static bool IsDigit(char ch)
2844 return ch >= '0' && ch <= '9';
2851 return _skipWhitespaceRegion > 0;
2855 void Enqueue(antlr.IToken token, string text)
2857 token.setText(text);
2858 _erecorder.Enqueue(makeESEPARATOR());
2859 _erecorder.Enqueue(token);
2860 _erecorder.Enqueue(makeESEPARATOR());
2863 antlr.IToken makeESEPARATOR()
2865 return makeToken(ESEPARATOR);
2868 internal void EnterSkipWhitespaceRegion()
2870 ++_skipWhitespaceRegion;
2873 internal void LeaveSkipWhitespaceRegion()
2875 --_skipWhitespaceRegion;
2879 ID options { testLiterals = true; }:
2880 (ID_PREFIX)? ID_LETTER (ID_LETTER | DIGIT)*
2885 { $setType(Token.SKIP); }
2889 ("0x"(HEXDIGIT)+)(('l' | 'L') { $setType(LONG); })? |
2891 (('e'|'E')('+'|'-')? DIGIT_GROUP)?
2893 ('l' | 'L') { $setType(LONG); } |
2894 (('f' | 'F') { $setType(FLOAT); }) |
2897 {WSABooLexer.IsDigit(LA(2))}?
2899 '.' REVERSE_DIGIT_GROUP
2900 (('e'|'E')('+'|'-')? DIGIT_GROUP)?
2903 (('f' | 'F') { $setType(FLOAT); }) |
2904 { $setType(DOUBLE); }
2907 (("ms" | 's' | 'm' | 'h' | 'd') { $setType(TIMESPAN); })?
2914 REVERSE_DIGIT_GROUP (('e'|'E')('+'|'-')? DIGIT_GROUP)?
2916 (('f' | 'F') { $setType(FLOAT); }) |
2917 (("ms" | 's' | 'm' | 'h' | 'd') { $setType(TIMESPAN); }) |
2925 BITWISE_OR: '|' ('=' { $setType(INPLACE_BITWISE_OR); })?;
2927 BITWISE_AND: '&' ('=' { $setType(INPLACE_BITWISE_AND); })?;
2929 EXCLUSIVE_OR: '^' ('=' { $setType(ASSIGN); })?;
2931 LPAREN : '(' { EnterSkipWhitespaceRegion(); };
2933 RPAREN : ')' { LeaveSkipWhitespaceRegion(); };
2936 ASSEMBLY_ATTRIBUTE_BEGIN: "assembly:";
2938 LBRACK : '[' { EnterSkipWhitespaceRegion(); }
2940 ("assembly:")=> "assembly:" { $setType(ASSEMBLY_ATTRIBUTE_BEGIN); } |
2944 RBRACK : ']' { LeaveSkipWhitespaceRegion(); };
2946 LBRACE : '{' { EnterSkipWhitespaceRegion(); };
2948 RBRACE : '}' { LeaveSkipWhitespaceRegion(); };
2960 ADD: ('+') ('=' { $setType(ASSIGN); })?;
2962 SUBTRACT: ('-') ('=' { $setType(ASSIGN); })?;
2966 MULTIPLY: '*' ('=' { $setType(ASSIGN); })?;
2968 EXPONENTIATION: "**";
2971 ("/*")=> ML_COMMENT { $setType(Token.SKIP); } |
2972 (RE_LITERAL)=> RE_LITERAL { $setType(RE_LITERAL); } |
2974 ('/' (~('\r'|'\n'))* { $setType(Token.SKIP); }) |
2975 ('=' { $setType(ASSIGN); }) |
2983 INPLACE_SHIFT_LEFT: "<<=";
2989 INPLACE_SHIFT_RIGHT: ">>=";
2991 ONES_COMPLEMENT: '~';
2993 CMP_OPERATOR : "<=" | ">=" | "!~" | "!=";
2995 ASSIGN : '=' ( ('=' | '~') { $setType(CMP_OPERATOR); } )?;
3000 TRIPLE_QUOTED_STRING:
3003 options { greedy=false; }:
3006 Enqueue(makeToken(TRIPLE_QUOTED_STRING), $getText);
3009 ESCAPED_EXPRESSION |
3010 ("\\$")=>'\\'! '$' |
3017 DOUBLE_QUOTED_STRING:
3020 {LA(1)=='"' && LA(2)=='"'}?TRIPLE_QUOTED_STRING { $setType(TRIPLE_QUOTED_STRING); }
3027 Enqueue(makeToken(DOUBLE_QUOTED_STRING), $getText);
3030 ESCAPED_EXPRESSION |
3031 ~('"' | '\\' | '\r' | '\n')
3037 if (_erecorder.Count > 0)
3039 Enqueue(makeToken(DOUBLE_QUOTED_STRING), $getText);
3040 $setType(ESEPARATOR);
3042 _selector.push(_erecorder);
3047 SINGLE_QUOTED_STRING :
3051 ~('\'' | '\\' | '\r' | '\n')
3058 { $setType(Token.SKIP); }
3065 { LA(2) != '/' }? '*' |
3066 ("/*")=>ML_COMMENT |
3071 { $setType(Token.SKIP); }
3081 $setType(Token.SKIP);
3087 X_RE_LITERAL: '@'!'/' (X_RE_CHAR)+ '/' { $setType(RE_LITERAL); };
3103 $setType(Token.SKIP);
3109 ESCAPED_EXPRESSION : "${"!
3111 _erecorder.Enqueue(makeESEPARATOR());
3112 if (0 == _erecorder.RecordUntil(CreateExpressionLexer(), RBRACE, LBRACE))
3114 _erecorder.Dequeue();
3118 _erecorder.Enqueue(makeESEPARATOR());
3125 DQS_ESC : '\\'! ( SESC | '"' | '$') ;
3128 SQS_ESC : '\\'! ( 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"); }) |
3140 HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT
3142 char ch = (char)int.Parse(text.ToString(_begin, 4), System.Globalization.NumberStyles.HexNumber);
3143 text.Length = _begin;
3147 ( '\\'! {$setText("\\"); });
3151 RE_LITERAL : '/' (RE_CHAR)+ '/';
3154 RE_CHAR : RE_ESC | ~('/' | '\\' | '\r' | '\n' | ' ' | '\t' );
3157 X_RE_CHAR: RE_CHAR | ' ' | '\t';
3177 // ms-help://MS.NETFrameworkSDKv1.1/cpgenref/html/cpconcharacterescapes.htm
3189 ('x' HEXDIGIT HEXDIGIT) |
3190 ('u' HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT) |
3193 // character classes
3194 // ms-help://MS.NETFrameworkSDKv1.1/cpgenref/html/cpconcharacterclasses.htm
3206 // atomic zero-width assertions
3207 // ms-help://MS.NETFrameworkSDKv1.1/cpgenref/html/cpconatomiczero-widthassertions.htm
3218 DIGIT_GROUP : DIGIT (('_'! DIGIT DIGIT DIGIT) | DIGIT)*;
3221 REVERSE_DIGIT_GROUP : (DIGIT DIGIT DIGIT ({WSABooLexer.IsDigit(LA(2))}? '_'!)? | DIGIT)+;
3227 ID_LETTER : ('_' | 'a'..'z' | 'A'..'Z' | {System.Char.IsLetter(LA(1))}? '\u0080'..'\uFFFE');
3233 HEXDIGIT : ('a'..'f' | 'A'..'F' | '0'..'9');
3235 NULLABLE_SUFFIX: '?';