Apparently I'm too dumb to figure this out...
Consider the following string:
foobar(123, 456, 789)
I'm trying to work out how to parse this. In particular,
call = do
cs <- many1 letter
char '('
as <- many argument
return (cs, as)
argument = manyTill anyChar (char ',' <|> char ')')
This works perfectly, until I add stuff to the end of the input string, at which point it tries to parse that stuff as the next argument, and gets upset when it doesn't end with a comma or bracket.
Fundamentally, the trouble is that a comma is a separator, while a bracket is a terminator. Parsec doesn't appear to provide a combinator for that.
Just to make things more interesting, the input string can also be
foobar(123, 456, ...
which indicates that the message is incomplete. There appears to be no way of parsing a sequence with two possible terminators and knowing which one was found. (I actually want to know whether the argument list was complete or incomplete.)
Can anyone figure out how I climb out of this?
arguement = many1 (noneOf ",()")
– user2407038sepBy
andsepBy1
. Soarguement `sepBy` (char ',')
– user2407038foobar(123, 456, ...
orfoobar (123, 456, ...)
? – kosmikus