Browse Source

Fixed exception when parsing incomplete Select Case statement.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1314 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
254bf37011
  1. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  3. 4
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  4. 4
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  5. 18
      src/Libraries/NRefactory/Test/Parser/ParseUtilVBNet.cs
  6. 24
      src/Libraries/NRefactory/Test/Parser/Statements/SwitchStatementTests.cs

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

@ -4186,14 +4186,14 @@ out SwitchSection stmt) { @@ -4186,14 +4186,14 @@ out SwitchSection stmt) {
out label);
#line 1971 "cs.ATG"
switchSection.SwitchLabels.Add(label);
if (label != null) { switchSection.SwitchLabels.Add(label); }
while (la.kind == 54 || la.kind == 62) {
SwitchLabel(
#line 1973 "cs.ATG"
out label);
#line 1973 "cs.ATG"
switchSection.SwitchLabels.Add(label);
if (label != null) { switchSection.SwitchLabels.Add(label); }
}
#line 1975 "cs.ATG"

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -1968,9 +1968,9 @@ SwitchSection<out SwitchSection stmt> @@ -1968,9 +1968,9 @@ SwitchSection<out SwitchSection stmt>
CaseLabel label;
.)
=
SwitchLabel<out label> (. switchSection.SwitchLabels.Add(label); .)
SwitchLabel<out label> (. if (label != null) { switchSection.SwitchLabels.Add(label); } .)
{
SwitchLabel<out label> (. switchSection.SwitchLabels.Add(label); .)
SwitchLabel<out label> (. if (label != null) { switchSection.SwitchLabels.Add(label); } .)
}
(. compilationUnit.BlockStart(switchSection); .)
Statement { Statement }

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

@ -5875,7 +5875,7 @@ out List<CaseLabel> caseClauses) { @@ -5875,7 +5875,7 @@ out List<CaseLabel> caseClauses) {
out caseClause);
#line 2800 "VBNET.ATG"
caseClauses.Add(caseClause);
if (caseClause != null) { caseClauses.Add(caseClause); }
while (la.kind == 12) {
lexer.NextToken();
CaseClause(
@ -5883,7 +5883,7 @@ out caseClause); @@ -5883,7 +5883,7 @@ out caseClause);
out caseClause);
#line 2801 "VBNET.ATG"
caseClauses.Add(caseClause);
if (caseClause != null) { caseClauses.Add(caseClause); }
}
}

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

@ -2797,8 +2797,8 @@ CaseClauses<out List<CaseLabel> caseClauses> @@ -2797,8 +2797,8 @@ CaseClauses<out List<CaseLabel> caseClauses>
caseClauses = new List<CaseLabel>();
CaseLabel caseClause = null;
.) =
CaseClause<out caseClause> (. caseClauses.Add(caseClause); .)
{ "," CaseClause<out caseClause> (. caseClauses.Add(caseClause); .) }
CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .)
{ "," CaseClause<out caseClause> (. if (caseClause != null) { caseClauses.Add(caseClause); } .) }
.
/* 19.8.2 */

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

@ -37,24 +37,34 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -37,24 +37,34 @@ namespace ICSharpCode.NRefactory.Tests.AST
return (T)parser.CompilationUnit.Children[0];
}
public static T ParseTypeMember<T>(string typeMember) 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");
TypeDeclaration td = ParseGlobal<TypeDeclaration>("Class TestClass\n " + typeMember + "\n End Class\n", expectErrors);
Assert.IsTrue(td.Children.Count > 0);
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];
}
public static T ParseStatement<T>(string statement) where T : INode
public static T ParseTypeMember<T>(string typeMember) where T : INode
{
return ParseTypeMember<T>(typeMember, false);
}
public static T ParseStatement<T>(string statement, bool expectErrors) where T : INode
{
MethodDeclaration md = ParseTypeMember<MethodDeclaration>("Sub A()\n " + statement + "\nEnd Sub\n");
MethodDeclaration md = ParseTypeMember<MethodDeclaration>("Sub A()\n " + statement + "\nEnd Sub\n", expectErrors);
Assert.IsTrue(md.Body.Children.Count > 0);
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];
}
public static T ParseStatement<T>(string statement) where T : INode
{
return ParseStatement<T>(statement, false);
}
public static T ParseExpression<T>(string expr) where T : INode
{
return ParseExpression<T>(expr, false);

24
src/Libraries/NRefactory/Test/Parser/Statements/SwitchStatementTests.cs

@ -20,13 +20,29 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -20,13 +20,29 @@ namespace ICSharpCode.NRefactory.Tests.AST
[Test]
public void CSharpSwitchStatementTest()
{
SwitchStatement switchStmt = ParseUtilCSharp.ParseStatement<SwitchStatement>("switch (a) { case 5: break; case 6: break; default: break; }");
// TODO : Extend test.
SwitchStatement switchStmt = ParseUtilCSharp.ParseStatement<SwitchStatement>("switch (a) { case 4: case 5: break; case 6: break; default: break; }");
Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier);
// TODO: Extend test
}
#endregion
#region VB.NET
// TODO
#endregion
[Test]
public void VBSwitchStatementTest()
{
SwitchStatement switchStmt = ParseUtilVBNet.ParseStatement<SwitchStatement>("Select Case a\n Case 4, 5\n Case 6\n Case Else\n End Select");
Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier);
// TODO: Extend test
}
[Test]
public void InvalidVBSwitchStatementTest()
{
SwitchStatement switchStmt = ParseUtilVBNet.ParseStatement<SwitchStatement>("Select Case a\n Case \n End Select", true);
Assert.AreEqual("a", ((IdentifierExpression)switchStmt.SwitchExpression).Identifier);
SwitchSection sec = switchStmt.SwitchSections[0];
Assert.AreEqual(0, sec.SwitchLabels.Count);
}
#endregion
}
}

Loading…
Cancel
Save