Skip to content

Commit

Permalink
Merge pull request #6168 from MDoerner/LineContinuationParserFix
Browse files Browse the repository at this point in the history
Make parser understand multiple line continuations inside lExpressions
  • Loading branch information
retailcoder authored Oct 21, 2023
2 parents 4d4853b + f4d1750 commit 877d0f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Rubberduck.Parsing/Grammar/VBAParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,13 @@ variantLiteralIdentifier : EMPTY | NULL;

lExpression :
lExpression LPAREN whiteSpace? argumentList? whiteSpace? RPAREN # indexExpr
| lExpression mandatoryLineContinuation? DOT mandatoryLineContinuation? printMethod (whiteSpace outputList)? # objectPrintExpr
| lExpression mandatoryLineContinuation? DOT mandatoryLineContinuation? unrestrictedIdentifier # memberAccessExpr
| lExpression mandatoryLineContinuation? dictionaryAccess mandatoryLineContinuation? unrestrictedIdentifier # dictionaryAccessExpr
| lExpression mandatoryLineContinuation* DOT mandatoryLineContinuation* printMethod (whiteSpace outputList)? # objectPrintExpr
| lExpression mandatoryLineContinuation* DOT mandatoryLineContinuation* unrestrictedIdentifier # memberAccessExpr
| lExpression mandatoryLineContinuation* dictionaryAccess mandatoryLineContinuation* unrestrictedIdentifier # dictionaryAccessExpr
| ME # instanceExpr
| identifier # simpleNameExpr
| DOT mandatoryLineContinuation? unrestrictedIdentifier # withMemberAccessExpr
| dictionaryAccess mandatoryLineContinuation? unrestrictedIdentifier # withDictionaryAccessExpr
| DOT whiteSpace? unrestrictedIdentifier # withMemberAccessExpr
| dictionaryAccess whiteSpace? unrestrictedIdentifier # withDictionaryAccessExpr
| lExpression mandatoryLineContinuation whiteSpace? LPAREN whiteSpace? argumentList? whiteSpace? RPAREN # whitespaceIndexExpr
;

Expand Down
23 changes: 23 additions & 0 deletions RubberduckTests/Grammar/VBAParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3989,6 +3989,29 @@ End Type
AssertTree(parseResult.Item1, parseResult.Item2, "//unrestrictedIdentifier", matches => matches.Count == 1);
}


// Adapted from opened issue https://github.com/rubberduck-vba/Rubberduck/issues/6164
[Test]
[TestCase(@"b _
_
. _
c")]
[TestCase(@"b _
. _
_
c")]
[TestCase(@"b _
_
. _
_
c")]
public void ParserCanDealWithMultiplyLineContinuedMemberAccess(string lineContinuedMemberAccess)
{
string code = $"Sub Test()\r\n a = {lineContinuedMemberAccess}\r\nEnd Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//lExpression", matches => matches.Count == 3);
}

// 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

0 comments on commit 877d0f6

Please sign in to comment.