Skip to content

Commit a44c320

Browse files
author
Andrin Meier
committed
consider declared option compare method when comparing strings
1 parent 3641b0b commit a44c320

21 files changed

+5306
-4253
lines changed

Rubberduck.Parsing/Grammar/VBA.g4

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ moduleOption :
5858
;
5959

6060
moduleDeclarationsElement :
61-
comment
62-
| declareStmt
61+
declareStmt
6362
| enumerationStmt
6463
| eventStmt
6564
| constStmt
6665
| implementsStmt
6766
| variableStmt
6867
| moduleOption
6968
| typeStmt
69+
| macroStmt
70+
;
71+
72+
macroStmt :
73+
macroConstStmt
74+
| macroIfThenElseStmt
7075
;
7176

7277
moduleBody :
@@ -78,6 +83,7 @@ moduleBodyElement :
7883
| propertySetStmt
7984
| propertyLetStmt
8085
| subStmt
86+
| macroStmt
8187
;
8288

8389

@@ -120,6 +126,7 @@ blockStmt :
120126
| loadStmt
121127
| lockStmt
122128
| lsetStmt
129+
| macroStmt
123130
| midStmt
124131
| mkdirStmt
125132
| nameStmt
@@ -284,6 +291,25 @@ lockStmt : LOCK WS valueStmt (WS? ',' WS? valueStmt (WS TO WS valueStmt)?)?;
284291

285292
lsetStmt : LSET WS implicitCallStmt_InStmt WS? EQ WS? valueStmt;
286293

294+
macroConstStmt : MACRO_CONST WS? ambiguousIdentifier WS? EQ WS? valueStmt;
295+
296+
macroIfThenElseStmt : macroIfBlockStmt macroElseIfBlockStmt* macroElseBlockStmt? MACRO_END_IF;
297+
298+
macroIfBlockStmt :
299+
MACRO_IF WS? ifConditionStmt WS THEN endOfStatement
300+
(moduleDeclarations | moduleBody | block)*
301+
;
302+
303+
macroElseIfBlockStmt :
304+
MACRO_ELSEIF WS? ifConditionStmt WS THEN endOfStatement
305+
(moduleDeclarations | moduleBody | block)*
306+
;
307+
308+
macroElseBlockStmt :
309+
MACRO_ELSE endOfStatement
310+
(moduleDeclarations | moduleBody | block)*
311+
;
312+
287313
midStmt : MID WS? LPAREN WS? argsCall WS? RPAREN;
288314

289315
mkdirStmt : MKDIR WS valueStmt;
@@ -700,6 +726,11 @@ LOCK_READ : L O C K WS R E A D;
700726
LOCK_WRITE : L O C K WS W R I T E;
701727
LOCK_READ_WRITE : L O C K WS R E A D WS W R I T E;
702728
LSET : L S E T;
729+
MACRO_CONST : '#' C O N S T;
730+
MACRO_IF : '#' I F;
731+
MACRO_ELSEIF : '#' E L S E I F;
732+
MACRO_ELSE : '#' E L S E;
733+
MACRO_END_IF : '#' E N D WS? I F;
703734
ME : M E;
704735
MID : M I D;
705736
MKDIR : M K D I R;

