Skip to content

Commit

Permalink
Fix for rubberduck-vba#6187, single line if must have something after…
Browse files Browse the repository at this point in the history
… the Then
  • Loading branch information
tommy9 committed Jan 27, 2024
1 parent 22b5a72 commit 617f16c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/Grammar/VBAParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ elseBlock :
// 5.4.2.9 Single-line If Statement
singleLineIfStmt : ifWithNonEmptyThen | ifWithEmptyThen;
ifWithNonEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? listOrLabel (whiteSpace singleLineElseClause)?;
ifWithEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? emptyThenStatement? singleLineElseClause?;
ifWithEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? (emptyThenStatement singleLineElseClause? | singleLineElseClause);
singleLineElseClause : ELSE whiteSpace? listOrLabel?;

// lineNumberLabel should actually be "statement-label" according to MS VBAL but they only allow lineNumberLabels:
Expand Down
14 changes: 14 additions & 0 deletions RubberduckTests/Grammar/VBAParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4032,6 +4032,20 @@ public void ParserCanDealWithStatementSeparateorsInOneLineIfStatements(string on
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt", matches => matches.Count == 1);
}

// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/6187
[Test]
public void OneLineIfStatementNotMistakenForIfStatement()
{
string code = @"
Sub Test()
If True Then: A = 1
If False Then
A = 5
End If
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt", matches => matches.Count == 1);
}

// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/4875
[Test]
Expand Down

0 comments on commit 617f16c

Please sign in to comment.