Skip to content

Commit 73341f6

Browse files
committed
Added ErrorExpression to provide feedback for malformed Expressions
1 parent bbcd278 commit 73341f6

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

RetailCoder.VBE/UI/RegexAssistant/RegexAssistantViewModel.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Rubberduck.RegexAssistant;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Threading.Tasks;
54
using System.Windows.Controls;
65

76
namespace Rubberduck.UI.RegexAssistant
@@ -99,8 +98,6 @@ public string DescriptionResults
9998

10099
private static TreeViewItem AsTreeViewItem(IRegularExpression expression)
101100
{
102-
var t = expression.GetType();
103-
104101
var result = new TreeViewItem();
105102
result.Header = "Some unknown IRegularExpression subtype was in the view";
106103
foreach (var subtree in expression.Subexpressions.Select(exp => AsTreeViewItem((dynamic)exp)))
@@ -110,6 +107,13 @@ private static TreeViewItem AsTreeViewItem(IRegularExpression expression)
110107
return result;
111108
}
112109

110+
private static TreeViewItem AsTreeViewItem(ErrorExpression expression)
111+
{
112+
var result = new TreeViewItem();
113+
result.Header = expression.Description;
114+
return result;
115+
}
116+
113117
private static TreeViewItem AsTreeViewItem(ConcatenatedExpression expression)
114118
{
115119
var result = new TreeViewItem();

Rubberduck.RegexAssistant/Atom.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public string Description
133133
{
134134
get
135135
{
136-
return string.Format(AssistantResources.AtomDescription_Group, _specifier) + "\r\n" + _subexpression.Description;
136+
return string.Format(AssistantResources.AtomDescription_Group, _specifier);
137+
//+"\r\n" + _subexpression.Description
137138
}
138139
}
139140

Rubberduck.RegexAssistant/IRegularExpression.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,40 @@ public override int GetHashCode()
139139

140140
}
141141

142+
public class ErrorExpression : IRegularExpression
143+
{
144+
private readonly string _errorToken;
145+
146+
public ErrorExpression(string errorToken)
147+
{
148+
_errorToken = errorToken;
149+
}
150+
151+
public string Description
152+
{
153+
get
154+
{
155+
return string.Format(AssistantResources.ExpressionDescription_ErrorExpression, _errorToken);
156+
}
157+
}
158+
159+
public Quantifier Quantifier
160+
{
161+
get
162+
{
163+
return new Quantifier(string.Empty);
164+
}
165+
}
166+
167+
public IList<IRegularExpression> Subexpressions
168+
{
169+
get
170+
{
171+
return new List<IRegularExpression>();
172+
}
173+
}
174+
}
175+
142176
internal static class RegularExpression
143177
{
144178

@@ -208,6 +242,11 @@ private static IRegularExpression ParseIntoConcatenatedExpression(ref string spe
208242
{
209243
subexpressions.Add(expression);
210244
}
245+
else if (currentSpecifier.Length == oldSpecifierLength)
246+
{
247+
subexpressions.Add(new ErrorExpression(currentSpecifier.Substring(0, 1)));
248+
currentSpecifier = currentSpecifier.Substring(1);
249+
}
211250
}
212251
specifier = ""; // we've exhausted the specifier, tell Parse about it to prevent infinite looping
213252
return new ConcatenatedExpression(subexpressions);

Rubberduck.RegexAssistant/i18n/AssistantResources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.RegexAssistant/i18n/AssistantResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@
192192
<data name="ExpressionDescription_ConcatenatedExpression" xml:space="preserve">
193193
<value>Matches the exact sequence given as follows:</value>
194194
</data>
195+
<data name="ExpressionDescription_ErrorExpression" xml:space="preserve">
196+
<value>Could not parse {0} as literal. Check your input, please</value>
197+
</data>
195198
<data name="PatternDescription_AnchorEnd" xml:space="preserve">
196199
<value>$ ensures all characters of the string are consumed</value>
197200
</data>

0 commit comments

Comments
 (0)