Skip to content

Commit

Permalink
Merge pull request #4838 from comintern/next
Browse files Browse the repository at this point in the history
Misc. fixes
  • Loading branch information
bclothier committed Mar 7, 2019
2 parents a770343 + 1e6e40d commit 1e3e615
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 3 deletions.
Expand Up @@ -43,7 +43,8 @@ public virtual void Synchronize(ref List<Declaration> updated)

var matching = updated.FirstOrDefault(decl =>
Declaration.DeclarationType == decl?.DeclarationType &&
Declaration.QualifiedName.Equals(decl.QualifiedName));
Declaration.QualifiedName.Equals(decl.QualifiedName) &&
(Declaration.ParentDeclaration is null || Declaration.ParentDeclaration.QualifiedName.Equals(decl.ParentDeclaration?.QualifiedName)));

if (matching is null)
{
Expand Down
Expand Up @@ -185,7 +185,7 @@
Command="{Binding BrowseCommand}">
<StackPanel Orientation="Horizontal">
<Image Margin="0,0,5,0" Height="16" Source="{StaticResource BrowseIcon}" />
<TextBlock Background="Transparent" Text="Browse..."></TextBlock>
<TextBlock Background="Transparent" Text="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=References_BrowseButtonText}" />
</StackPanel>
</Button>
<Grid Grid.Row="1" Margin="10,10,10,5">
Expand Down
5 changes: 4 additions & 1 deletion Rubberduck.Parsing/Grammar/VBAParser.g4
Expand Up @@ -416,8 +416,9 @@ elseBlock :
// 5.4.2.9 Single-line If Statement
singleLineIfStmt : ifWithNonEmptyThen | ifWithEmptyThen;
ifWithNonEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? listOrLabel (whiteSpace singleLineElseClause)?;
ifWithEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN endOfStatement? whiteSpace? singleLineElseClause;
ifWithEmptyThen : IF whiteSpace? booleanExpression whiteSpace? THEN whiteSpace? emptyThenStatement? singleLineElseClause;
singleLineElseClause : ELSE whiteSpace? listOrLabel?;

// lineNumberLabel should actually be "statement-label" according to MS VBAL but they only allow lineNumberLabels:
// A <statement-label> that occurs as the first element of a <list-or-label> element has the effect
// as if the <statement-label> was replaced with a <goto-statement> containing the same
Expand All @@ -427,7 +428,9 @@ listOrLabel :
lineNumberLabel (whiteSpace? COLON whiteSpace? sameLineStatement?)*
| (COLON whiteSpace?)? sameLineStatement (whiteSpace? COLON whiteSpace? sameLineStatement?)*
;

sameLineStatement : mainBlockStmt;
emptyThenStatement : (COLON whiteSpace?)+;
booleanExpression : expression;

implementsStmt : IMPLEMENTS whiteSpace expression;
Expand Down
18 changes: 18 additions & 0 deletions Rubberduck.Resources/RubberduckUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rubberduck.Resources/RubberduckUI.resx
Expand Up @@ -1549,4 +1549,7 @@ NOTE: Restart is required for the setting to take effect.</value>
<data name="Language_ES" xml:space="preserve">
<value>Español</value>
</data>
<data name="References_BrowseButtonText" xml:space="preserve">
<value>Browse...</value>
</data>
</root>
123 changes: 123 additions & 0 deletions RubberduckTests/Grammar/VBAParserTests.cs
Expand Up @@ -2046,6 +2046,129 @@ Sub Test()
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfSingleEmptyThenEmptyElse()
{
string code = @"
Sub Test()
If False Then:: Else:
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

public void TestSingleLineIfSingleMultipleEmptyThensEmptyElse()
{
string code = @"
Sub Test()
If False Then:: _
:Else:
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

public void TestSingleLineIfSingleMultipleEmptyThensElse()
{
string code = @"
Sub Test()
If False Then:: _
:Else Bar
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfSingleEmptyMultiLineThenEmptyElse()
{
string code = @"
Sub Test()
If False Then: _
: Else:
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfSingleEmptyThenEmptyMultiLineElse()
{
string code = @"
Sub Test()
If False Then Else _
:
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfSingleEmptyThenElse()
{
string code = @"
Sub Test()
If False Then Else _
: Bar
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfNestedEmptyThenEmptyElse()
{
string code = @"
Sub Test()
If True Then If False Then If True Then Else
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfNestedThenEmptyElse()
{
string code = @"
Sub Test()
If True Then If False Then If True Then Bar Else
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfNestedEmptyThenElse()
{
string code = @"
Sub Test()
If True Then If False Then If True Then Else Bar
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfSingleEmptyMultiLineThenEmptyMultiLineElse()
{
string code = @"
Sub Test()
If False Then: _
Else _
:
End Sub";
var parseResult = Parse(code);
AssertTree(parseResult.Item1, parseResult.Item2, "//singleLineIfStmt");
}

[Category("Parser")]
[Test]
public void TestSingleLineIfImplicitGoTo()
Expand Down

0 comments on commit 1e3e615

Please sign in to comment.