Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TokenStream no longer implements IEnumerable<Token>.

  • Loading branch information...
commit bf54d88f3d54fe108297ab290b4160e820aa54d5 1 parent 5bbd8f1
@plioi authored
View
11 src/Parsley.Test/TokenStreamTests.cs
@@ -131,16 +131,5 @@ public void ProvidesPositionOfCurrentToken()
tokens.Advance().Advance().Advance().Position.Line.ShouldEqual(1);
tokens.Advance().Advance().Advance().Position.Column.ShouldEqual(10);
}
-
- [Fact]
- public void CanBeEnumerated()
- {
- var tokens = new TokenStream(Tokens()).ToArray();
- tokens.Length.ShouldEqual(4);
- tokens[0].ShouldEqual(upper, "ABC", 1, 1);
- tokens[1].ShouldEqual(lower, "def", 1, 4);
- tokens[2].ShouldEqual(upper, "GHI", 1, 7);
- tokens[3].ShouldEqual(TokenKind.EndOfInput, "", 1, 10);
- }
}
}
View
14 src/Parsley/ParsingAssertions.cs
@@ -72,7 +72,15 @@ private static Reply<T> Succeeds<T>(this Reply<T> reply)
public static Reply<T> LeavingUnparsedTokens<T>(this Reply<T> reply, params string[] expectedLiterals)
{
- var actualLiterals = reply.UnparsedTokens.Where(x => x.Kind != TokenKind.EndOfInput).Select(x => x.Literal).ToArray();
+ var stream = reply.UnparsedTokens;
+
+ var actualLiterals = new List<string>();
+
+ while (stream.Current.Kind != TokenKind.EndOfInput)
+ {
+ actualLiterals.Add(stream.Current.Literal);
+ stream = stream.Advance();
+ }
Action raiseError = () =>
{
@@ -81,10 +89,10 @@ public static Reply<T> LeavingUnparsedTokens<T>(this Reply<T> reply, params stri
String.Join(", ", actualLiterals));
};
- if (actualLiterals.Length != expectedLiterals.Length)
+ if (actualLiterals.Count != expectedLiterals.Length)
raiseError();
- for (int i = 0; i < actualLiterals.Length; i++)
+ for (int i = 0; i < actualLiterals.Count; i++)
if (actualLiterals[i] != expectedLiterals[i])
raiseError();
View
19 src/Parsley/TokenStream.cs
@@ -1,10 +1,9 @@
using System;
-using System.Collections;
using System.Collections.Generic;
namespace Parsley
{
- public class TokenStream : IEnumerable<Token>
+ public class TokenStream
{
private readonly Token current;
private readonly Lazy<TokenStream> rest;
@@ -59,21 +58,5 @@ private TokenStream LazyAdvance(IEnumerator<Token> enumerator)
return new TokenStream(new Token(TokenKind.EndOfInput, endPosition, ""));
}
-
- public IEnumerator<Token> GetEnumerator()
- {
- var head = Current;
-
- yield return head;
-
- if (head.Kind != TokenKind.EndOfInput)
- foreach (var token in Advance())
- yield return token;
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.