Skip to content

Commit 877d0f6

Browse files
authored
Merge pull request #6168 from MDoerner/LineContinuationParserFix
Make parser understand multiple line continuations inside lExpressions
2 parents 4d4853b + f4d1750 commit 877d0f6

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,13 @@ variantLiteralIdentifier : EMPTY | NULL;
687687

688688
lExpression :
689689
lExpression LPAREN whiteSpace? argumentList? whiteSpace? RPAREN # indexExpr
690-
| lExpression mandatoryLineContinuation? DOT mandatoryLineContinuation? printMethod (whiteSpace outputList)? # objectPrintExpr
691-
| lExpression mandatoryLineContinuation? DOT mandatoryLineContinuation? unrestrictedIdentifier # memberAccessExpr
692-
| lExpression mandatoryLineContinuation? dictionaryAccess mandatoryLineContinuation? unrestrictedIdentifier # dictionaryAccessExpr
690+
| lExpression mandatoryLineContinuation* DOT mandatoryLineContinuation* printMethod (whiteSpace outputList)? # objectPrintExpr
691+
| lExpression mandatoryLineContinuation* DOT mandatoryLineContinuation* unrestrictedIdentifier # memberAccessExpr
692+
| lExpression mandatoryLineContinuation* dictionaryAccess mandatoryLineContinuation* unrestrictedIdentifier # dictionaryAccessExpr
693693
| ME # instanceExpr
694694
| identifier # simpleNameExpr
695-
| DOT mandatoryLineContinuation? unrestrictedIdentifier # withMemberAccessExpr
696-
| dictionaryAccess mandatoryLineContinuation? unrestrictedIdentifier # withDictionaryAccessExpr
695+
| DOT whiteSpace? unrestrictedIdentifier # withMemberAccessExpr
696+
| dictionaryAccess whiteSpace? unrestrictedIdentifier # withDictionaryAccessExpr
697697
| lExpression mandatoryLineContinuation whiteSpace? LPAREN whiteSpace? argumentList? whiteSpace? RPAREN # whitespaceIndexExpr
698698
;
699699

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3989,6 +3989,29 @@ End Type
39893989
AssertTree(parseResult.Item1, parseResult.Item2, "//unrestrictedIdentifier", matches => matches.Count == 1);
39903990
}
39913991

3992+
3993+
// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/6164
3994+
[Test]
3995+
[TestCase(@"b _
3996+
_
3997+
. _
3998+
c")]
3999+
[TestCase(@"b _
4000+
. _
4001+
_
4002+
c")]
4003+
[TestCase(@"b _
4004+
_
4005+
. _
4006+
_
4007+
c")]
4008+
public void ParserCanDealWithMultiplyLineContinuedMemberAccess(string lineContinuedMemberAccess)
4009+
{
4010+
string code = $"Sub Test()\r\n a = {lineContinuedMemberAccess}\r\nEnd Sub";
4011+
var parseResult = Parse(code);
4012+
AssertTree(parseResult.Item1, parseResult.Item2, "//lExpression", matches => matches.Count == 3);
4013+
}
4014+
39924015
// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/4875
39934016
[Test]
39944017
[TestCase("form.Line (0, 0)-(12, 12), RGB(255, 255, 0), B")]

0 commit comments

Comments
 (0)