namespace Jtr.Parsing; public abstract class ParsableStream { private readonly ReadOnlyMemory _tokens; protected ReadOnlySpan Tokens => _tokens.Span; protected int Position { get; set; } public T Current => Position < Tokens.Length ? Tokens[Position] : default!; protected ParsableStream(ReadOnlyMemory 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; } }