Skip to content

Commit

Permalink
Added position to infinite loop exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMissal committed Jun 19, 2012
1 parent 8168ee8 commit 6c9a60b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Parsley.Test/GrammarTests.cs
Expand Up @@ -99,7 +99,7 @@ public void ApplyingARuleZeroOrMoreTimes()

Parser<Token> succeedWithoutConsuming = new LambdaParser<Token>(tokens => new Parsed<Token>(null, tokens));
Action infiniteLoop = () => ZeroOrMore(succeedWithoutConsuming).Parse(new TokenStream(Tokenize("")));
infiniteLoop.ShouldThrow<Exception>("Parser encountered a potential infinite loop.");
infiniteLoop.ShouldThrow<Exception>("Parser encountered a potential infinite loop at position (1, 1).");
}

[Fact]
Expand All @@ -123,7 +123,7 @@ public void ApplyingARuleOneOrMoreTimes()

Parser<Token> succeedWithoutConsuming = new LambdaParser<Token>(tokens => new Parsed<Token>(null, tokens));
Action infiniteLoop = () => OneOrMore(succeedWithoutConsuming).Parse(new TokenStream(Tokenize("")));
infiniteLoop.ShouldThrow<Exception>("Parser encountered a potential infinite loop.");
infiniteLoop.ShouldThrow<Exception>("Parser encountered a potential infinite loop at position (1, 1).");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Parsley/Primitives/ZeroOrMoreParser.cs
Expand Up @@ -23,7 +23,7 @@ public Reply<IEnumerable<T>> Parse(TokenStream tokens)
while (reply.Success)
{
if (oldPosition == newPosition)
throw new Exception("Parser encountered a potential infinite loop.");
throw new Exception(string.Format("Parser encountered a potential infinite loop at position {0}.", newPosition));

list.Add(reply.Value);
oldPosition = newPosition;
Expand Down

0 comments on commit 6c9a60b

Please sign in to comment.