4

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?

Community
  • 1
  • 1
abhishek
  • 373
  • 1
  • 9
  • 3
    "Not working" is not a good description of a problem. – Fyodor Soikin Jan 16 '17 at 04:42
  • 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](http://www.quanttec.com/fparsec/tutorial.html#parsing-a-single-float) and run `test specialListParser "{def,ghi,jkl}"`. What does it output? – rmunn Jan 16 '17 at 07:04
  • Basically, you haven't yet provided a [minimal, complete and verifiable example](http://stackoverflow.com/help/mcve) to demonstrate your precise problem, and it's going to be hard to give you useful answers until you tell us more. – rmunn Jan 16 '17 at 07:05
  • Now that I see what your error message was, I was able to reproduce the problem myself, and fix it. – rmunn Jan 16 '17 at 08:28

1 Answers1

5

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.

rmunn
  • 34,942
  • 10
  • 74
  • 105
  • @rumnn thanks for reply. your suggestion solves the successful scenario, but its not giving for negative scenarios (where parser should have thrown error). – abhishek Jan 16 '17 at 09:30
  • I don't understand what you mean by "its not giving for negative scenarios". Could you rephrase that? Or give an example of an input where the parser *should* have thrown an error, but didn't? – rmunn Jan 16 '17 at 09:43
  • @rumn please ignore my previous comment. – abhishek Jan 16 '17 at 10:19