Skip to content

Commit

Permalink
Fixes #4111
Browse files Browse the repository at this point in the history
  • Loading branch information
mansellan committed Jun 23, 2018
1 parent 487f9d3 commit 57e51f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Rubberduck.Parsing/Grammar/VBAParser.g4
Expand Up @@ -130,6 +130,7 @@ mainBlockStmt :
| ifStmt
| singleLineIfStmt
| implementsStmt
| midStatement
| letStmt
| lsetStmt
| onErrorStmt
Expand Down Expand Up @@ -462,9 +463,9 @@ redimVariableDeclaration : expression (whiteSpace asTypeClause)?;
// This needs to be explicitly defined to distinguish between Mid as a function and Mid as a keyword.
midStatement : modeSpecifier
LPAREN whiteSpace?
lExpression whiteSpace? COMMA whiteSpace? lExpression whiteSpace? (COMMA whiteSpace? lExpression whiteSpace?)?
lExpression whiteSpace? COMMA whiteSpace? expression whiteSpace? (COMMA whiteSpace? expression whiteSpace?)?
RPAREN
whiteSpace? ASSIGN whiteSpace?
whiteSpace? EQ whiteSpace?
expression;
modeSpecifier : (MID | MIDB) DOLLAR? ;

Expand Down
15 changes: 15 additions & 0 deletions RubberduckTests/Grammar/VBAParserTests.cs
Expand Up @@ -2859,6 +2859,21 @@ End Type
AssertTree(parseResult.Item1, parseResult.Item2, "//commentOrAnnotation", matches => matches.Count == 1);
}

[Category("Parser")]
[Test]
public void MidStatement()
{
const string code = @"
Public Sub Test()
Dim TestString As String
TestString = ""The dog jumps""
Mid(TestString, 5, 3) = ""fox""
End Sub
";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//midStatement", matches => matches.Count == 1);
}

private Tuple<VBAParser, ParserRuleContext> Parse(string code, PredictionMode predictionMode = null)
{
var stream = new AntlrInputStream(code);
Expand Down

0 comments on commit 57e51f3

Please sign in to comment.