[Haskell-cafe] Parsec combinator like Prolog's cut operator?
Stephen Tetley
stephen.tetley at gmail.com
Wed Jun 30 03:05:56 EDT 2010
Hi Erik
Malcolm Wallace describes a commit combinator in the paper "Partial
parsing: combining choice with commitment" which sounds like what you
would want. It is implemented for Polyparse rather than Parsec though.
>From a quick scan of the paper and code, the implementation appears to
be built into the Parser type, so it is a primitive rather than a
definable combinator.
If your Parsec parser uses try because it is not especially
left-factored, one extra combinator I have found useful for
left-factoring on the cheap is optionalSuffix:
optionalSuffix :: (a -> c) -> (a -> b -> c) -> Parser a -> Parser b
-> Parser c
optionalSuffix f g pbody psuffix = do
a <- pbody
mb_b <- optionMaybe psuffix
return $ maybe (f a) (\b -> g a b) mb_b
More information about the Haskell-Cafe
mailing list