Browse Source

r3143@daniel-notebook: daniel | 2008-06-26 22:55:25 +0200

Fixed VB parser bugs related to ":" statement separator use in global scope


git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3139 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
f9bf7d61cd
  1. 2278
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 35
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 24
      src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs
  4. 6
      src/Libraries/NRefactory/Test/Parser/ParseUtilVBNet.cs
  5. 4
      src/Libraries/NRefactory/Test/Parser/Statements/LabelStatementTests.cs

2278
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

35
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -231,14 +231,15 @@ VBNET @@ -231,14 +231,15 @@ VBNET
(.
lexer.NextToken(); // get the first token
compilationUnit = new CompilationUnit();
.) =
{ EOL }
{ OptionStmt }
{ ImportsStmt}
{ IF (IsGlobalAttrTarget()) GlobalAttributeSection }
{ NamespaceMemberDecl }
.)
=
{ EndOfStmt }
{ OptionStmt { EndOfStmt } }
{ ImportsStmt { EndOfStmt } }
{ IF (IsGlobalAttrTarget()) GlobalAttributeSection { EndOfStmt } }
{ NamespaceMemberDecl { EndOfStmt } }
EOF
.
.
OptionStmt (. INode node = null; bool val = true; .) =
"Option" (. Location startPos = t.Location; .)
@ -529,13 +530,18 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes> @@ -529,13 +530,18 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
.
NamespaceBody =
{ NamespaceMemberDecl }
{ EndOfStmt } /* allow empty lines at begin of body */
{
NamespaceMemberDecl
{ EndOfStmt } /* allow empty lines in body */
}
"End" "Namespace"
EndOfStmt
.
ClassBody<TypeDeclaration newType>
(. AttributeSection section; .) =
{ EndOfStmt } /* allow empty lines at begin of body */
{
(.List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
@ -543,11 +549,13 @@ ClassBody<TypeDeclaration newType> @@ -543,11 +549,13 @@ ClassBody<TypeDeclaration newType>
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ MemberModifier<m> }
ClassMemberDecl<m, attributes>
{ EndOfStmt } /* allow empty lines in body */
}
.
StructureBody<TypeDeclaration newType>
(. AttributeSection section; .) =
{ EndOfStmt } /* allow empty lines at begin of body */
{
(.List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
@ -555,6 +563,7 @@ StructureBody<TypeDeclaration newType> @@ -555,6 +563,7 @@ StructureBody<TypeDeclaration newType>
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ MemberModifier<m> }
StructureMemberDecl<m, attributes>
{ EndOfStmt } /* allow empty lines in body */
}
"End" "Structure" (. newType.EndLocation = t.EndLocation; .)
EndOfStmt
@ -563,6 +572,7 @@ StructureBody<TypeDeclaration newType> @@ -563,6 +572,7 @@ StructureBody<TypeDeclaration newType>
/* 7.7.1 */
ModuleBody<TypeDeclaration newType>
(. AttributeSection section; .) =
{ EndOfStmt } /* allow empty lines at begin of body */
{
(.List<AttributeSection> attributes = new List<AttributeSection>();
ModifierList m = new ModifierList();
@ -570,6 +580,7 @@ ModuleBody<TypeDeclaration newType> @@ -570,6 +580,7 @@ ModuleBody<TypeDeclaration newType>
{ AttributeSection<out section> (. attributes.Add(section); .) }
{ MemberModifier<m> }
ClassMemberDecl<m, attributes>
{ EndOfStmt } /* allow empty lines in body */
}
"End" "Module" (. newType.EndLocation = t.EndLocation; .)
EndOfStmt
@ -577,15 +588,21 @@ ModuleBody<TypeDeclaration newType> @@ -577,15 +588,21 @@ ModuleBody<TypeDeclaration newType>
EnumBody<TypeDeclaration newType>
(. FieldDeclaration f; .) =
{ EndOfStmt } /* allow empty lines at begin of body */
{
EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .)
{ EndOfStmt } /* allow empty lines in body */
}
"End" "Enum" (. newType.EndLocation = t.EndLocation; .)
EndOfStmt
.
InterfaceBody<TypeDeclaration newType> =
{ InterfaceMemberDecl }
{ EndOfStmt } /* allow empty lines at begin of body */
{
InterfaceMemberDecl
{ EndOfStmt } /* allow empty lines in body */
}
"End" "Interface" (. newType.EndLocation = t.EndLocation; .)
EndOfStmt
.

