3

I have an user input text like "abc,def,ghi". I want to parse it to get list of string as ["abc", "def"].

I tried

let str : Parser<_> = many1Chars (noneOf ",")
let listParser : Parser<_> = many (str);;

but it always give me the first item only ["abc"]. "Def" and others are not coming in result list

TeaDrivenDev
  • 6,591
  • 33
  • 50
abhishek
  • 373
  • 1
  • 9

1 Answers1

3

You're parsing up to the first comma, but not parsing the comma itself.

To parse a list of things separated by other things, use sepBy:

let comma = pstring ","
let listParser = sepBy str comma

If you need to parse "at least one", use sepBy1 instead.

Fyodor Soikin
  • 78,590
  • 9
  • 125
  • 172