Browse Source

Fixed forum-10660: make EndOfStatement between "Else" and the following block optional. It isn't according to the VB spec, but the MS VB compiler allows such code.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5445 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
6a8bf3b680
  1. 4
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 2
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 13
      src/Libraries/NRefactory/Test/Parser/Statements/IfElseStatementTests.cs

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

@ -6313,7 +6313,9 @@ out block); @@ -6313,7 +6313,9 @@ out block);
}
if (la.kind == 98) {
lexer.NextToken();
EndOfStmt();
if (la.kind == 1 || la.kind == 11) {
EndOfStmt();
}
Block(
#line 2955 "VBNET.ATG"
out embeddedStatement);

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

@ -2951,7 +2951,7 @@ EmbeddedStatement<out Statement statement> @@ -2951,7 +2951,7 @@ EmbeddedStatement<out Statement statement>
.)
}
[
"Else" EndOfStmt
"Else" [EndOfStmt]
Block<out embeddedStatement>
(.
ifStatement.FalseStatement.Add(embeddedStatement);

13
src/Libraries/NRefactory/Test/Parser/Statements/IfElseStatementTests.cs

@ -171,6 +171,19 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -171,6 +171,19 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(2, ifElseStatement.TrueStatement.Count, "true count");
Assert.AreEqual(0, ifElseStatement.FalseStatement.Count, "false count");
}
[Test]
public void VBNetIfWithSingleLineElse()
{
// This isn't legal according to the VB spec, but the MS VB compiler seems to allow it.
IfElseStatement ifElseStatement = ParseUtilVBNet.ParseStatement<IfElseStatement>("If True THEN\n" +
" x()\n" +
"Else y()\n" +
"End If");
Assert.IsFalse(ifElseStatement.Condition.IsNull);
Assert.AreEqual(1, ifElseStatement.TrueStatement.Count, "true count");
Assert.AreEqual(1, ifElseStatement.FalseStatement.Count, "false count");
}
#endregion
}
}

Loading…
Cancel
Save