[Haskell] Parsec question: attempted 'notMatching' combinator

Andrew Pimlott andrew at pimlott.net
Wed Feb 18 01:11:31 EST 2004


On Tue, Feb 17, 2004 at 04:57:34PM -0500, Andrew Pimlott wrote:
> What about a more prosaic implementation:
> 
>     notFollowedBy' :: Show a => GenParser tok st a -> GenParser tok st ()
>     notFollowedBy' p    = do  res <-  do a <- try p; return $ Just a
>                                       <|>
>                                       return Nothing
>                               case res of Just a  -> unexpected (show a)
>                                           Nothing -> return ()

After some pondering and fiddling, a version I like:

    notFollowedBy' :: Show a => GenParser tok st a -> GenParser tok st ()
    notFollowedBy' p    = join $  do a <- try p; return (unexpected (show a))
                                  <|>
                                  return (return ())

Andrew


More information about the Haskell mailing list