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

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

@ -220,6 +220,18 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(3, td.Children.Count); 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] [Test]
public void VBNetEnumWithSystemBaseClassDeclarationTest() public void VBNetEnumWithSystemBaseClassDeclarationTest()
{ {
@ -246,6 +258,18 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual(2, td.EndLocation.Y, "end line"); 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] [Test]
public void VBNetSimplePartialClassTypeDeclarationTest() public void VBNetSimplePartialClassTypeDeclarationTest()
{ {

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

@ -28,7 +28,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully");
else else
Assert.AreEqual("", parser.Errors.ErrorOutput); Assert.AreEqual("", parser.Errors.ErrorOutput);
Assert.IsTrue(parser.CompilationUnit.Children.Count > 0); Assert.AreEqual(1, parser.CompilationUnit.Children.Count);
Type type = typeof(T); 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])); 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]; return (T)parser.CompilationUnit.Children[0];
@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public static T ParseTypeMember<T>(string typeMember, bool expectErrors) where T : INode 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); 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); 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)); 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]; return (T)td.Children[0];
@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public static T ParseStatement<T>(string statement, bool expectErrors) where T : INode public static T ParseStatement<T>(string statement, bool expectErrors) where T : INode
{ {
MethodDeclaration md = ParseTypeMember<MethodDeclaration>("Sub A()\n " + statement + "\nEnd Sub\n", expectErrors); 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); 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)); 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]; return (T)md.Body.Children[0];

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

@ -35,7 +35,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast
[Test] [Test]
public void VBNetLabelStatementTest() 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); Assert.AreEqual("myLabel", labelStmt.Label);
} }
#endregion #endregion

Loading…
Cancel
Save