Closed
Description
It would be nice if we could get some context with parse failures, like Megaparsec label
In ParserT
, fail
is implemented as throwError
purescript-parsing/src/Text/Parsing/Parser.purs
Lines 132 to 138 in e801a0e
This suggests a cheap implementation strategy for label
, using catchError :: forall a. m a -> (e -> m a) -> m a
.
-- | If parsing fails inside this context, then prepend the String to the error String.
label :: forall m s a. Monad m => String -> ParserT s m a -> ParserT s m a
label preerror p = catchError p go
where go (ParseError err pos) = failWithPosition (preerror <> err) pos
Actually come to think of it, anyone can use this label
function without library support. Maybe I'll just do that.
I suppose if we wanted to make this more official and support it in the library, then we could change the error type to ParseError (NonEmptyList String) Position
and cons the errors up as we fail out of the parser.
Metadata
Metadata
Assignees
Labels
No labels