[Haskell-cafe] A parsec question

Ben Franksen ben.franksen at online.de
Wed Sep 29 11:50:41 EDT 2010

I have a question about Parsec. The following program

> import Control.Applicative ((*>),(<*))
> import Text.Parsec
> import Text.Parsec.Char
> block p = char '{' *> p <* char '}'
> parser = block (many digit)
> main = parseTest parser "{123a}"

gives the output

  parse error at (line 1, column 5):
  unexpected "a"
  expecting "}"

Note the last line mentions only '}'. I would rather like to see

  expecting "}" or digit

since the parser could very well accept another digit here.

(1) What is the reason for this behaviour?
(2) Is there another combinator that behaves as I would like?
(3) Otherwise, how do I write one myself?

BTW, I am using parsec-3.1.0 and ghc-6.12.3.


More information about the Haskell-Cafe mailing list