All checks were successful
Run the JSON parser tests / test (push) Has been skipped
32 lines
778 B
C#
32 lines
778 B
C#
namespace Jtr.Parsing;
|
|
|
|
public abstract class ParsableStream<T>
|
|
{
|
|
private readonly ReadOnlyMemory<T> _tokens;
|
|
|
|
protected ReadOnlySpan<T> Tokens => _tokens.Span;
|
|
|
|
protected int Position { get; set; }
|
|
|
|
public T Current => Position < Tokens.Length ? Tokens[Position] : default!;
|
|
|
|
protected ParsableStream(ReadOnlyMemory<T> tokens)
|
|
{
|
|
_tokens = tokens;
|
|
}
|
|
|
|
public virtual T Advance()
|
|
{
|
|
return Position + 1 <= Tokens.Length ? Tokens[++Position - 1] : default!;
|
|
}
|
|
|
|
public virtual T Peek(int offset = 0)
|
|
{
|
|
return Position + offset < Tokens.Length ? Tokens[Position + offset] : default!;
|
|
}
|
|
|
|
public virtual bool Ended()
|
|
{
|
|
return Position >= Tokens.Length;
|
|
}
|
|
} |