[Haskell-cafe] Parsing problem
daniel.is.fischer at web.de
Thu Jun 26 18:16:23 EDT 2008
Am Donnerstag, 26. Juni 2008 23:22 schrieb Eric:
> Daniel Fischer wrote:
> > Can't be exactly that, though because then removing sat (== Reserved ")")
> > shouldn't help.
> > Anyway, I need at least the failure message, better the complete code, to
> > diagnose.
> I've attached the complete code.
Thanks, though a plaintext file would've been better.
It's pretty much what I came up with myself, the odd thing is that I can't
reproduce your behaviour, whether sat (== Reserved ")") is present or not
doesn't make a difference. Which version of GHC and parsec are you using? (I
tried with 6.8.3 & parsec-184.108.40.206, 6.8.2 & parsec-220.127.116.11 and 6.6.1 &
parsec-2.0, all give the same results,
*Eric2> parseall . scanall $ "(_ineg_ 0)"
*** Exception: (line 1, column 1):unknown parse error
with or without the second sat).
However, the problem is indeed that upon failure (sat p) returns a Consumed
value (and removes the token from the input), make it
sat p = try $ do
(t,pos) <- item
if p t then return (t,pos) else pzero
and you're all set (you don't need the try's in atom, then).
More information about the Haskell-Cafe