Check that Slice has correct position after matching
This commit is contained in:
@ -31,30 +31,27 @@ func (pe ParseError) Error() string {
|
||||
return fmt.Sprintf("parse error: %d: %s", pe.Pos, pe.Got)
|
||||
}
|
||||
|
||||
type State[T any] struct {
|
||||
cursor cursor.Cursor[T]
|
||||
func MakeState[In any](c cursor.Cursor[In]) State[In] {
|
||||
return State[In]{cursor: c}
|
||||
}
|
||||
|
||||
func (s State[T]) Cursor() cursor.Cursor[T] {
|
||||
type State[In any] struct {
|
||||
cursor cursor.Cursor[In]
|
||||
}
|
||||
|
||||
func (s State[In]) Cursor() cursor.Cursor[In] {
|
||||
return s.cursor
|
||||
}
|
||||
|
||||
func (s State[T]) Read(dst []T) (n uint64, next State[T], err error) {
|
||||
func (s State[In]) Read(dst []In) (n uint64, next State[In], err error) {
|
||||
n, c, err := s.cursor.Read(dst)
|
||||
return n, State[T]{cursor: c}, err
|
||||
return n, State[In]{cursor: c}, err
|
||||
}
|
||||
|
||||
func (s State[T]) Pos() uint64 {
|
||||
func (s State[In]) Pos() uint64 {
|
||||
return s.cursor.Pos()
|
||||
}
|
||||
|
||||
func Parse[In, Out any](p Parser[In, Out], c cursor.Cursor[In]) (result Out, err error) {
|
||||
st := State[In]{cursor: c}
|
||||
var reply Result[In, Out]
|
||||
_, reply, err = p(st)
|
||||
return reply.Value, err
|
||||
}
|
||||
|
||||
type Parser[In, Out any] func(State[In]) (consumed bool, reply Result[In, Out], err error)
|
||||
|
||||
func Return[In, Out any](value Out) Parser[In, Out] {
|
||||
|
Reference in New Issue
Block a user