Skip to content

Commit

Permalink
Actually use the IScanner interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaubry committed Sep 18, 2015
1 parent fef040f commit 4a2ea9f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 11 additions & 2 deletions YamlDotNet/Core/IScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ Token Current
}

/// <summary>
/// Moves to the next token.
/// Moves to the next token and consumes the current token.
/// </summary>
/// <returns></returns>
bool MoveNext();

/// <summary>
/// Moves to the next token without consuming the current token.
/// </summary>
bool MoveNextWithoutConsuming();

/// <summary>
/// Consumes the current token.
/// </summary>
void ConsumeCurrent();
}
}
8 changes: 4 additions & 4 deletions YamlDotNet/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Parser : IParser
private readonly TagDirectiveCollection tagDirectives = new TagDirectiveCollection();
private ParserState state;

private readonly Scanner scanner;
private readonly IScanner scanner;
private ParsingEvent current;

private Token currentToken;
Expand All @@ -48,7 +48,7 @@ private Token GetCurrentToken()
{
if (currentToken == null)
{
while (scanner.InternalMoveNext())
while (scanner.MoveNextWithoutConsuming())
{
currentToken = scanner.Current;

Expand Down Expand Up @@ -78,7 +78,7 @@ public Parser(TextReader input)
/// <summary>
/// Initializes a new instance of the <see cref="Parser"/> class.
/// </summary>
public Parser(Scanner scanner)
public Parser(IScanner scanner)
{
this.scanner = scanner;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ private ParsingEvent ParseDocumentStart(bool isImplicit)

ParsingEvent evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
// Do not call skip here because that would throw an exception
if (scanner.InternalMoveNext())
if (scanner.MoveNextWithoutConsuming())
{
throw new InvalidOperationException("The scanner should contain no more tokens.");
}
Expand Down
6 changes: 3 additions & 3 deletions YamlDotNet/Core/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public bool MoveNext()
ConsumeCurrent();
}

return InternalMoveNext();
return MoveNextWithoutConsuming();
}

internal bool InternalMoveNext()
public bool MoveNextWithoutConsuming()
{
if (!tokenAvailable && !streamEndProduced)
{
Expand All @@ -141,7 +141,7 @@ internal bool InternalMoveNext()
/// <summary>
/// Consumes the current token and increments the parsed token count
/// </summary>
internal void ConsumeCurrent()
public void ConsumeCurrent()
{
++tokensParsed;
tokenAvailable = false;
Expand Down

0 comments on commit 4a2ea9f

Please sign in to comment.