Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the parser understand completely empty single line if statements #6169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 : ELSE whiteSpace? listOrLabel?;

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


// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/6163
[Test]
[TestCase(@"If True Then:")]
[TestCase(@"If True Then: ")]
[TestCase(@"If True Then:
")]
[TestCase(@" If True Then::::::::::::: _
:::::::::::::::: _
:::")]
[TestCase(@" If True Then::::::::::::: _
:::::::::::::::: _
:::Else")]
public void ParserCanDealWithStatementSeparateorsInOneLineIfStatements(string oneLineIfStatement)
{
string code = $"Sub Test()\r\n {oneLineIfStatement}\r\nEnd 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]
[TestCase("form.Line (0, 0)-(12, 12), RGB(255, 255, 0), B")]
Expand Down