[Haskell-cafe] Re: [Parsec] Backtracking with try does not work for me?

Stephane Bortzmeyer bortzmeyer at nic.fr
Mon Jul 31 17:08:56 EDT 2006

On Mon, Jul 31, 2006 at 06:51:27PM +0100,
 Chris Kuklewicz <haskell at list.mightyreason.com> wrote 
 a message of 102 lines which said:

>minilang = do
>       char 'a'
>       optional (try (do {comma ; char 'b'}))
>       optional (do {comma ; char 'c'})
>       eof
>       return "OK"

I now have a new problem which was hidden beneath. If the language
authorizes "a,bb" and "a,bbc", "a,bbc" is not accepted by my parser
since it already accepted "a,bb" and the "c" which is left triggers a
syntax error.

This time, "try" believes it succeeded but should not. I need more
look-ahead but I'm not sure how?

(Again, I do not control the language so I cannot make it more

More information about the Haskell-Cafe mailing list