Skip to content

Commit bbc0b37

Browse files
committed
Enforce ending NEWLINE on commentBody
This requires an additional modification to endOfStatement to keep consuming any "leading" whitespace for the following statement. Fixes #3789
1 parent 4ebeece commit bbc0b37

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,9 @@ endOfLine :
864864
| whiteSpace? commentOrAnnotation
865865
;
866866

867+
// we expect endOfStatement to consume all trailing whitespace
867868
endOfStatement :
868-
(endOfLine | (whiteSpace? COLON whiteSpace?))+
869+
(endOfLine whiteSpace? | (whiteSpace? COLON whiteSpace?))+
869870
| whiteSpace? EOF
870871
;
871872

@@ -877,7 +878,8 @@ commentOrAnnotation :
877878
;
878879
remComment : REM whiteSpace? commentBody;
879880
comment : SINGLEQUOTE commentBody;
880-
commentBody : (LINE_CONTINUATION | ~NEWLINE)*;
881+
// commentBody must terminate with a NEWLINE, see VBA Language spec, section 3.3.1 and 3789
882+
commentBody : (LINE_CONTINUATION | ~NEWLINE)* (NEWLINE | EOF);
881883
annotationList : SINGLEQUOTE (AT annotation whiteSpace?)+ (whiteSpace? COLON commentBody)?;
882884
annotation : annotationName annotationArgList?;
883885
annotationName : unrestrictedIdentifier;

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ public void TestModuleConfig()
440440
[Test]
441441
public void TestEmptyComment()
442442
{
443-
string code = @"'";
443+
string code = @"'
444+
";
444445
var parseResult = Parse(code);
445446
AssertTree(parseResult.Item1, parseResult.Item2, "//comment");
446447
}
@@ -449,7 +450,8 @@ public void TestEmptyComment()
449450
[Test]
450451
public void TestEmptyRemComment()
451452
{
452-
string code = @"Rem";
453+
string code = @"Rem
454+
";
453455
var parseResult = Parse(code);
454456
AssertTree(parseResult.Item1, parseResult.Item2, "//remComment");
455457
}
@@ -458,7 +460,8 @@ public void TestEmptyRemComment()
458460
[Test]
459461
public void TestOneCharRemComment()
460462
{
461-
string code = @"Rem a";
463+
string code = @"Rem a
464+
";
462465
var parseResult = Parse(code);
463466
AssertTree(parseResult.Item1, parseResult.Item2, "//remComment");
464467
}
@@ -467,7 +470,8 @@ public void TestOneCharRemComment()
467470
[Test]
468471
public void TestCommentThatLooksLikeAnnotation()
469472
{
470-
string code = @"'@param foo; the value of something";
473+
string code = @"'@param foo; the value of something
474+
";
471475
var parseResult = Parse(code);
472476
AssertTree(parseResult.Item1, parseResult.Item2, "//comment");
473477
}
@@ -496,7 +500,8 @@ Sub FooFoo()
496500
[Test]
497501
public void TestOneCharComment()
498502
{
499-
string code = @"'a";
503+
string code = @"'a
504+
";
500505
var parseResult = Parse(code);
501506
AssertTree(parseResult.Item1, parseResult.Item2, "//comment");
502507
}

0 commit comments

Comments
 (0)