Skip to content

Commit 415ae07

Browse files
authored
Merge pull request #6169 from MDoerner/OneLineIfStatementParserFix
Make the parser understand completely empty single line if statements
2 parents 3dd7ee4 + eb75069 commit 415ae07

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ elseBlock :
421421
// 5.4.2.9 Single-line If Statement
422422
singleLineIfStmt : ifWithNonEmptyThen | ifWithEmptyThen;
423423
ifWithNonEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? listOrLabel (whiteSpace singleLineElseClause)?;
424-
ifWithEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? emptyThenStatement? singleLineElseClause;
424+
ifWithEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? emptyThenStatement? singleLineElseClause?;
425425
singleLineElseClause : ELSE whiteSpace? listOrLabel?;
426426

427427
// lineNumberLabel should actually be "statement-label" according to MS VBAL but they only allow lineNumberLabels:

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,27 @@ public void ParserCanDealWithMultiplyLineContinuedMemberAccess(string lineContin
40124012
AssertTree(parseResult.Item1, parseResult.Item2, "//lExpression", matches => matches.Count == 3);
40134013
}
40144014

4015+
4016+
// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/6163
4017+
[Test]
4018+
[TestCase(@"If True Then:")]
4019+
[TestCase(@"If True Then: ")]
4020+
[TestCase(@"If True Then:
4021+
")]
4022+
[TestCase(@" If True Then::::::::::::: _
4023+
:::::::::::::::: _
4024+
:::")]
4025+
[TestCase(@" If True Then::::::::::::: _
4026+
:::::::::::::::: _
4027+
:::Else")]
4028+
public void ParserCanDealWithStatementSeparateorsInOneLineIfStatements(string oneLineIfStatement)
4029+
{
4030+
string code = $"Sub Test()\r\n {oneLineIfStatement}\r\nEnd Sub";
4031+
var parseResult = Parse(code);
4032+
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt", matches => matches.Count == 1);
4033+
}
4034+
4035+
40154036
// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/4875
40164037
[Test]
40174038
[TestCase("form.Line (0, 0)-(12, 12), RGB(255, 255, 0), B")]

0 commit comments

Comments
 (0)