24
src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs

@ -220,6 +220,18 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -220,6 +220,18 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(3, td.Children.Count);
}
[Test]
public void VBNetEnumOnSingleLine2()
{
string program = "Enum TestEnum : A : : B = 1 :: C : End Enum";
TypeDeclaration td = ParseUtilVBNet.ParseGlobal<TypeDeclaration>(program);
Assert.AreEqual("TestEnum", td.Name);
Assert.AreEqual(ClassType.Enum, td.Type);
Assert.AreEqual(3, td.Children.Count);
}
[Test]
public void VBNetEnumWithSystemBaseClassDeclarationTest()
{
@ -246,6 +258,18 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -246,6 +258,18 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(2, td.EndLocation.Y, "end line");
}
[Test]
public void VBNetSimpleClassTypeDeclarationWithColon()
{
string program = "Class TestClass\n" +
" : \n" +
"End Class";
TypeDeclaration td = ParseUtilVBNet.ParseGlobal<TypeDeclaration>(program);
Assert.AreEqual("TestClass", td.Name);
Assert.AreEqual(ClassType.Class, td.Type);
}
[Test]
public void VBNetSimplePartialClassTypeDeclarationTest()
{

6
src/Libraries/NRefactory/Test/Parser/ParseUtilVBNet.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully");
else
Assert.AreEqual("", parser.Errors.ErrorOutput);
Assert.IsTrue(parser.CompilationUnit.Children.Count > 0);
Assert.AreEqual(1, parser.CompilationUnit.Children.Count);
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(parser.CompilationUnit.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parser.CompilationUnit.Children[0].GetType(), type, parser.CompilationUnit.Children[0]));
return (T)parser.CompilationUnit.Children[0];
@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public static T ParseTypeMember<T>(string typeMember, bool expectErrors) where T : INode
{
TypeDeclaration td = ParseGlobal<TypeDeclaration>("Class TestClass\n " + typeMember + "\n End Class\n", expectErrors);
Assert.IsTrue(td.Children.Count > 0);
Assert.AreEqual(1, td.Children.Count);
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(td.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", td.GetType(), type, td));
return (T)td.Children[0];
@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public static T ParseStatement<T>(string statement, bool expectErrors) where T : INode
{
MethodDeclaration md = ParseTypeMember<MethodDeclaration>("Sub A()\n " + statement + "\nEnd Sub\n", expectErrors);
Assert.IsTrue(md.Body.Children.Count > 0);
Assert.AreEqual(1, md.Body.Children.Count);
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(md.Body.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", md.GetType(), type, md));
return (T)md.Body.Children[0];

4
src/Libraries/NRefactory/Test/Parser/Statements/LabelStatementTests.cs

@ -35,7 +35,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -35,7 +35,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test]
public void VBNetLabelStatementTest()
{
LabelStatement labelStmt = ParseUtilVBNet.ParseStatement<LabelStatement>("myLabel: Console.WriteLine()");
MethodDeclaration method = ParseUtilVBNet.ParseTypeMember<MethodDeclaration>("Sub Test \n myLabel: Console.WriteLine() \n End Sub");
Assert.AreEqual(2, method.Body.Children.Count);
LabelStatement labelStmt = (LabelStatement)method.Body.Children[0];
Assert.AreEqual("myLabel", labelStmt.Label);
}
#endregion

Loading…
Cancel
Save