Is there a built-in or parser in the Parsec library?

I'm looking for a parser that will try to use the first parser, and will return Left a

if it succeeds, or if it doesn't work, try the second parser and return Right b

. In other words, something with a signature:

Parser a -> Parser b -> Parser (Either a b)

      

Where, for example, type Parser a = P.Parsec String () a

It's not particularly hard to implement this yourself:

parseEither pa pb = (Left <$> pa) <|> (Right <$> pb)

      

But it seems to be such a useful and trivial construct that I was wondering if something like this already exists in the Parsec library.

+3


source to share





All Articles