4
votes

When trying to parse {asdc,456,ghji,abc} and I run

run specialListParser "{asdc,456,ghji,abc}"

the parser fails with

The error occurred at the end of the input stream.
Expecting: any char not in ‘,’, ',' or '}'

I defined my parser based on this answer:

let str : Parser<_> = many1Chars (noneOf ",")
let comma = pstring ","
let listParser = sepBy str comma

let specialListParser = between (pstring "{") (pstring "}") listParser

What am I missing?

1
"Not working" is not a good description of a problem. - Fyodor Soikin
Please be more specific than "not working". What error message are you getting? Try implementing the test function from this section of the FParsec tutorial and run test specialListParser "{def,ghi,jkl}". What does it output? - rmunn
Basically, you haven't yet provided a minimal, complete and verifiable example to demonstrate your precise problem, and it's going to be hard to give you useful answers until you tell us more. - rmunn
Now that I see what your error message was, I was able to reproduce the problem myself, and fix it. - rmunn

1 Answers

5
votes

Looks like your str parser is consuming the final }, so that between never gets to see it. Change your str parser to be many1Chars (noneOf ",}") and it should work.

Alternately, noneOf [','; '}'] would also work, and might be more explicit about your intentions.