[Haskell-beginners] Parsec, comma sperated list with special last element
Nathan Hüsken
nathan.huesken at posteo.de
Sun Dec 16 17:55:53 CET 2012
Hey,
I want to parse a string like this:
<cell>,<cell>,<lastCell>
All cells but the last cell are parsed with "cell", the last one is
parsed with "lastCell".
So I am trying:
file = do
res <- endBy cell (char ',')
l <- lastCell
eof
return res
cell = many1 (noneOf ",")
lastCell = many1 (noneOf "\n")
This results in
unexpected end of input
expecting ","
I am assuming this is because the lastCell is comsumed by a "cell" parser.
lastCell and cell look pretty similar, so the cell parser can does not
fail when presented the <lastCell>.
Can I still do this with "endBy" or is there a better combinator?
Thanks!
Nathan
More information about the Beginners
mailing list