Skip to content

Commit 5d49b4e

Browse files
authored
Merge pull request #1932 from Hosch250/Issue1917
Fix grammar to support line continuations inside a date literal, to match VBE's clunkiness
2 parents 3796552 + d6037af commit 5d49b4e

12 files changed

+2097
-2203
lines changed

Rubberduck.Parsing/Grammar/VBALexer.cs

Lines changed: 218 additions & 214 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Grammar/VBALexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fragment EXPONENT : EXPONENTLETTER EXPONENTSIGN? DIGIT+;
259259
fragment EXPONENTLETTER : [DEde];
260260
fragment EXPONENTSIGN : [+-];
261261
fragment DECIMALLITERAL : DIGIT+;
262-
DATELITERAL : '#' DATEORTIME '#';
262+
DATELITERAL : HASH ((WS | LINE_CONTINUATION)+)? DATEORTIME HASH;
263263
fragment DATEORTIME : DATEVALUE WS? TIMEVALUE | DATEVALUE | TIMEVALUE;
264264
fragment DATEVALUE : DATEVALUEPART DATESEPARATOR DATEVALUEPART (DATESEPARATOR DATEVALUEPART)?;
265265
fragment DATEVALUEPART : DIGIT+ | MONTHNAME;

Rubberduck.Parsing/Preprocessing/DateLiteralExpression.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Rubberduck.Parsing.Date;
2-
using Rubberduck.Parsing.VBA;
1+
using Rubberduck.Parsing.VBA;
32
using System;
43
using System.Globalization;
54

Rubberduck.Parsing/Preprocessing/VBADate.g4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ grammar VBADate;
22

33
compilationUnit : dateLiteral EOF;
44

5-
dateLiteral : HASH dateOrTime HASH;
5+
dateLiteral : HASH ((WS | LINE_CONTINUATION)+)? dateOrTime HASH;
66
dateOrTime :
77
dateValue
88
| timeValue
@@ -20,6 +20,8 @@ timeValuePart : DIGIT+;
2020
timeSeparator : WS* (COLON | DOT) WS*;
2121
AMPM : AM | PM | A | P;
2222

23+
LINE_CONTINUATION : [ \t]* '_' [ \t]* '\r'? '\n';
24+
2325
JANUARY : J A N U A R Y;
2426
FEBRUARY : F E B R U A R Y;
2527
MARCH : M A R C H;

Rubberduck.Parsing/Preprocessing/VBADateBaseListener.cs

Lines changed: 200 additions & 202 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Preprocessing/VBADateBaseVisitor.cs

Lines changed: 160 additions & 162 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Preprocessing/VBADateLexer.cs

Lines changed: 180 additions & 172 deletions
Large diffs are not rendered by default.

Rubberduck.Parsing/Preprocessing/VBADateListener.cs

Lines changed: 157 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

11-
// Generated from C:\Users\Splinter\Documents\Visual Studio 2015\Projects\TestProj\TestProj\VBADate.g4 by ANTLR 4.3
11+
// Generated from C:\Users\hosch\Documents\Visual Studio 2015\Projects\Rubberduck\Rubberduck.Parsing\Preprocessing\VBADate.g4 by ANTLR 4.3
1212

1313
// Unreachable code detected
1414
#pragma warning disable 0162
@@ -17,161 +17,159 @@
1717
// Missing XML comment for publicly visible type or member '...'
1818
#pragma warning disable 1591
1919

