Fix position when an error occurs in `sat`.

master
Philippe Pittoli 2024-01-19 19:31:25 +01:00
parent bbb5c1c415
commit d4cbcb8b99
1 changed files with 4 additions and 2 deletions

View File

@ -121,8 +121,10 @@ try p = Parser p'
_ -> failureError position error _ -> failureError position error
sat :: forall e. (Char -> Boolean) -> Parser e Char sat :: forall e. (Char -> Boolean) -> Parser e Char
sat p = do x <- item sat p = do
if p x then pure x else empty pos <- current_position
x <- item
if p x then pure x else Parser \input -> failure pos
digit :: forall e. Parser e Char digit :: forall e. Parser e Char
digit = sat isDigit digit = sat isDigit