Skip to content

Commit 26f4cb6

Browse files
authored
Merge pull request #3768 from MDoerner/FixSLLModeForArrayDeclarations
Fix SLL parser prediction mode for array declarations with extraneous whitespace.
2 parents aa89113 + 5f3afc3 commit 26f4cb6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ constantExpression : expression;
520520

521521
variableStmt : (DIM | STATIC | visibility) whiteSpace (WITHEVENTS whiteSpace)? variableListStmt;
522522
variableListStmt : variableSubStmt (whiteSpace? COMMA whiteSpace? variableSubStmt)*;
523-
variableSubStmt : identifier (whiteSpace? LPAREN whiteSpace? (subscripts whiteSpace?)? RPAREN whiteSpace?)? (whiteSpace asTypeClause)?;
523+
variableSubStmt : identifier (whiteSpace? LPAREN whiteSpace? (subscripts whiteSpace?)? RPAREN)? (whiteSpace asTypeClause)?;
524524

525525
whileWendStmt :
526526
WHILE whiteSpace expression endOfStatement

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,31 @@ End Sub
21552155
AssertTree(parseResult.Item1, parseResult.Item2, "//universalLetterRange", matches => matches.Count == 0);
21562156
}
21572157

2158+
[Category("Parser")]
2159+
[Test]
2160+
public void SLLParserDoesNotThrowForArrayDefinitionInModuleWithMultipleSpacesInFromtOfAsType()
2161+
{
2162+
const string code = @"
2163+
Dim Foo1(0 To 3) As Long
2164+
2165+
";
2166+
var parseResult = Parse(code);
2167+
AssertTree(parseResult.Item1, parseResult.Item2, "//variableSubStmt", matches => matches.Count == 1);
2168+
}
2169+
2170+
[Category("Parser")]
2171+
[Test]
2172+
public void SLLParserDoesNotThrowForArrayDefinitionInSubWithMultipleSpacesInFromtOfAsType()
2173+
{
2174+
const string code = @"
2175+
Sub Test()
2176+
Dim Foo2(0 To 3) As Long
2177+
End Sub
2178+
";
2179+
var parseResult = Parse(code);
2180+
AssertTree(parseResult.Item1, parseResult.Item2, "//variableSubStmt", matches => matches.Count == 1);
2181+
}
2182+
21582183
private Tuple<VBAParser, ParserRuleContext> Parse(string code, PredictionMode predictionMode = null)
21592184
{
21602185
var stream = new AntlrInputStream(code);

0 commit comments

Comments
 (0)