Raise ParseError in Haskell / Parsec

What is the preferred way to raise errors ( ParseError ) in Parsec? I got code inside the parser that performs the check, and if the check fails, then the ParseError should be returned (i.e. Left ParseError when starting parse ).

+6
parsing haskell parsec
source share
1 answer

You can use Text.ParserCombinators.Parsec.Prim.unexpected and Control.Monad.fail for this. Both take a String argument indicating the error message and return (in this case) a GenParser tok st a value.

For details, see Text.ParserCombinators.Parsec.Error , in particular Message . There you can read which function to use in this case (although both mean a parsing error, they are semantically slightly different).

+5
source share

All Articles