From f4d1750ab9093493d252fa584f21aac5acdfe77a Mon Sep 17 00:00:00 2001 From: Max Doerner Date: Sat, 21 Oct 2023 20:03:39 +0200 Subject: [PATCH] Make parser understand multiple line continuations inside lExpressions --- Rubberduck.Parsing/Grammar/VBAParser.g4 | 10 +++++----- RubberduckTests/Grammar/VBAParserTests.cs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Rubberduck.Parsing/Grammar/VBAParser.g4 b/Rubberduck.Parsing/Grammar/VBAParser.g4 index a8d6f18e7b..9b23ff6ae1 100644 --- a/Rubberduck.Parsing/Grammar/VBAParser.g4 +++ b/Rubberduck.Parsing/Grammar/VBAParser.g4 @@ -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 ; diff --git a/RubberduckTests/Grammar/VBAParserTests.cs b/RubberduckTests/Grammar/VBAParserTests.cs index 9355082202..d24317143c 100644 --- a/RubberduckTests/Grammar/VBAParserTests.cs +++ b/RubberduckTests/Grammar/VBAParserTests.cs @@ -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")]