[Haskell] Parsec question: attempted 'notMatching' combinator
Andrew Pimlott
andrew at pimlott.net
Wed Feb 18 09:49:43 EST 2004
On Wed, Feb 18, 2004 at 02:45:15PM +0100, Daan Leijen wrote:
> On Wed, 18 Feb 2004 01:11:31 -0500, Andrew Pimlott <andrew at pimlott.net>
> wrote:
> >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 ())
>
> Great work. Do you think that the library function should
> be fixed with this version? (or can you check it in yourself?)
Thanks! There is one catch: I followed Graham's idea of generalizing
the signature (which is orthogonal to my fix). As per earlier mails,
the signature of the current notFollowedBy
notFollowedBy :: Show tok => GenParser tok st tok -> GenParser tok st ()
notFollowedBy p = try (do{ c <- p; unexpected (show [c]) }
<|> return ()
)
is rather curious--<TV lawyer>as if the author knew about the problem,
and required a parser returning tok so no-one would notice</TV lawyer>.
Actually, maybe the reason is error reporting. Graham's "show a" might
be confusing (who knows whether a is anything like a representation of
the input?). It seems you'd like to grab the Expect message out of p,
but I'm not sure if this is possible.
Also, in the tok case, there is a small change in the error message (c
vs [c]).
Even if these are not fixible, they seem to me minor problems compared
with the benefit of a more general type. So I'm happy with my version
as written.
I'm not set up to check it in, so you should probably do it. Don't
forget that there is a copy of the code in the documentation.
Andrew
More information about the Haskell
mailing list