Added End parser
This commit is contained in:
parent
3864fad99d
commit
c1eae9fa34
@ -222,3 +222,22 @@ func Map[In, Out1, Out2 any](p Parser[In, Out1], f func(Out1) Out2) Parser[In, O
|
||||
return Return[In](f(out))
|
||||
})
|
||||
}
|
||||
|
||||
func End[In any](s State[In]) (consumed bool, reply Result[In, struct{}], err error) {
|
||||
_, _, err = s.cursor.Read([]In{})
|
||||
if errors.Is(err, io.EOF) {
|
||||
reply := Result[In, struct{}]{
|
||||
State: s,
|
||||
Message: MessageOK(s.Pos()),
|
||||
}
|
||||
return true, reply, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, Result[In, struct{}]{}, fmt.Errorf("End: unexpected error: %w", err)
|
||||
}
|
||||
return false, Result[In, struct{}]{}, ParseError{
|
||||
Pos: s.Pos(),
|
||||
Got: "",
|
||||
Expected: []string{"end of input"},
|
||||
}
|
||||
}
|
||||
|
@ -90,3 +90,7 @@ func Try(t *testing.T) {
|
||||
func TestLabel(t *testing.T) {
|
||||
Todo(t)
|
||||
}
|
||||
|
||||
func TestEnd(t *testing.T) {
|
||||
Todo(t)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user