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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to