Rubberduck.Parsing/Grammar/VBABaseListener.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,19 @@ public virtual void EnterForEachStmt([NotNull] VBAParser.ForEachStmtContext cont
12031203
/// <param name="context">The parse tree.</param>
12041204
public virtual void ExitForEachStmt([NotNull] VBAParser.ForEachStmtContext context) { }
12051205

1206+
/// <summary>
1207+
/// Enter a parse tree produced by <see cref="VBAParser.macroElseBlockStmt"/>.
1208+
/// <para>The default implementation does nothing.</para>
1209+
/// </summary>
1210+
/// <param name="context">The parse tree.</param>
1211+
public virtual void EnterMacroElseBlockStmt([NotNull] VBAParser.MacroElseBlockStmtContext context) { }
1212+
/// <summary>
1213+
/// Exit a parse tree produced by <see cref="VBAParser.macroElseBlockStmt"/>.
1214+
/// <para>The default implementation does nothing.</para>
1215+
/// </summary>
1216+
/// <param name="context">The parse tree.</param>
1217+
public virtual void ExitMacroElseBlockStmt([NotNull] VBAParser.MacroElseBlockStmtContext context) { }
1218+
12061219
/// <summary>
12071220
/// Enter a parse tree produced by <see cref="VBAParser.exitStmt"/>.
12081221
/// <para>The default implementation does nothing.</para>
@@ -1515,6 +1528,19 @@ public virtual void EnterVariableStmt([NotNull] VBAParser.VariableStmtContext co
15151528
/// <param name="context">The parse tree.</param>
15161529
public virtual void ExitVariableStmt([NotNull] VBAParser.VariableStmtContext context) { }
15171530

1531+
/// <summary>
1532+
/// Enter a parse tree produced by <see cref="VBAParser.macroIfBlockStmt"/>.
1533+
/// <para>The default implementation does nothing.</para>
1534+
/// </summary>
1535+
/// <param name="context">The parse tree.</param>
1536+
public virtual void EnterMacroIfBlockStmt([NotNull] VBAParser.MacroIfBlockStmtContext context) { }
1537+
/// <summary>
1538+
/// Exit a parse tree produced by <see cref="VBAParser.macroIfBlockStmt"/>.
1539+
/// <para>The default implementation does nothing.</para>
1540+
/// </summary>
1541+
/// <param name="context">The parse tree.</param>
1542+
public virtual void ExitMacroIfBlockStmt([NotNull] VBAParser.MacroIfBlockStmtContext context) { }
1543+
15181544
/// <summary>
15191545
/// Enter a parse tree produced by <see cref="VBAParser.subscript"/>.
15201546
/// <para>The default implementation does nothing.</para>
@@ -1619,6 +1645,19 @@ public virtual void EnterFunctionStmt([NotNull] VBAParser.FunctionStmtContext co
16191645
/// <param name="context">The parse tree.</param>
16201646
public virtual void ExitFunctionStmt([NotNull] VBAParser.FunctionStmtContext context) { }
16211647

1648+
/// <summary>
1649+
/// Enter a parse tree produced by <see cref="VBAParser.macroElseIfBlockStmt"/>.
1650+
/// <para>The default implementation does nothing.</para>
1651+
/// </summary>
1652+
/// <param name="context">The parse tree.</param>
1653+
public virtual void EnterMacroElseIfBlockStmt([NotNull] VBAParser.MacroElseIfBlockStmtContext context) { }
1654+
/// <summary>
1655+
/// Exit a parse tree produced by <see cref="VBAParser.macroElseIfBlockStmt"/>.
1656+
/// <para>The default implementation does nothing.</para>
1657+
/// </summary>
1658+
/// <param name="context">The parse tree.</param>
1659+
public virtual void ExitMacroElseIfBlockStmt([NotNull] VBAParser.MacroElseIfBlockStmtContext context) { }
1660+
16221661
/// <summary>
16231662
/// Enter a parse tree produced by <see cref="VBAParser.returnStmt"/>.
16241663
/// <para>The default implementation does nothing.</para>
@@ -1983,6 +2022,19 @@ public virtual void EnterVariableListStmt([NotNull] VBAParser.VariableListStmtCo
19832022
/// <param name="context">The parse tree.</param>
19842023
public virtual void ExitVariableListStmt([NotNull] VBAParser.VariableListStmtContext context) { }
19852024

2025+
/// <summary>
2026+
/// Enter a parse tree produced by <see cref="VBAParser.macroConstStmt"/>.
2027+
/// <para>The default implementation does nothing.</para>
2028+
/// </summary>
2029+
/// <param name="context">The parse tree.</param>
2030+
public virtual void EnterMacroConstStmt([NotNull] VBAParser.MacroConstStmtContext context) { }
2031+
/// <summary>
2032+
/// Exit a parse tree produced by <see cref="VBAParser.macroConstStmt"/>.
2033+
/// <para>The default implementation does nothing.</para>
2034+
/// </summary>
2035+
/// <param name="context">The parse tree.</param>
2036+
public virtual void ExitMacroConstStmt([NotNull] VBAParser.MacroConstStmtContext context) { }
2037+
19862038
/// <summary>
19872039
/// Enter a parse tree produced by <see cref="VBAParser.iCS_B_ProcedureCall"/>.
19882040
/// <para>The default implementation does nothing.</para>
@@ -2048,6 +2100,19 @@ public virtual void EnterMidStmt([NotNull] VBAParser.MidStmtContext context) { }
20482100
/// <param name="context">The parse tree.</param>
20492101
public virtual void ExitMidStmt([NotNull] VBAParser.MidStmtContext context) { }
20502102

2103+
/// <summary>
2104+
/// Enter a parse tree produced by <see cref="VBAParser.macroIfThenElseStmt"/>.
2105+
/// <para>The default implementation does nothing.</para>
2106+
/// </summary>
2107+
/// <param name="context">The parse tree.</param>
2108+
public virtual void EnterMacroIfThenElseStmt([NotNull] VBAParser.MacroIfThenElseStmtContext context) { }
2109+
/// <summary>
2110+
/// Exit a parse tree produced by <see cref="VBAParser.macroIfThenElseStmt"/>.
2111+
/// <para>The default implementation does nothing.</para>
2112+
/// </summary>
2113+
/// <param name="context">The parse tree.</param>
2114+
public virtual void ExitMacroIfThenElseStmt([NotNull] VBAParser.MacroIfThenElseStmtContext context) { }
2115+
20512116
/// <summary>
20522117
/// Enter a parse tree produced by <see cref="VBAParser.vsPow"/>.
20532118
/// <para>The default implementation does nothing.</para>
@@ -2217,6 +2282,19 @@ public virtual void EnterModuleBodyElement([NotNull] VBAParser.ModuleBodyElement
22172282
/// <param name="context">The parse tree.</param>
22182283
public virtual void ExitModuleBodyElement([NotNull] VBAParser.ModuleBodyElementContext context) { }
22192284

2285+
/// <summary>
2286+
/// Enter a parse tree produced by <see cref="VBAParser.macroStmt"/>.
2287+
/// <para>The default implementation does nothing.</para>
2288+
/// </summary>
2289+
/// <param name="context">The parse tree.</param>
2290+
public virtual void EnterMacroStmt([NotNull] VBAParser.MacroStmtContext context) { }
2291+
/// <summary>
2292+
/// Exit a parse tree produced by <see cref="VBAParser.macroStmt"/>.
2293+
/// <para>The default implementation does nothing.</para>
2294+
/// </summary>
2295+
/// <param name="context">The parse tree.</param>
2296+
public virtual void ExitMacroStmt([NotNull] VBAParser.MacroStmtContext context) { }
2297+
22202298
/// <summary>
22212299
/// Enter a parse tree produced by <see cref="VBAParser.vsMid"/>.
22222300
/// <para>The default implementation does nothing.</para>

Rubberduck.Parsing/Grammar/VBABaseVisitor.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,17 @@ public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>,
10221022
/// <return>The visitor result.</return>
10231023
public virtual Result VisitForEachStmt([NotNull] VBAParser.ForEachStmtContext context) { return VisitChildren(context); }
10241024

1025+
/// <summary>
1026+
/// Visit a parse tree produced by <see cref="VBAParser.macroElseBlockStmt"/>.
1027+
/// <para>
1028+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
1029+
/// on <paramref name="context"/>.
1030+
/// </para>
1031+
/// </summary>
1032+
/// <param name="context">The parse tree.</param>
1033+
/// <return>The visitor result.</return>
1034+
public virtual Result VisitMacroElseBlockStmt([NotNull] VBAParser.MacroElseBlockStmtContext context) { return VisitChildren(context); }
1035+
10251036
/// <summary>
10261037
/// Visit a parse tree produced by <see cref="VBAParser.exitStmt"/>.
10271038
/// <para>
@@ -1286,6 +1297,17 @@ public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>,
12861297
/// <return>The visitor result.</return>
12871298
public virtual Result VisitVariableStmt([NotNull] VBAParser.VariableStmtContext context) { return VisitChildren(context); }
12881299

1300+
/// <summary>
1301+
/// Visit a parse tree produced by <see cref="VBAParser.macroIfBlockStmt"/>.
1302+
/// <para>
1303+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
1304+
/// on <paramref name="context"/>.
1305+
/// </para>
1306+
/// </summary>
1307+
/// <param name="context">The parse tree.</param>
1308+
/// <return>The visitor result.</return>
1309+
public virtual Result VisitMacroIfBlockStmt([NotNull] VBAParser.MacroIfBlockStmtContext context) { return VisitChildren(context); }
1310+
12891311
/// <summary>
12901312
/// Visit a parse tree produced by <see cref="VBAParser.subscript"/>.
12911313
/// <para>
@@ -1374,6 +1396,17 @@ public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>,
13741396
/// <return>The visitor result.</return>
13751397
public virtual Result VisitFunctionStmt([NotNull] VBAParser.FunctionStmtContext context) { return VisitChildren(context); }
13761398

1399+
/// <summary>
1400+
/// Visit a parse tree produced by <see cref="VBAParser.macroElseIfBlockStmt"/>.
1401+
/// <para>
1402+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
1403+
/// on <paramref name="context"/>.
1404+
/// </para>
1405+
/// </summary>
1406+
/// <param name="context">The parse tree.</param>
1407+
/// <return>The visitor result.</return>
1408+
public virtual Result VisitMacroElseIfBlockStmt([NotNull] VBAParser.MacroElseIfBlockStmtContext context) { return VisitChildren(context); }
1409+
13771410
/// <summary>
13781411
/// Visit a parse tree produced by <see cref="VBAParser.returnStmt"/>.
13791412
/// <para>
@@ -1682,6 +1715,17 @@ public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>,
16821715
/// <return>The visitor result.</return>
16831716
public virtual Result VisitVariableListStmt([NotNull] VBAParser.VariableListStmtContext context) { return VisitChildren(context); }
16841717

1718+
/// <summary>
1719+
/// Visit a parse tree produced by <see cref="VBAParser.macroConstStmt"/>.
1720+
/// <para>
1721+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
1722+
/// on <paramref name="context"/>.
1723+
/// </para>
1724+
/// </summary>
1725+
/// <param name="context">The parse tree.</param>
1726+
/// <return>The visitor result.</return>
1727+
public virtual Result VisitMacroConstStmt([NotNull] VBAParser.MacroConstStmtContext context) { return VisitChildren(context); }
1728+
16851729
/// <summary>
16861730
/// Visit a parse tree produced by <see cref="VBAParser.iCS_B_ProcedureCall"/>.
16871731
/// <para>
@@ -1737,6 +1781,17 @@ public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>,
17371781
/// <return>The visitor result.</return>
17381782
public virtual Result VisitMidStmt([NotNull] VBAParser.MidStmtContext context) { return VisitChildren(context); }
17391783

1784+
/// <summary>
1785+
/// Visit a parse tree produced by <see cref="VBAParser.macroIfThenElseStmt"/>.
1786+
/// <para>
1787+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
1788+
/// on <paramref name="context"/>.
1789+
/// </para>
1790+
/// </summary>
1791+
/// <param name="context">The parse tree.</param>
1792+
/// <return>The visitor result.</return>
1793+
public virtual Result VisitMacroIfThenElseStmt([NotNull] VBAParser.MacroIfThenElseStmtContext context) { return VisitChildren(context); }
1794+
17401795
/// <summary>
17411796
/// Visit a parse tree produced by <see cref="VBAParser.vsPow"/>.
17421797
/// <para>
@@ -1880,6 +1935,17 @@ public partial class VBABaseVisitor<Result> : AbstractParseTreeVisitor<Result>,
18801935
/// <return>The visitor result.</return>
18811936
public virtual Result VisitModuleBodyElement([NotNull] VBAParser.ModuleBodyElementContext context) { return VisitChildren(context); }
18821937

1938+
/// <summary>
1939+
/// Visit a parse tree produced by <see cref="VBAParser.macroStmt"/>.
1940+
/// <para>
1941+
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
1942+
/// on <paramref name="context"/>.
1943+
/// </para>
1944+
/// </summary>
1945+
/// <param name="context">The parse tree.</param>
1946+
/// <return>The visitor result.</return>
1947+
public virtual Result VisitMacroStmt([NotNull] VBAParser.MacroStmtContext context) { return VisitChildren(context); }
1948+
18831949
/// <summary>
18841950
/// Visit a parse tree produced by <see cref="VBAParser.vsMid"/>.
18851951
/// <para>

0 commit comments

Comments
 (0)