Skip to content

Commit 8057c3d

Browse files
committed
updated change log in grammar file, added implementation stubs and comments (referencing GitHub issues) for picking up literals in IdentifierReferenceListener
1 parent 364ec2e commit 8057c3d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Rubberduck.Parsing/Grammar/VBA.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* - added support for Option Compare Database.
5252
* - added support for numbered lines (amended lineLabel rule).
5353
* - added support for VBA 7.0 PtrSafe attribute for Declare statements.
54+
* - implemented a fileNumber rule to locate identifier usages in file numbers.
5455
*
5556
*======================================================================================
5657
*

Rubberduck.Parsing/Symbols/IdentifierReferenceListener.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Antlr4.Runtime;
5+
using Antlr4.Runtime.Tree;
56
using Rubberduck.Parsing.Grammar;
67

78
namespace Rubberduck.Parsing.Symbols
@@ -44,6 +45,41 @@ private void SetCurrentScope(string name)
4445
_currentScope = _qualifiedName.ProjectName + "." + _qualifiedName.ModuleName + "." + name;
4546
}
4647

48+
public override void EnterLiteral(VBAParser.LiteralContext context)
49+
{
50+
var stringLiteral = context.STRINGLITERAL();
51+
if (stringLiteral != null)
52+
{
53+
HandleEmptyStringLiteral(stringLiteral);
54+
return;
55+
}
56+
57+
var numberLiteral = context.INTEGERLITERAL();
58+
if (numberLiteral != null)
59+
{
60+
HandleNumberLiteral(numberLiteral);
61+
return;
62+
}
63+
}
64+
65+
private void HandleEmptyStringLiteral(ITerminalNode stringLiteral)
66+
{
67+
if (stringLiteral.Symbol.Text.Length == 2) // string literal only contains opening & closing quotes
68+
{
69+
// todo: track that value + implement an inspection that recommends replacing it with vbNullString (#363)
70+
}
71+
}
72+
73+
private void HandleNumberLiteral(ITerminalNode numberLiteral)
74+
{
75+
// todo: verify whether the string representation ends with a type hint; flag as such if needed.
76+
77+
// todo: track that value + implement an inspection that checks for magic numbers (#359)
78+
// also, don't do anything here if tree walker is currently in a ConstSubStmtContext
79+
80+
81+
}
82+
4783
public override void EnterSubStmt(VBAParser.SubStmtContext context)
4884
{
4985
SetCurrentScope(context.ambiguousIdentifier().GetText());

0 commit comments

Comments
 (0)