Skip to content

Commit 9238e68

Browse files
committed
Tests added, hack removed, resolver happy
1 parent 57e51f3 commit 9238e68

File tree

2 files changed

+115
-10
lines changed

2 files changed

+115
-10
lines changed

Rubberduck.Parsing/Binding/Bindings/SimpleNameDefaultBinding.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Antlr4.Runtime;
22
using Rubberduck.Parsing.Symbols;
33
using System.Linq;
4-
using Rubberduck.Parsing.Grammar;
54

65
namespace Rubberduck.Parsing.Binding
76
{
@@ -75,14 +74,9 @@ public IBoundExpression Resolve()
7574
var bracketedExpression = _declarationFinder.OnBracketedExpression(_context.GetText(), _context);
7675
return new SimpleNameExpression(bracketedExpression, ExpressionClassification.Unbound, _context);
7776
}
78-
//TODO - this is a complete and total hack to prevent `Mid` and `Mid$` from creating undeclared variables
79-
//pending an actual fix to the grammar. See #2618
80-
else if (!_name.Equals("Mid") && !_name.Equals("Mid$"))
81-
{
82-
var undeclaredLocal = _declarationFinder.OnUndeclaredVariable(_parent, _name, _context);
83-
return new SimpleNameExpression(undeclaredLocal, ExpressionClassification.Variable, _context);
84-
}
85-
return new ResolutionFailedExpression();
77+
78+
var undeclaredLocal = _declarationFinder.OnUndeclaredVariable(_parent, _name, _context);
79+
return new SimpleNameExpression(undeclaredLocal, ExpressionClassification.Variable, _context);
8680
}
8781

8882
private IBoundExpression ResolveProcedureNamespace()

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2873,7 +2873,118 @@ End Sub
28732873
var parseResult = Parse(code);
28742874
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
28752875
}
2876-
2876+
2877+
[Category("Parser")]
2878+
[Test]
2879+
public void MidDollarStatement()
2880+
{
2881+
const string code = @"
2882+
Public Sub Test()
2883+
Dim TestString As String
2884+
TestString = ""The dog jumps""
2885+
Mid$(TestString, 5, 3) = ""fox""
2886+
End Sub
2887+
";
2888+
var parseResult = Parse(code);
2889+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
2890+
}
2891+
2892+
public void MidBStatement()
2893+
{
2894+
const string code = @"
2895+
Public Sub Test()
2896+
Dim TestString As String
2897+
TestString = ""The dog jumps""
2898+
MidB(TestString, 5, 3) = ""fox""
2899+
End Sub
2900+
";
2901+
var parseResult = Parse(code);
2902+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
2903+
}
2904+
2905+
[Category("Parser")]
2906+
[Test]
2907+
public void MidBDollarStatement()
2908+
{
2909+
const string code = @"
2910+
Public Sub Test()
2911+
Dim TestString As String
2912+
TestString = ""The dog jumps""
2913+
MidB$(TestString, 5, 3) = ""fox""
2914+
End Sub
2915+
";
2916+
var parseResult = Parse(code);
2917+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
2918+
}
2919+
2920+
[Category("Parser")]
2921+
[Test]
2922+
public void MidFunction()
2923+
{
2924+
const string code = @"
2925+
Public Sub Test()
2926+
Dim TestString As String
2927+
TestString = ""The dog jumps""
2928+
If Mid(TestString, 5, 3) = ""fox"" Then
2929+
MsgBox ""Found""
2930+
End If
2931+
End Sub
2932+
";
2933+
var parseResult = Parse(code);
2934+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
2935+
}
2936+
2937+
[Category("Parser")]
2938+
[Test]
2939+
public void MidDollarFunction()
2940+
{
2941+
const string code = @"
2942+
Public Sub Test()
2943+
Dim TestString As String
2944+
TestString = ""The dog jumps""
2945+
If Mid$(TestString, 5, 3) = ""fox"" Then
2946+
MsgBox ""Found""
2947+
End If
2948+
End Sub
2949+
";
2950+
var parseResult = Parse(code);
2951+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
2952+
}
2953+
2954+
[Category("Parser")]
2955+
[Test]
2956+
public void MidBFunction()
2957+
{
2958+
const string code = @"
2959+
Public Sub Test()
2960+
Dim TestString As String
2961+
TestString = ""The dog jumps""
2962+
If MidB(TestString, 5, 3) = ""fox"" Then
2963+
MsgBox ""Found""
2964+
End If
2965+
End Sub
2966+
";
2967+
var parseResult = Parse(code);
2968+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
2969+
}
2970+
2971+
[Category("Parser")]
2972+
[Test]
2973+
public void MidBDollarFunction()
2974+
{
2975+
const string code = @"
2976+
Public Sub Test()
2977+
Dim TestString As String
2978+
TestString = ""The dog jumps""
2979+
If MidB$(TestString, 5, 3) = ""fox"" Then
2980+
MsgBox ""Found""
2981+
End If
2982+
End Sub
2983+
";
2984+
var parseResult = Parse(code);
2985+
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 0);
2986+
}
2987+
28772988
private Tuple<VBAParser, ParserRuleContext> Parse(string code, PredictionMode predictionMode = null)
28782989
{
28792990
var stream = new AntlrInputStream(code);

0 commit comments

Comments
 (0)