20-
namespace Rubberduck.Parsing.Date
21-
{
22-
using Antlr4.Runtime.Misc;
23-
using IParseTreeListener = Antlr4.Runtime.Tree.IParseTreeListener;
24-
using IToken = Antlr4.Runtime.IToken;
25-
26-
/// <summary>
27-
/// This interface defines a complete listener for a parse tree produced by
28-
/// <see cref="VBADateParser"/>.
29-
/// </summary>
30-
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.3")]
31-
[System.CLSCompliant(false)]
32-
public interface IVBADateListener : IParseTreeListener
33-
{
34-
/// <summary>
35-
/// Enter a parse tree produced by <see cref="VBADateParser.dateValue"/>.
36-
/// </summary>
37-
/// <param name="context">The parse tree.</param>
38-
void EnterDateValue([NotNull] VBADateParser.DateValueContext context);
39-
/// <summary>
40-
/// Exit a parse tree produced by <see cref="VBADateParser.dateValue"/>.
41-
/// </summary>
42-
/// <param name="context">The parse tree.</param>
43-
void ExitDateValue([NotNull] VBADateParser.DateValueContext context);
44-
45-
/// <summary>
46-
/// Enter a parse tree produced by <see cref="VBADateParser.dateSeparator"/>.
47-
/// </summary>
48-
/// <param name="context">The parse tree.</param>
49-
void EnterDateSeparator([NotNull] VBADateParser.DateSeparatorContext context);
50-
/// <summary>
51-
/// Exit a parse tree produced by <see cref="VBADateParser.dateSeparator"/>.
52-
/// </summary>
53-
/// <param name="context">The parse tree.</param>
54-
void ExitDateSeparator([NotNull] VBADateParser.DateSeparatorContext context);
55-
56-
/// <summary>
57-
/// Enter a parse tree produced by <see cref="VBADateParser.englishMonthAbbreviation"/>.
58-
/// </summary>
59-
/// <param name="context">The parse tree.</param>
60-
void EnterEnglishMonthAbbreviation([NotNull] VBADateParser.EnglishMonthAbbreviationContext context);
61-
/// <summary>
62-
/// Exit a parse tree produced by <see cref="VBADateParser.englishMonthAbbreviation"/>.
63-
/// </summary>
64-
/// <param name="context">The parse tree.</param>
65-
void ExitEnglishMonthAbbreviation([NotNull] VBADateParser.EnglishMonthAbbreviationContext context);
66-
67-
/// <summary>
68-
/// Enter a parse tree produced by <see cref="VBADateParser.dateOrTime"/>.
69-
/// </summary>
70-
/// <param name="context">The parse tree.</param>
71-
void EnterDateOrTime([NotNull] VBADateParser.DateOrTimeContext context);
72-
/// <summary>
73-
/// Exit a parse tree produced by <see cref="VBADateParser.dateOrTime"/>.
74-
/// </summary>
75-
/// <param name="context">The parse tree.</param>
76-
void ExitDateOrTime([NotNull] VBADateParser.DateOrTimeContext context);
77-
78-
/// <summary>
79-
/// Enter a parse tree produced by <see cref="VBADateParser.englishMonthName"/>.
80-
/// </summary>
81-
/// <param name="context">The parse tree.</param>
82-
void EnterEnglishMonthName([NotNull] VBADateParser.EnglishMonthNameContext context);
83-
/// <summary>
84-
/// Exit a parse tree produced by <see cref="VBADateParser.englishMonthName"/>.
85-
/// </summary>
86-
/// <param name="context">The parse tree.</param>
87-
void ExitEnglishMonthName([NotNull] VBADateParser.EnglishMonthNameContext context);
88-
89-
/// <summary>
90-
/// Enter a parse tree produced by <see cref="VBADateParser.monthName"/>.
91-
/// </summary>
92-
/// <param name="context">The parse tree.</param>
93-
void EnterMonthName([NotNull] VBADateParser.MonthNameContext context);
94-
/// <summary>
95-
/// Exit a parse tree produced by <see cref="VBADateParser.monthName"/>.
96-
/// </summary>
97-
/// <param name="context">The parse tree.</param>
98-
void ExitMonthName([NotNull] VBADateParser.MonthNameContext context);
99-
100-
/// <summary>
101-
/// Enter a parse tree produced by <see cref="VBADateParser.timeSeparator"/>.
102-
/// </summary>
103-
/// <param name="context">The parse tree.</param>
104-
void EnterTimeSeparator([NotNull] VBADateParser.TimeSeparatorContext context);
105-
/// <summary>
106-
/// Exit a parse tree produced by <see cref="VBADateParser.timeSeparator"/>.
107-
/// </summary>
108-
/// <param name="context">The parse tree.</param>
109-
void ExitTimeSeparator([NotNull] VBADateParser.TimeSeparatorContext context);
110-
111-
/// <summary>
112-
/// Enter a parse tree produced by <see cref="VBADateParser.timeValue"/>.
113-
/// </summary>
114-
/// <param name="context">The parse tree.</param>
115-
void EnterTimeValue([NotNull] VBADateParser.TimeValueContext context);
116-
/// <summary>
117-
/// Exit a parse tree produced by <see cref="VBADateParser.timeValue"/>.
118-
/// </summary>
119-
/// <param name="context">The parse tree.</param>
120-
void ExitTimeValue([NotNull] VBADateParser.TimeValueContext context);
121-
122-
/// <summary>
123-
/// Enter a parse tree produced by <see cref="VBADateParser.compilationUnit"/>.
124-
/// </summary>
125-
/// <param name="context">The parse tree.</param>
126-
void EnterCompilationUnit([NotNull] VBADateParser.CompilationUnitContext context);
127-
/// <summary>
128-
/// Exit a parse tree produced by <see cref="VBADateParser.compilationUnit"/>.
129-
/// </summary>
130-
/// <param name="context">The parse tree.</param>
131-
void ExitCompilationUnit([NotNull] VBADateParser.CompilationUnitContext context);
132-
133-
/// <summary>
134-
/// Enter a parse tree produced by <see cref="VBADateParser.dateValuePart"/>.
135-
/// </summary>
136-
/// <param name="context">The parse tree.</param>
137-
void EnterDateValuePart([NotNull] VBADateParser.DateValuePartContext context);
138-
/// <summary>
139-
/// Exit a parse tree produced by <see cref="VBADateParser.dateValuePart"/>.
140-
/// </summary>
141-
/// <param name="context">The parse tree.</param>
142-
void ExitDateValuePart([NotNull] VBADateParser.DateValuePartContext context);
143-
144-
/// <summary>
145-
/// Enter a parse tree produced by <see cref="VBADateParser.timeValuePart"/>.
146-
/// </summary>
147-
/// <param name="context">The parse tree.</param>
148-
void EnterTimeValuePart([NotNull] VBADateParser.TimeValuePartContext context);
149-
/// <summary>
150-
/// Exit a parse tree produced by <see cref="VBADateParser.timeValuePart"/>.
151-
/// </summary>
152-
/// <param name="context">The parse tree.</param>
153-
void ExitTimeValuePart([NotNull] VBADateParser.TimeValuePartContext context);
154-
155-
/// <summary>
156-
/// Enter a parse tree produced by <see cref="VBADateParser.dateLiteral"/>.
157-
/// </summary>
158-
/// <param name="context">The parse tree.</param>
159-
void EnterDateLiteral([NotNull] VBADateParser.DateLiteralContext context);
160-
/// <summary>
161-
/// Exit a parse tree produced by <see cref="VBADateParser.dateLiteral"/>.
162-
/// </summary>
163-
/// <param name="context">The parse tree.</param>
164-
void ExitDateLiteral([NotNull] VBADateParser.DateLiteralContext context);
165-
166-
/// <summary>
167-
/// Enter a parse tree produced by <see cref="VBADateParser.dateValueNumber"/>.
168-
/// </summary>
169-
/// <param name="context">The parse tree.</param>
170-
void EnterDateValueNumber([NotNull] VBADateParser.DateValueNumberContext context);
171-
/// <summary>
172-
/// Exit a parse tree produced by <see cref="VBADateParser.dateValueNumber"/>.
173-
/// </summary>
174-
/// <param name="context">The parse tree.</param>
175-
void ExitDateValueNumber([NotNull] VBADateParser.DateValueNumberContext context);
176-
}
177-
} // namespace Rubberduck.Parsing.Date
20+
namespace Rubberduck.Parsing {
21+
using Antlr4.Runtime.Misc;
22+
using IParseTreeListener = Antlr4.Runtime.Tree.IParseTreeListener;
23+
using IToken = Antlr4.Runtime.IToken;
24+
25+
/// <summary>
26+
/// This interface defines a complete listener for a parse tree produced by
27+
/// <see cref="VBADateParser"/>.
28+
/// </summary>
29+
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.3")]
30+
[System.CLSCompliant(false)]
31+
public interface IVBADateListener : IParseTreeListener {
32+
/// <summary>
33+
/// Enter a parse tree produced by <see cref="VBADateParser.dateValue"/>.
34+
/// </summary>
35+
/// <param name="context">The parse tree.</param>
36+
void EnterDateValue([NotNull] VBADateParser.DateValueContext context);
37+
/// <summary>
38+
/// Exit a parse tree produced by <see cref="VBADateParser.dateValue"/>.
39+
/// </summary>
40+
/// <param name="context">The parse tree.</param>
41+
void ExitDateValue([NotNull] VBADateParser.DateValueContext context);
42+
43+
/// <summary>
44+
/// Enter a parse tree produced by <see cref="VBADateParser.dateSeparator"/>.
45+
/// </summary>
46+
/// <param name="context">The parse tree.</param>
47+
void EnterDateSeparator([NotNull] VBADateParser.DateSeparatorContext context);
48+
/// <summary>
49+
/// Exit a parse tree produced by <see cref="VBADateParser.dateSeparator"/>.
50+
/// </summary>
51+
/// <param name="context">The parse tree.</param>
52+
void ExitDateSeparator([NotNull] VBADateParser.DateSeparatorContext context);
53+
54+
/// <summary>
55+
/// Enter a parse tree produced by <see cref="VBADateParser.englishMonthAbbreviation"/>.
56+
/// </summary>
57+
/// <param name="context">The parse tree.</param>
58+
void EnterEnglishMonthAbbreviation([NotNull] VBADateParser.EnglishMonthAbbreviationContext context);
59+
/// <summary>
60+
/// Exit a parse tree produced by <see cref="VBADateParser.englishMonthAbbreviation"/>.
61+
/// </summary>
62+
/// <param name="context">The parse tree.</param>
63+
void ExitEnglishMonthAbbreviation([NotNull] VBADateParser.EnglishMonthAbbreviationContext context);
64+
65+
/// <summary>
66+
/// Enter a parse tree produced by <see cref="VBADateParser.dateOrTime"/>.
67+
/// </summary>
68+
/// <param name="context">The parse tree.</param>
69+
void EnterDateOrTime([NotNull] VBADateParser.DateOrTimeContext context);
70+
/// <summary>
71+
/// Exit a parse tree produced by <see cref="VBADateParser.dateOrTime"/>.
72+
/// </summary>
73+
/// <param name="context">The parse tree.</param>
74+
void ExitDateOrTime([NotNull] VBADateParser.DateOrTimeContext context);
75+
76+
/// <summary>
77+
/// Enter a parse tree produced by <see cref="VBADateParser.englishMonthName"/>.
78+
/// </summary>
79+
/// <param name="context">The parse tree.</param>
80+
void EnterEnglishMonthName([NotNull] VBADateParser.EnglishMonthNameContext context);
81+
/// <summary>
82+
/// Exit a parse tree produced by <see cref="VBADateParser.englishMonthName"/>.
83+
/// </summary>
84+
/// <param name="context">The parse tree.</param>
85+
void ExitEnglishMonthName([NotNull] VBADateParser.EnglishMonthNameContext context);
86+
87+
/// <summary>
88+
/// Enter a parse tree produced by <see cref="VBADateParser.monthName"/>.
89+
/// </summary>
90+
/// <param name="context">The parse tree.</param>
91+
void EnterMonthName([NotNull] VBADateParser.MonthNameContext context);
92+
/// <summary>
93+
/// Exit a parse tree produced by <see cref="VBADateParser.monthName"/>.
94+
/// </summary>
95+
/// <param name="context">The parse tree.</param>
96+
void ExitMonthName([NotNull] VBADateParser.MonthNameContext context);
97+
98+
/// <summary>
99+
/// Enter a parse tree produced by <see cref="VBADateParser.timeSeparator"/>.
100+
/// </summary>
101+
/// <param name="context">The parse tree.</param>
102+
void EnterTimeSeparator([NotNull] VBADateParser.TimeSeparatorContext context);
103+
/// <summary>
104+
/// Exit a parse tree produced by <see cref="VBADateParser.timeSeparator"/>.
105+
/// </summary>
106+
/// <param name="context">The parse tree.</param>
107+
void ExitTimeSeparator([NotNull] VBADateParser.TimeSeparatorContext context);
108+
109+
/// <summary>
110+
/// Enter a parse tree produced by <see cref="VBADateParser.timeValue"/>.
111+
/// </summary>
112+
/// <param name="context">The parse tree.</param>
113+
void EnterTimeValue([NotNull] VBADateParser.TimeValueContext context);
114+
/// <summary>
115+
/// Exit a parse tree produced by <see cref="VBADateParser.timeValue"/>.
116+
/// </summary>
117+
/// <param name="context">The parse tree.</param>
118+
void ExitTimeValue([NotNull] VBADateParser.TimeValueContext context);
119+
120+
/// <summary>
121+
/// Enter a parse tree produced by <see cref="VBADateParser.compilationUnit"/>.
122+
/// </summary>
123+
/// <param name="context">The parse tree.</param>
124+
void EnterCompilationUnit([NotNull] VBADateParser.CompilationUnitContext context);
125+
/// <summary>
126+
/// Exit a parse tree produced by <see cref="VBADateParser.compilationUnit"/>.
127+
/// </summary>
128+
/// <param name="context">The parse tree.</param>
129+
void ExitCompilationUnit([NotNull] VBADateParser.CompilationUnitContext context);
130+
131+
/// <summary>
132+
/// Enter a parse tree produced by <see cref="VBADateParser.dateValuePart"/>.
133+
/// </summary>
134+
/// <param name="context">The parse tree.</param>
135+
void EnterDateValuePart([NotNull] VBADateParser.DateValuePartContext context);
136+
/// <summary>
137+
/// Exit a parse tree produced by <see cref="VBADateParser.dateValuePart"/>.
138+
/// </summary>
139+
/// <param name="context">The parse tree.</param>
140+
void ExitDateValuePart([NotNull] VBADateParser.DateValuePartContext context);
141+
142+
/// <summary>
143+
/// Enter a parse tree produced by <see cref="VBADateParser.timeValuePart"/>.
144+
/// </summary>
145+
/// <param name="context">The parse tree.</param>
146+
void EnterTimeValuePart([NotNull] VBADateParser.TimeValuePartContext context);
147+
/// <summary>
148+
/// Exit a parse tree produced by <see cref="VBADateParser.timeValuePart"/>.
149+
/// </summary>
150+
/// <param name="context">The parse tree.</param>
151+
void ExitTimeValuePart([NotNull] VBADateParser.TimeValuePartContext context);
152+
153+
/// <summary>
154+
/// Enter a parse tree produced by <see cref="VBADateParser.dateLiteral"/>.
155+
/// </summary>
156+
/// <param name="context">The parse tree.</param>
157+
void EnterDateLiteral([NotNull] VBADateParser.DateLiteralContext context);
158+
/// <summary>
159+
/// Exit a parse tree produced by <see cref="VBADateParser.dateLiteral"/>.
160+
/// </summary>
161+
/// <param name="context">The parse tree.</param>
162+
void ExitDateLiteral([NotNull] VBADateParser.DateLiteralContext context);
163+
164+
/// <summary>
165+
/// Enter a parse tree produced by <see cref="VBADateParser.dateValueNumber"/>.
166+
/// </summary>
167+
/// <param name="context">The parse tree.</param>
168+
void EnterDateValueNumber([NotNull] VBADateParser.DateValueNumberContext context);
169+
/// <summary>
170+
/// Exit a parse tree produced by <see cref="VBADateParser.dateValueNumber"/>.
171+
/// </summary>
172+
/// <param name="context">The parse tree.</param>
173+
void ExitDateValueNumber([NotNull] VBADateParser.DateValueNumberContext context);
174+
}
175+
} // namespace Rubberduck.Parsing

0 commit comments

Comments
 (0)