[Haskell-cafe] Optional EOF in Parsec.

Kannan Goundan kannan at cakoose.com
Fri Apr 3 21:17:08 EDT 2009

I'm writing a parser with Parsec.  In the input language, elements of a sequence
are separated by commas:

   [1, 2, 3]

However, instead of a comma, you can also use an EOL:

  [1, 2

Anywhere else, EOL is considered ignorable whitespace.  So it's not as simple as
just making EOL a token and looking for (comma | eol).

I've implemented this functionality in a hand-written parser (basically a hack
that keeps track of whether the last read token was preceded by an EOL,
without making EOL itself a token).  Does anybody have ideas about how to
do this with Parsec?

More information about the Haskell-Cafe mailing list