mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-15 00:15:47 +08:00
Preparations for the 1.0 release
* Less cluttered solution layout. * Move examples to a repository of its own. * Move Roslyn analyzer to a repository of its own. * Enable central package management. * Clean up csproj files. * Add README file to NuGet packages.
This commit is contained in:
committed by
Patrik Svensson
parent
bb72b44d60
commit
42fd801876
55
src/Extensions/Spectre.Console.Json/JsonTokenReader.cs
Normal file
55
src/Extensions/Spectre.Console.Json/JsonTokenReader.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace Spectre.Console.Json;
|
||||
|
||||
internal sealed class JsonTokenReader
|
||||
{
|
||||
private readonly List<JsonToken> _reader;
|
||||
private readonly int _length;
|
||||
|
||||
public int Position { get; private set; }
|
||||
public bool Eof => Position >= _length;
|
||||
|
||||
public JsonTokenReader(List<JsonToken> tokens)
|
||||
{
|
||||
_reader = tokens;
|
||||
_length = tokens.Count;
|
||||
|
||||
Position = 0;
|
||||
}
|
||||
|
||||
public JsonToken Consume(JsonTokenType type)
|
||||
{
|
||||
var read = Read();
|
||||
if (read == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not read token");
|
||||
}
|
||||
|
||||
if (read.Type != type)
|
||||
{
|
||||
throw new InvalidOperationException($"Expected '{type}' token, but found '{read.Type}'");
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
public JsonToken? Peek()
|
||||
{
|
||||
if (Eof)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _reader[Position];
|
||||
}
|
||||
|
||||
public JsonToken? Read()
|
||||
{
|
||||
if (Eof)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Position++;
|
||||
return _reader[Position - 1];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user