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

Viewed 289

I'm looking for a parser that would try to use the first parser, and return Left a if it succeeds, or if it fails try the second parser and return Right b. In other words, something with the signature:

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

Where, e.g., type Parser a = P.Parsec String () a

It's not particularly hard to implement it on my own:

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

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

0 Answers
Related