Skip to content

Commit 8ec9b6d

Browse files
committed
Minor and Major cleanup inside Rubberduck.RegexAssistant
1 parent 68b2c2c commit 8ec9b6d

File tree

4 files changed

+8
-85
lines changed

4 files changed

+8
-85
lines changed

Rubberduck.RegexAssistant/Atom.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public CharacterClass(string specifier)
2626
Match m = Matcher.Match(specifier);
2727
if (!m.Success)
2828
{
29+
// TODO: i18n
2930
throw new ArgumentException("The given specifier does not denote a character class");
3031
}
3132
this._specifier = specifier;
@@ -54,14 +55,12 @@ private IList<string> ExtractCharacterSpecifiers(string characterClass)
5455
{
5556
if (specifier.Value.EndsWith("-\\"))
5657
{
57-
// BOOM!
58+
// TODO: i18n
5859
throw new ArgumentException("Character Ranges that have incorrectly escaped characters as target are not allowed");
5960
}
6061
else if (specifier.Value.Length == 1)
6162
{
62-
// fun... we somehow got to grab a single backslash. Pattern is probably broken
63-
// alas for simplicity we just skip the incorrect backslash
64-
// TODO: make a warning from this.. how?? no idea
63+
// Something's bork with the Pattern. For now we skip this it shouldn't affect anyone
6564
continue;
6665
}
6766
}
@@ -113,6 +112,7 @@ public Group(string specifier) {
113112
Match m = Matcher.Match(specifier);
114113
if (!m.Success)
115114
{
115+
// TODO i18n
116116
throw new ArgumentException("The given specifier does not denote a Group");
117117
}
118118
_subexpression = RegularExpression.Parse(m.Groups["expression"].Value);
@@ -134,7 +134,6 @@ public string Description
134134
get
135135
{
136136
return string.Format(AssistantResources.AtomDescription_Group, _specifier);
137-
//+"\r\n" + _subexpression.Description
138137
}
139138
}
140139

@@ -185,6 +184,7 @@ public Literal(string specifier)
185184
Match m = Matcher.Match(specifier);
186185
if (!m.Success)
187186
{
187+
// TODO: i18n
188188
throw new ArgumentException("The given specifier does not denote a Literal");
189189
}
190190
_specifier = specifier;

Rubberduck.RegexAssistant/IRegularExpression.cs

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Rubberduck.RegexAssistant.Extensions;
22
using Rubberduck.RegexAssistant.i18n;
3-
using System;
43
using System.Collections.Generic;
54
using System.Linq;
65
using System.Text.RegularExpressions;
@@ -29,7 +28,6 @@ public string Description
2928
get
3029
{
3130
return AssistantResources.ExpressionDescription_ConcatenatedExpression;
32-
//return string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description));
3331
}
3432
}
3533

@@ -66,7 +64,6 @@ public string Description
6664
get
6765
{
6866
return AssistantResources.ExpressionDescription_AlternativesExpression;
69-
// + Environment.NewLine + string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description))
7067
}
7168
}
7269

