Skip to content

Commit 9d5f49a

Browse files
authored
Merge pull request #4208 from MDoerner/FixMinorGrammarIssues
Fix minor grammar issues
2 parents 2699ace + b997085 commit 9d5f49a

File tree

6 files changed

+375
-46
lines changed

6 files changed

+375
-46
lines changed

Rubberduck.Parsing/Grammar/VBALexer.g4

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,14 @@ UNDERSCORE : '_';
301301
WS : [ \t];
302302
GUIDLITERAL : '{' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '-' [0-9A-F]+ '}';
303303
IDENTIFIER : ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; 0-9-/\\-] ~[[\](){}\r\n\t.,'"|!@#$%^&*\-+:=; -]*;
304-
LINE_CONTINUATION : [ \t]* UNDERSCORE [ \t]* '\r'? '\n';
304+
LINE_CONTINUATION : [ \t]+ UNDERSCORE [ \t]* '\r'? '\n' WS_NOT_FOLLOWED_BY_LINE_CONTINUATION*;
305305
// The following rule is needed in order to capture hex literals without format prefixes which start with a digit. Needed for VBForm resources.
306-
BARE_HEX_LITERAL : [0-9] [0-9a-fA-F]*;
306+
BARE_HEX_LITERAL : [0-9] [0-9a-fA-F]*;
307+
fragment WS_NOT_FOLLOWED_BY_LINE_CONTINUATION : [ \t] {(char)_input.La(1) != '_'
308+
|| ((char)_input.La(2) != '\r'
309+
&& (char)_input.La(2) != '\n'
310+
&& (char)_input.La(2) != '\t'
311+
&& (char)_input.La(2) != ' ')}?;
307312
fragment LETTER : [a-zA-Z_äöüÄÖÜ];
308313
fragment DIGIT : [0-9];
309314
fragment LETTERORDIGIT : [a-zA-Z0-9_äöüÄÖÜ];

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ complexType :
601601
fieldLength : MULT whiteSpace? (numberLiteral | identifierValue);
602602

603603
//Statement labels can only appear at the start of a line.
604-
statementLabelDefinition : {_input.La(-1) == NEWLINE}? (combinedLabels | identifierStatementLabel | standaloneLineNumberLabel);
604+
statementLabelDefinition : {_input.La(-1) == NEWLINE || _input.La(-1) == LINE_CONTINUATION}? (combinedLabels | identifierStatementLabel | standaloneLineNumberLabel);
605605
identifierStatementLabel : legalLabelIdentifier whiteSpace? COLON;
606606
standaloneLineNumberLabel :
607607
lineNumberLabel whiteSpace? COLON

Rubberduck.sln

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.RegexAssistant",
5555
EndProjectSection
5656
EndProject
5757
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.CodeAnalysis", "Rubberduck.CodeAnalysis\Rubberduck.CodeAnalysis.csproj", "{DEF2FB9D-6E62-49D6-8E26-9983AC025768}"
58+
ProjectSection(ProjectDependencies) = postProject
59+
{F83B6746-49A6-4CFD-9A29-3D7BBD4F0323} = {F83B6746-49A6-4CFD-9A29-3D7BBD4F0323}
60+
EndProjectSection
5861
EndProject
5962
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.Main", "Rubberduck.Main\Rubberduck.Main.csproj", "{E8AB5D93-2D0F-423D-BC15-5EE118673E48}"
6063
ProjectSection(ProjectDependencies) = postProject
@@ -96,10 +99,19 @@ EndProject
9699
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RubberduckTestsCodeAnalysis", "RubberduckTestsCodeAnalysis\RubberduckTestsCodeAnalysis.csproj", "{E9FC6518-F9E8-4E57-BD28-583A9EA69297}"
97100
EndProject
98101
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.Resources", "Rubberduck.Resources\Rubberduck.Resources.csproj", "{1B84B387-F7C4-4876-9BDF-C644C365359A}"
102+
ProjectSection(ProjectDependencies) = postProject
103+
{F83B6746-49A6-4CFD-9A29-3D7BBD4F0323} = {F83B6746-49A6-4CFD-9A29-3D7BBD4F0323}
104+
EndProjectSection
99105
EndProject
100106
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.Refactorings", "Rubberduck.Refactorings\Rubberduck.Refactorings.csproj", "{D4B6A510-14E1-420A-A8D5-6A09890FD7D8}"
107+
ProjectSection(ProjectDependencies) = postProject
108+
{F83B6746-49A6-4CFD-9A29-3D7BBD4F0323} = {F83B6746-49A6-4CFD-9A29-3D7BBD4F0323}
109+
EndProjectSection
101110
EndProject
102111
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rubberduck.Interaction", "Rubberduck.Interaction\Rubberduck.Interaction.csproj", "{AC54B7FB-170D-4DA6-A30B-8CAD182F0E6B}"
112+
ProjectSection(ProjectDependencies) = postProject
113+
{F83B6746-49A6-4CFD-9A29-3D7BBD4F0323} = {F83B6746-49A6-4CFD-9A29-3D7BBD4F0323}
114+
EndProjectSection
103115
EndProject
104116
Global
105117
GlobalSection(SolutionConfigurationPlatforms) = preSolution

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 286 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public void TestTrivialCase()
550550
public void TestEmptyModule()
551551
{
552552
string code = @"
553-
_
553+
_
554554
555555
_
556556
@@ -1748,7 +1748,7 @@ For Each d In bar
17481748
a = m + n + c + d
17491749
For k = 0 To 100
17501750
t = a + k
1751-
Next k, d, m,_
1751+
Next k, d, m, _
17521752
c, _
17531753
n
17541754
End Sub";
@@ -2813,6 +2813,290 @@ End Sub
28132813
AssertTree(parseResult.Item1, parseResult.Item2, "//argumentList", matches => matches.Count == 2);
28142814
}
28152815

2816+
[Category("Parser")]
2817+
[Test]
2818+
public void ParserDoesNotFailOnUnderscoreComment()
2819+
{
2820+
const string code = @"
2821+
Sub Test()
2822+
'_
2823+
If True Then
2824+
End If
2825+
End Sub
2826+
";
2827+
var parseResult = Parse(code);
2828+
AssertTree(parseResult.Item1, parseResult.Item2, "//ifStmt", matches => matches.Count == 1);
2829+
}
2830+
2831+
[Category("Parser")]
2832+
[Test]
2833+
public void ParserDoesNotFailOnUnderscoreAfterNonBreakingSpaceInComment()
2834+
{
2835+
const string code = @"
2836+
Sub Test()
2837+
'" + "\u00A0" + @"_
2838+
If True Then
2839+
End If
2840+
End Sub
2841+
";
2842+
var parseResult = Parse(code);
2843+
AssertTree(parseResult.Item1, parseResult.Item2, "//ifStmt", matches => matches.Count == 1);
2844+
}
2845+
2846+
[Category("Parser")]
2847+
[Test]
2848+
public void ParserDoesNotFailOnStartOfLineUnderscoreInLineContinuedComment()
2849+
{
2850+
const string code = @"
2851+
Sub Test()
2852+
' _
2853+
_
2854+
If True Then
2855+
End If
2856+
End Sub
2857+
";
2858+
var parseResult = Parse(code);
2859+
AssertTree(parseResult.Item1, parseResult.Item2, "//ifStmt", matches => matches.Count == 1);
2860+
}
2861+
2862+
[Category("Parser")]
2863+
[Test]
2864+
public void ParserDoesNotFailOnLineContinuedMemberAccessExpressionInType1()
2865+
{
2866+
const string code = @"
2867+
Sub Test()
2868+
Dim dic2 As _
2869+
Scripting _
2870+
. _
2871+
Dictionary
2872+
End Sub
2873+
";
2874+
var parseResult = Parse(code);
2875+
}
2876+
2877+
[Category("Parser")]
2878+
[Test]
2879+
public void ParserDoesNotFailOnLineContinuedMemberAccessExpressionInType2()
2880+
{
2881+
const string code = @"
2882+
Sub Test()
2883+
Dim dic3 As Scripting _
2884+
. _
2885+
Dictionary
2886+
End Sub
2887+
";
2888+
var parseResult = Parse(code);
2889+
}
2890+
2891+
[Category("Parser")]
2892+
[Test]
2893+
public void ParserDoesNotFailOnLineContinuedMemberAccessExpressionOnObject1()
2894+
{
2895+
const string code = @"
2896+
Sub Test()
2897+
Dim dict As Scripting.Dictionary
2898+
2899+
Debug.Print dict. _
2900+
Item(""a"")
2901+
End Sub
2902+
";
2903+
var parseResult = Parse(code);
2904+
}
2905+
2906+
[Category("Parser")]
2907+
[Test]
2908+
public void ParserDoesNotFailOnLineContinuedMemberAccessExpressionOnObject2()
2909+
{
2910+
const string code = @"
2911+
Sub Test()
2912+
Dim dict As Scripting.Dictionary
2913+
2914+
Debug.Print dict _
2915+
. _
2916+
Item(""a"")
2917+
End Sub
2918+
";
2919+
var parseResult = Parse(code);
2920+
}
2921+
2922+
[Category("Parser")]
2923+
[Test]
2924+
public void ParserDoesNotFailOnLineContinuedMemberAccessExpressionOnObject3()
2925+
{
2926+
const string code = @"
2927+
Sub Test()
2928+
Dim dict As Scripting.Dictionary
2929+
2930+
Debug.Print dict _
2931+
. _
2932+
Item(""a"")
2933+
End Sub
2934+
";
2935+
var parseResult = Parse(code);
2936+
}
2937+
2938+
[Category("Parser")]
2939+
[Test]
2940+
public void ParserDoesNotFailOnLineContinuedBangOperator1()
2941+
{
2942+
const string code = @"
2943+
Sub Test()
2944+
Dim dict As Scripting.Dictionary
2945+
2946+
Dim x
2947+
x = dict _
2948+
! _
2949+
a
2950+
End Sub
2951+
";
2952+
var parseResult = Parse(code);
2953+
}
2954+
2955+
[Category("Parser")]
2956+
[Test]
2957+
public void ParserDoesNotFailOnLineContinuedBangOperator2()
2958+
{
2959+
const string code = @"
2960+
Sub Test()
2961+
Dim dict As Scripting.Dictionary
2962+
2963+
Dim x
2964+
x = dict _
2965+
! _
2966+
a
2967+
2968+
End Sub
2969+
";
2970+
var parseResult = Parse(code);
2971+
}
2972+
2973+
[Category("Parser")]
2974+
[Test]
2975+
public void ParserDoesNotFailOnLineContinuedBangOperator3()
2976+
{
2977+
const string code = @"
2978+
Sub Test()
2979+
Dim dict As Scripting.Dictionary
2980+
2981+
Dim x
2982+
x = dict _
2983+
!a
2984+
End Sub
2985+
";
2986+
var parseResult = Parse(code);
2987+
}
2988+
2989+
[Category("Parser")]
2990+
[Test]
2991+
public void ParserDoesNotFailOnLineContinuedTypeDeclaration()
2992+
{
2993+
const string code = @"
2994+
Sub Test()
2995+
Dim dic1 As _
2996+
Dictionary
2997+
End Sub
2998+
";
2999+
var parseResult = Parse(code);
3000+
}
3001+
3002+
[Category("Parser")]
3003+
[Test]
3004+
public void ParserDoesNotFailOnIdentifierEndingInUnderscore()
3005+
{
3006+
const string code = @"
3007+
Sub Test()
3008+
Dim dict As Scripting.Dictionary
3009+
3010+
Dim x_
3011+
End Sub
3012+
";
3013+
var parseResult = Parse(code);
3014+
}
3015+
3016+
[Category("Parser")]
3017+
[Test]
3018+
public void ParserDoesNotFailOnLineNumberNotOnStartOfLineAfterALineContinuation()
3019+
{
3020+
const string code = @"
3021+
Sub foo()
3022+
_
3023+
10
3024+
_
3025+
Beep
3026+
End Sub
3027+
";
3028+
var parseResult = Parse(code);
3029+
AssertTree(parseResult.Item1, parseResult.Item2, "//standaloneLineNumberLabel", matches => matches.Count == 1);
3030+
}
3031+
3032+
[Category("Parser")]
3033+
[Test]
3034+
public void ParserDoesNotFailOnLineLAbelNotOnStartOfLineAfterALineContinuation()
3035+
{
3036+
const string code = @"
3037+
Sub foo()
3038+
_
3039+
foo: Beep
3040+
End Sub
3041+
";
3042+
var parseResult = Parse(code);
3043+
AssertTree(parseResult.Item1, parseResult.Item2, "//identifierStatementLabel", matches => matches.Count == 1);
3044+
}
3045+
3046+
[Category("Parser")]
3047+
[Test]
3048+
public void ParserDoesNotFailOnLinecontinuedLabel()
3049+
{
3050+
const string code = @"
3051+
Sub foo()
3052+
foo _
3053+
: Beep
3054+
End Sub
3055+
";
3056+
var parseResult = Parse(code);
3057+
AssertTree(parseResult.Item1, parseResult.Item2, "//identifierStatementLabel", matches => matches.Count == 1);
3058+
}
3059+
3060+
[Category("Parser")]
3061+
[Test]
3062+
public void ParserDoesNotFailOnLineNumberAndLineContinuedLabelNotOnStartOfLineAfterALineContinuation()
3063+
{
3064+
const string code = @"
3065+
Sub foo()
3066+
_
3067+
10
3068+
_
3069+
foo _
3070+
: Beeb
3071+
End Sub
3072+
";
3073+
var parseResult = Parse(code);
3074+
AssertTree(parseResult.Item1, parseResult.Item2, "//standaloneLineNumberLabel", matches => matches.Count == 1);
3075+
AssertTree(parseResult.Item1, parseResult.Item2, "//identifierStatementLabel", matches => matches.Count == 1);
3076+
}
3077+
3078+
[Category("Parser")]
3079+
[Test]
3080+
public void ParserDoesNotFailOnLineNumberAndLineContinuedLabelNotOnStartOfLineAfterMultipleLineContinuation()
3081+
{
3082+
const string code = @"
3083+
Sub foo()
3084+
_
3085+
_
3086+
_
3087+
10
3088+
_
3089+
_
3090+
_
3091+
foo _
3092+
: Beeb
3093+
End Sub
3094+
";
3095+
var parseResult = Parse(code);
3096+
AssertTree(parseResult.Item1, parseResult.Item2, "//standaloneLineNumberLabel", matches => matches.Count == 1);
3097+
AssertTree(parseResult.Item1, parseResult.Item2, "//identifierStatementLabel", matches => matches.Count == 1);
3098+
}
3099+
28163100
[Category("Parser")]
28173101
[Test]
28183102
public void LeftOutOptionalArgumentsAreCountedAsMissingArguments()

RubberduckTests/QuickFixes/AssignedByValParameterMakeLocalCopyQuickFixTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ End Property
145145
public void AssignedByValParameter_LocalVariableAssignment_ComplexFormat()
146146
{
147147
var inputCode =
148-
@"Sub DoSomething(_
148+
@"Sub DoSomething( _
149149
ByVal foo As Long, _
150150
ByRef _
151151
bar, _
@@ -157,7 +157,7 @@ ByRef barbecue _
157157
End Sub
158158
";
159159
var expectedCode =
160-
@"Sub DoSomething(_
160+
@"Sub DoSomething( _
161161
ByVal foo As Long, _
162162
ByRef _
163163
bar, _

0 commit comments

Comments
 (0)