Parsec question

Tomasz Zielonka t.zielonka at students.mimuw.edu.pl
Thu Jan 1 10:54:40 EST 2004


On Wed, Dec 31, 2003 at 07:21:54PM -0500, Mark Carroll wrote:
> I tried posting this before but, from my point of view, it vanished. My
> apologies if it's a duplicate.
> 
> In http://www.cs.uu.nl/~daan/download/parsec/parsec.html we read,
> 
> > testOr2 =   try (string "(a)")
> >         <|> string "(b)"
> >
> > or an even better version:
> >
> > testOr3 =   do{ try (string "(a"); char ')'; return "(a)" }
> >         <|> string "(b)"
> 
> Why is the latter better?

testOr3 is a bit better at error reporting, for example:

  *> parseTest testOr2 "(a"
  parse error at (line 1, column 1):
  unexpected "a"
  expecting "(b)"

  *> parseTest testOr3 "(a"
  parse error at (line 1, column 3):
  unexpected end of input
  expecting ")"

But it still gives silly error messages in some cases:

  *> parseTest testOr3 "("
  parse error at (line 1, column 1):
  unexpected end of input
  expecting "(b)"

The original testOr1 is better here:

  *> parseTest testOr1 "(a"
  parse error at (line 1, column 3):
  unexpected end of input
  expecting ")"

  *> parseTest testOr1 "("
  parse error at (line 1, column 2):
  unexpected end of input
  expecting "a" or "b"

  *> parseTest testOr1 ""
  parse error at (line 1, column 1):
  unexpected end of input
  expecting "("

> (BTW, I like Parsec. Thanks, Daan. (-:)

I like Parsec too :)

Tom

-- 
.signature: Too many levels of symbolic links


More information about the Haskell-Cafe mailing list