Skip to content

Commit 2451931

Browse files
committed
rebuilt grammar/parser (support anonymous "with" blocks) and rewrote IdentifierReferenceListener, which doesn't work for member references Needs testing.
1 parent d13c186 commit 2451931

File tree

12 files changed

+2876
-2054
lines changed

12 files changed

+2876
-2054
lines changed

RetailCoder.VBE/Settings/DisplayLanguageSetting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public DisplayLanguageSetting(string code)
4646

4747
public override bool Equals(object obj)
4848
{
49-
var other = (DisplayLanguageSetting) obj;
50-
return Code.Equals(other.Code);
49+
var other = obj as DisplayLanguageSetting;
50+
return other != null && Code.Equals(other.Code);
5151
}
5252

5353
public override int GetHashCode()

Rubberduck.Parsing/Grammar/VBA.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* - added support for numbered lines (amended lineLabel rule).
5353
* - added support for VBA 7.0 PtrSafe attribute for Declare statements.
5454
* - implemented a fileNumber rule to locate identifier usages in file numbers.
55+
* - added support for anonymous declarations in With blocks (With New Something)
5556
*
5657
*======================================================================================
5758
*
@@ -532,7 +533,7 @@ whileWendStmt :
532533
widthStmt : WIDTH WS valueStmt WS? ',' WS? valueStmt;
533534

534535
withStmt :
535-
WITH WS implicitCallStmt_InStmt NEWLINE+
536+
WITH WS (implicitCallStmt_InStmt | (NEW WS type)) NEWLINE+
536537
(block NEWLINE+)?
537538
END_WITH
538539
;

Rubberduck.Parsing/Grammar/VBABaseListener.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
// Generated from C:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Grammar\VBA.g4 by ANTLR 4.3
1212

1313
// Unreachable code detected
14-
15-
using System;
16-
using System.CodeDom.Compiler;
17-
using Antlr4.Runtime;
18-
using Antlr4.Runtime.Misc;
19-
using Antlr4.Runtime.Tree;
20-
2114
#pragma warning disable 0162
2215
// The variable '...' is assigned but its value is never used
2316
#pragma warning disable 0219
2417
// Missing XML comment for publicly visible type or member '...'
2518
#pragma warning disable 1591
2619

