[Haskell-cafe] Parsec - Custom Fail
Martijn van Steenbergen
martijn at van.steenbergen.nl
Tue May 5 11:10:37 EDT 2009
mwinter at brocku.ca wrote:
> Hi,
>
> I am using parsec to parse a small programming language. The language is typed and
> I need to do some type checking, too. I have decided to do the parsing and type checking
> simultaneously in the my parsec parser. This approach avoids to keep source code positions
> in the data type in order to produce suitable error messages during type checking. Anyhow,
> because type errors are usually detected after parsing some code I need produce error
> messages with an earlier source position. Unfortunately, there is no function that produces
> an error taking a position as parameter.
If you already know what position you want to report the error at, then
why bother calling setPosition to let parsec know? Just do:
> fail (show pos ++ ": " ++ msg)
Parsec will then result in a ParseError with its own ideas of location,
but you can ignore that.
HTH,
Martijn.
More information about the Haskell-Cafe
mailing list