Skip to content

Commit 1ab7f46

Browse files
committed
Fix more issues with bang notation and its fix
1 parent cfd4060 commit 1ab7f46

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Rubberduck.Parsing/Grammar/VBAParser.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ subscript : (expression whiteSpace TO whiteSpace)? expression;
579579

580580
unrestrictedIdentifier : identifier | statementKeyword | markerKeyword;
581581
legalLabelIdentifier : { !(new[]{DOEVENTS,END,CLOSE,ELSE,LOOP,NEXT,RANDOMIZE,REM,RESUME,RETURN,STOP,WEND}).Contains(_input.La(1))}? identifier | markerKeyword;
582-
identifier : {_input.La(3) != IDENTIFIER}? typedIdentifier | untypedIdentifier;
582+
identifier : {_input.La(3) != IDENTIFIER && _input.La(3) != L_SQUARE_BRACKET || _input.La(1) == L_SQUARE_BRACKET}? typedIdentifier
583+
| untypedIdentifier;
583584
untypedIdentifier : identifierValue;
584585
typedIdentifier : untypedIdentifier typeHint;
585586
identifierValue : IDENTIFIER | keyword | foreignName;

RubberduckTests/Grammar/VBAParserTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,35 @@ End Sub
29532953
var parseResult = Parse(code);
29542954
}
29552955

2956+
[Category("Parser")]
2957+
[Test]
2958+
public void ParserDoesNotFailDoubleBracketForgeignIdentifierWithTypeHint()
2959+
{
2960+
const string code = @"
2961+
Sub Test()
2962+
Dim x
2963+
x = [[bar]]!
2964+
End Sub
2965+
";
2966+
var parseResult = Parse(code);
2967+
AssertTree(parseResult.Item1, parseResult.Item2, "//typeHint", matches => matches.Count == 1);
2968+
}
2969+
2970+
[Category("Parser")]
2971+
[Test]
2972+
public void ParserDoesNotFailOnBangOperatorFollowedByForeignIdentifier()
2973+
{
2974+
const string code = @"
2975+
Sub Test()
2976+
Dim dict As Scripting.Dictionary
2977+
2978+
Dim x
2979+
x = dict![a]
2980+
End Sub
2981+
";
2982+
var parseResult = Parse(code);
2983+
}
2984+
29562985
[Category("Parser")]
29572986
[Test]
29582987
public void ParserDoesNotFailOnBangOperator()

0 commit comments

Comments
 (0)