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

2006-07-31 Thread Stephane Bortzmeyer
I'm trying to write a Parsec parser for a language which authorizes (this is a simplified example) a or a,b,c or a,c or a,b. (I can change the grammar but not the language.) The first attempt was: * CUT HERE import Text.ParserCombinators.Parsec import System (getArgs) comma = char ','

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

2006-07-31 Thread Matthias Fischmann
On Mon, Jul 31, 2006 at 09:04:32AM +0200, Stephane Bortzmeyer wrote: minilang = do char 'a' try (optional (do {comma ; char 'b'})) optional (do {comma ; char 'c'}) eof return OK parse error at (line 1, column 2): unexpected c expecting b

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

2006-07-31 Thread Udo Stenzel
Stephane Bortzmeyer wrote: minilang = do char 'a' try (optional (do {comma ; char 'b'})) optional (do {comma ; char 'c'}) eof return OK * CUT HERE *** parse error at (line 1, column 2): unexpected c expecting b Apparently,

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

2006-07-31 Thread Chris Kuklewicz
The semantics of Parsec's optional operation are what is causing the problem. optional foo can have 3 results: 1) foo can succeed, optional succeeds, proceed to next command 2) foo can fail without consuming any input, optional succeeds proceed to next command 3) foo can fail after