@@ -229,7 +226,6 @@ private static IRegularExpression ParseIntoConcatenatedExpression(ref string spe
229226
int oldSpecifierLength = currentSpecifier.Length + 1;
230227
while (currentSpecifier.Length > 0 && currentSpecifier.Length < oldSpecifierLength)
231228
{
232-
// Fugly hack for an error-return
233229
oldSpecifierLength = currentSpecifier.Length;
234230
IRegularExpression expression;
235231
// we actually have an AlternativesExpression, return the current status to Parse after updating the specifier
@@ -300,77 +296,5 @@ internal static bool TryParseAsAtom(ref string specifier, out IRegularExpression
300296
expression = null;
301297
return false;
302298
}
303-
304-
/// <summary>
305-
/// Makes the given specifier with the given pipeIndices into an AlternativesExpression
306-
/// </summary>
307-
/// <param name="pipeIndices">The indices of Alternative-indicating pipes on the current expression level</param>
308-
/// <param name="specifier">The specifier to split into subexpressions</param>
309-
/// <returns>An AlternativesExpression consisting of the split alternatives in the specifier, in order of encounter</returns>
310-
private static IRegularExpression ParseIntoAlternativesExpression(List<int> pipeIndices, string specifier)
311-
{
312-
List<IRegularExpression> expressions = new List<IRegularExpression>();
313-
string currentRemainder = specifier;
314-
for (int i = pipeIndices.Count - 1; i > 0; i--)
315-
{
316-
expressions.Add(Parse(currentRemainder.Substring(pipeIndices[i] + 1)));
317-
currentRemainder = currentRemainder.Substring(0, pipeIndices[i] - 1);
318-
}
319-
expressions.Reverse(); // because we built them from the back
320-
return new AlternativesExpression(expressions);
321-
}
322-
323-
324-
/// <summary>
325-
/// Finds all Pipes in the given specifier that are not escaped
326-
/// </summary>
327-
/// <param name="specifier">the regex specifier to search for unescaped pipes</param>
328-
/// <returns>A list populated with the indices of all pipes</returns>
329-
private static List<int> GrabPipeIndices(string specifier)
330-
{
331-
// FIXME: Check assumptions:
332-
// - | is never encountered at index 0
333-
// - | is never preceded by \\
334-
335-
if (!specifier.Contains("|")) {
336-
return new List<int>();
337-
}
338-
int currentIndex = 0;
339-
List<int> result = new List<int>();
340-
while (true)
341-
{
342-
currentIndex = specifier.IndexOf("|", currentIndex);
343-
if(currentIndex == -1)
344-
{
345-
break;
346-
}
347-
// ignore escaped literals
348-
// FIXME this is still a little too naive, since we could actually have something like "\\\|", which means that | is escaped again, but it should suffice for now
349-
if (currentIndex == 0 || !specifier.Substring(currentIndex - 1, 2).Equals("\\|")
350-
|| (currentIndex > 1 && specifier.Substring(currentIndex -2, 2).Equals("\\\\")))
351-
{
352-
result.Add(currentIndex);
353-
}
354-
}
355-
return result;
356-
}
357-
358-
/// <summary>
359-
/// Weeds out pipe indices that do not signify alternatives at the current "top level" from the given String.
360-
/// </summary>
361-
/// <param name="pipeIndices">indices of unescaped pipes in the given specifier</param>
362-
/// <param name="specifier">the regex specifier under scrutiny</param>
363-
internal static void WeedPipeIndices(ref List<int> pipeIndices, string specifier)
364-
{
365-
if (pipeIndices.Count == 0)
366-
{
367-
return;
368-
}
369-
foreach (int pipeIndex in pipeIndices)
370-
{
371-
// must not be between () or [] braces, else we just weed it out
372-
373-
}
374-
}
375299
}
376300
}

Rubberduck.RegexAssistant/Quantifier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Quantifier
1212
public readonly int MinimumMatches;
1313
public readonly int MaximumMatches;
1414

15+
// FIXME i18n ? Shouldn't ever show up actually...
1516
public Quantifier(string expression)
1617
{
1718
if (expression.Length == 0)
@@ -26,7 +27,7 @@ public Quantifier(string expression)
2627
Match m = Matcher.Match(expression);
2728
if (!m.Success)
2829
{
29-
throw new ArgumentException(String.Format("Cannot extract a Quantifier from the expression {1}", expression));
30+
throw new ArgumentException(string.Format("Cannot extract a Quantifier from the expression {1}", expression));
3031
}
3132
int minimum;
3233
// shouldn't ever happen
@@ -93,8 +94,7 @@ public override bool Equals(object obj)
9394

9495
public override int GetHashCode()
9596
{
96-
// FIXME get a proper has function
97-
return base.GetHashCode();
97+
return MinimumMatches ^ MaximumMatches ^ Kind.GetHashCode();
9898
}
9999

100100
public override string ToString()

Rubberduck.RegexAssistant/QuantifierExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public static string HumanReadable(this Quantifier quant)
3030
return string.Format(AssistantResources.Quantifier_OpenRange, quant.MinimumMatches);
3131
}
3232
return string.Format(AssistantResources.Quantifier_ClosedRange, quant.MinimumMatches, quant.MaximumMatches);
33-
3433
}
3534
return "";
3635
}

0 commit comments

Comments
 (0)