jtr/DevDisciples.Parsing/ParsableStream.cs
mdnapo 82a59eebd2 - Refactored code
- Implemented basic JSON Path interpreter
- Clean up
2024-09-22 16:30:31 +02:00

32 lines
787 B
C#

namespace DevDisciples.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;
}
}