[Haskell-cafe] Parsec - Custom Fail
mwinter at brocku.ca
mwinter at brocku.ca
Tue May 5 11:38:35 EDT 2009
Thanks, but I want a nice solution not another, even more complicated, workaround.
On 5 May 2009 at 17:10, Martijn van Steenbergen wrote:
> 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