2720
namespace Rubberduck.Parsing.Grammar {
28-
/// <summary>
21+
22+
using Antlr4.Runtime.Misc;
23+
using IErrorNode = Antlr4.Runtime.Tree.IErrorNode;
24+
using ITerminalNode = Antlr4.Runtime.Tree.ITerminalNode;
25+
using IToken = Antlr4.Runtime.IToken;
26+
using ParserRuleContext = Antlr4.Runtime.ParserRuleContext;
27+
28+
/// <summary>
2929
/// This class provides an empty implementation of <see cref="IVBAListener"/>,
3030
/// which can be extended to create a listener which only needs to handle a subset
3131
/// of the available methods.
3232
/// </summary>
33-
[GeneratedCode("ANTLR", "4.3")]
34-
[CLSCompliant(false)]
33+
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.3")]
34+
[System.CLSCompliant(false)]
3535
public partial class VBABaseListener : IVBAListener {
3636
/// <summary>
3737
/// Enter a parse tree produced by <see cref="VBAParser.stopStmt"/>.

Rubberduck.Parsing/Grammar/VBABaseVisitor.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@
1111
// Generated from C:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Grammar\VBA.g4 by ANTLR 4.3
1212

1313
// Unreachable code detected
14-
15-
using System;
16-
using System.CodeDom.Compiler;
17-
using Antlr4.Runtime.Misc;
18-
using Antlr4.Runtime.Tree;
19-
2014
#pragma warning disable 0162
2115
// The variable '...' is assigned but its value is never used
2216
#pragma warning disable 0219
2317
// Missing XML comment for publicly visible type or member '...'
2418
#pragma warning disable 1591
2519

2620
namespace Rubberduck.Parsing.Grammar {
27-
/// <summary>
21+
using Antlr4.Runtime.Misc;
22+
using Antlr4.Runtime.Tree;
23+
using IToken = Antlr4.Runtime.IToken;
24+
using ParserRuleContext = Antlr4.Runtime.ParserRuleContext;
25+
26+
/// <summary>
2827
/// This class provides an empty implementation of <see cref="IVBAVisitor{Result}"/>,
2928
/// which can be extended to create a visitor which only needs to handle a subset
3029
/// of the available methods.
3130
/// </summary>
3231
/// <typeparam name="Result">The return type of the visit operation.</typeparam>
33-
[GeneratedCode("ANTLR", "4.3")]
34-
[CLSCompliant(false)]
32+
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.3")]
33+
[System.CLSCompliant(false)]
3534
public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>, IVBAVisitor<Result> {
3635
/// <summary>
3736
/// Visit a parse tree produced by <see cref="VBAParser.stopStmt"/>.

Rubberduck.Parsing/Grammar/VBALexer.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@
1111
// Generated from C:\Users\Mathieu\Source\Repos\Rubberduck\Rubberduck.Parsing\Grammar\VBA.g4 by ANTLR 4.3
1212

1313
// Unreachable code detected
14-
15-
using System;
16-
using System.CodeDom.Compiler;
17-
using Antlr4.Runtime;
18-
using Antlr4.Runtime.Atn;
19-
2014
#pragma warning disable 0162
2115
// The variable '...' is assigned but its value is never used
2216
#pragma warning disable 0219
2317
// Missing XML comment for publicly visible type or member '...'
2418
#pragma warning disable 1591
2519

2620
namespace Rubberduck.Parsing.Grammar {
27-
[GeneratedCode("ANTLR", "4.3")]
28-
[CLSCompliant(false)]
21+
using Antlr4.Runtime;
22+
using Antlr4.Runtime.Atn;
23+
using Antlr4.Runtime.Misc;
24+
using DFA = Antlr4.Runtime.Dfa.DFA;
25+
26+
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.3")]
27+
[System.CLSCompliant(false)]
2928
public partial class VBALexer : Lexer {
3029
public const int
3130
T__8=1, T__7=2, T__6=3, T__5=4, T__4=5, T__3=6, T__2=7, T__1=8, T__0=9,
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
FUNCTION=78
2+
PROPERTY_LET=133
3+
BYREF=23
4+
DEFDBL=39
5+
MOD=111
6+
CONST=32
7+
DO=50
8+
COLORLITERAL=206
9+
NOT=115
10+
EXIT_PROPERTY=72
11+
KILL=90
12+
END_SELECT=59
13+
REDIM=143
14+
TYPE=171
15+
RPAREN=201
16+
LOOP=94
17+
BEGIN=18
18+
CHDIR=27
19+
RETURN=147
20+
IMP=84
21+
GET=79
22+
GEQ=189
23+
GOTO=82
24+
EQ=188
25+
SHARED=157
26+
DEFLNG=43
27+
PRESERVE=129
28+
GOSUB=81
29+
DEFVAR=47
30+
STATIC=160
31+
ELSE=53
32+
DOUBLELITERAL=208
33+
LOAD=91
34+
STOP=162
35+
DEFDEC=40
36+
SAVEPICTURE=150
37+
VARIANT=176
38+
PLUS_EQ=199
39+
DEFOBJ=44
40+
LIB=97
41+
MINUS_EQ=195
42+
OPTION_BASE=122
43+
WS=214
44+
MACRO_END_IF=107
45+
READ=141
46+
TYPEOF=172
47+
DEFDATE=38
48+
ALIAS=12
49+
WIDTH=180
50+
LOCK_READ_WRITE=102
51+
GT=190
52+
RMDIR=148
53+
CALL=25
54+
END=63
55+
END_SUB=60
56+
MACRO_ELSEIF=105
57+
UNLOCK=174
58+
ERASE=66
59+
FILECOPY=75
60+
INPUT=87
61+
STEP=161
62+
SUB=164
63+
VERSION=177
64+
RANDOM=138
65+
LPAREN=192
66+
DATELITERAL=205
67+
AS=17
68+
TIME=168
69+
THEN=167
70+
IMPLEMENTS=85
71+
END_TYPE=61
72+
LINE_CONTINUATION=211
73+
ACCESS=10
74+
LINE_INPUT=99
75+
PLUS=198
76+
EXIT_FUNCTION=71
77+
LIKE=98
78+
INTEGER=89
79+
OPTION_PRIVATE_MODULE=125
80+
DEFBYTE=37
81+
DEFBOOL=36
82+
TO=169
83+
MID=109
84+
AMPERSAND=185
85+
SET=155
86+
MINUS=194
87+
TEXT=166
88+
PRINT=130
89+
RESUME=146
90+
SETATTR=156
91+
DELETESETTING=48
92+
ENUM=64
93+
DATABASE=33
94+
CLOSE=30
95+
END_WITH=62
96+
STRINGLITERAL=204
97+
ADDRESSOF=11
98+
WITHEVENTS=182
99+
DIM=49
100+
END_IF=57
101+
END_PROPERTY=58
102+
DECLARE=35
103+
DEFSNG=45
104+
DIV=187
105+
LONG=93
106+
PUBLIC=136
107+
STRING=163
108+
WEND=178
109+
LT=193
110+
INTEGERLITERAL=207
111+
WHILE=179
112+
SPC=159
113+
RESET=145
114+
CASE=26
115+
NEW=114
116+
BYVAL=22
117+
ME=108
118+
MACRO_IF=104
119+
READ_WRITE=142
120+
BEEP=19
121+
T__8=1
122+
END_ENUM=55
123+
T__7=2
124+
PROPERTY_SET=134
125+
T__6=3
126+
T__5=4
127+
T__4=5
128+
OPTION_EXPLICIT=123
129+
NAME=112
130+
OPTION_COMPARE=124
131+
POW=200
132+
EXIT_SUB=73
133+
LOCK_READ=100
134+
FRIEND=76
135+
LSET=103
136+
DOUBLE=51
137+
EACH=52
138+
COMMENT=213
139+
L_SQUARE_BRACKET=202
140+
SELECT=153
141+
PRIVATE=131
142+
NULL=117
143+
ON=118
144+
MULT=196
145+
ERROR=67
146+
SENDKEYS=154
147+
EXIT_DO=69
148+
UNTIL=175
149+
OR=126
150+
FALSE=74
151+
OUTPUT=127
152+
APPEND=16
153+
CLASS=29
154+
ATTRIBUTE=14
155+
DEFCUR=41
156+
FOR=77
157+
PTRSAFE=135
158+
AND=13
159+
LOCK=92
160+
IF=83
161+
RSET=149
162+
APPACTIVATE=15
163+
BOOLEAN=21
164+
IN=86
165+
PARAMARRAY=128
166+
END_FUNCTION=56
167+
IS=88
168+
IDENTIFIER=210
169+
MACRO_ELSE=106
170+
NOTHING=116
171+
NEXT=113
172+
COLLECTION=31
173+
WITH=181
174+
RAISEEVENT=140
175+
BYTE=24
176+
XOR=184
177+
DEFSTR=46
178+
BYTELITERAL=209
179+
R_SQUARE_BRACKET=203
180+
TAB=165
181+
ON_ERROR=119
182+
PROPERTY_GET=132
183+
REM=144
184+
EVENT=68
185+
TRUE=170
186+
WRITE=183
187+
UNLOAD=173
188+
OPTIONAL=121
189+
ELSEIF=54
190+
SEEK=152
191+
OPEN=120
192+
NEQ=197
193+
NEWLINE=212
194+
MKDIR=110
195+
SINGLE=158
196+
T__1=8
197+
T__0=9
198+
T__3=6
199+
EXIT_FOR=70
200+
T__2=7
201+
DEFINT=42
202+
ASSIGN=186
203+
LEN=95
204+
EQV=65
205+
BINARY=20
206+
LOCK_WRITE=101
207+
GLOBAL=80
208+
CHDRIVE=28
209+
DATE=34
210+
LET=96
211+
SAVESETTING=151
212+
PUT=137
213+
RANDOMIZE=139
214+
LEQ=191
215+
'!'=8
216+
'#'=6
217+
'>='=189
218+
':='=186
219+
'>'=190
220+
';'=7
221+
'='=188
222+
'<>'=197
223+
'@'=5
224+
'+'=198
225+
')'=201
226+
'.'=2
227+
'^'=200
228+
'%'=1
229+
'$'=9
230+
'+='=199
231+
'<='=191
232+
'<'=193
233+
':'=4
234+
'('=192
235+
'['=202
236+
'-'=194
237+
'*'=196
238+
','=3
239+
'&'=185
240+
'-='=195
241+
']'=203

0 commit comments

Comments
 (0)