
Is there a way in Parsec to, within a parser, throw an error generated by another parser? For instance, something of type ParseError -> GenParser tok st a or whatever. -- Mark

On Thu, Dec 02, 2004 at 02:48:07PM +0000, Mark Carroll wrote:
Is there a way in Parsec to, within a parser, throw an error generated by another parser? For instance, something of type
ParseError -> GenParser tok st a
or whatever.
I guess no. I tried hard to find this about a month ago, but my best approximation was something like this: do setPosition (errorPos err) fail (messageString (head (errorMessages err))) which is very, very unsatisfying. It would be nice, if there were explicit functions in Parsec for this and also: instance Control.Monad.Error.MonadError ParseError (GenParser tok st) ... Best regards, Tomasz

Mark Carroll writes:
Is there a way in Parsec to, within a parser, throw an error generated by another parser?
How about wrapping the ParseError into your result type? Like this: data Foo = Bar String | ... | BadLuck ParseError Then you could run any number of parsers (with 'runParser') inside another parser and return their results and errors without needing any special support from the Parsec library. Peter

On Sun, Dec 05, 2004 at 07:36:07PM +0100, Peter Simons wrote:
Mark Carroll writes:
Is there a way in Parsec to, within a parser, throw an error generated by another parser?
How about wrapping the ParseError into your result type? Like this:
data Foo = Bar String | ... | BadLuck ParseError
Then you could run any number of parsers (with 'runParser') inside another parser and return their results and errors without needing any special support from the Parsec library.
But it will work against our intentions. For example, if you have try p1 <|> p2 and p1 returns (BadLuck err), than p2 won't be tried. p1 should *fail* with err. I feel that the amount of work to support this feature in Parsec is minimal. If I find some time tomorrow _and_ I find a way to experiment with Parsec's fptools repository, I will try to implement it. Best regards, Tomasz
participants (3)
-
Mark Carroll
-
Peter Simons
-
Tomasz Zielonka