On Fri, Apr 3, 2009 at 8:17 PM, Kannan Goundan <kan...@cakoose.com> wrote: > > 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 > 3] > > Anywhere else, EOL is considered ignorable whitespace. So it's not as simple > as > just making EOL a token and looking for (comma | eol). >
Untested, but hopefully enough so you get an idea of where to start: > -- End of line parser. Consumes the carriage return, if present. > eol :: Parser () > eol = eof <|> char '\n' > -- list-element separator. > listSep :: Parser () > listSep = eol <|> (char ',' >> spaces) > -- list parser. The list may be empty - denoted by "[]" > myListOf :: Parser a -> Parser [a] > myListOf p = > char '[' >> > sepBy p listSep >>= \vals -> > char ']' >> > return vals This would probably be better off with a custom version of the 'spaces' parser that didn't parse newlines. Antoine _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe