I believe you want to use sepBy
.
type AST = | Arguments of AST list | Argument of string * string let parseArguments = spaces >>. pchar '(' >>. spaces >>. sepBy parseArgument (pchar ',') .>> spaces .>> pchar ')' |>> Arguments
Edited by devoured_elysium:
The above code is correct, although it does not compile. I will post my compilation version here, so if someone just wants to try the code without further ado, they can do it.
type AST = | Arguments of AST list | Argument of string let parseArguments = spaces >>. pchar '(' >>. spaces >>. sepBy (many1Satisfy isLetter |>> Argument) (pchar ',') .>> spaces .>> pchar ')' |>> Arguments test parseArguments "(a,b,c)" //succeed test parseArguments "(a,b,c,)" //fail
source share