Permalink
Browse files

MatchResult.Fail returns a static value instead of redundantly constr…

…ucting one for each failure.
  • Loading branch information...
1 parent 23908a1 commit 1f33f317398f04fbfc999d7755b0e81faf0e0a35 @plioi committed Mar 31, 2012
Showing with 6 additions and 9 deletions.
  1. +2 −5 src/Parsley/MatchResult.cs
  2. +1 −1 src/Parsley/Text.cs
  3. +2 −2 src/Parsley/TokenKind.cs
  4. +1 −1 src/Parsley/TokenRegex.cs
@@ -2,16 +2,13 @@ namespace Parsley
{
public class MatchResult
{
+ public static readonly MatchResult Fail = new MatchResult(false, "");
+
public static MatchResult Succeed(string value)
{
return new MatchResult(true, value);
}
- public static MatchResult Fail()
- {
- return new MatchResult(false, "");
- }
-
private MatchResult(bool success, string value)
{
Success = success;
View
@@ -63,7 +63,7 @@ public MatchResult Match(Predicate<char> test)
if (value.Length > 0)
return MatchResult.Succeed(value);
- return MatchResult.Fail();
+ return MatchResult.Fail;
}
private int Column
View
@@ -92,7 +92,7 @@ protected override MatchResult Match(Text text)
if (peek == symbol)
return MatchResult.Succeed(peek);
- return MatchResult.Fail();
+ return MatchResult.Fail;
}
}
@@ -103,7 +103,7 @@ public Empty(string name)
protected override MatchResult Match(Text text)
{
- return MatchResult.Fail();
+ return MatchResult.Fail;
}
}
}
@@ -22,7 +22,7 @@ public MatchResult Match(string input, int index)
if (match.Success)
return MatchResult.Succeed(match.Value);
- return MatchResult.Fail();
+ return MatchResult.Fail;
}
public override string ToString()

0 comments on commit 1f33f31

Please sign in to comment.