The problem is that the separator /
starts with a space, so the first parser is committing to parsing its separator and then the next digit.
You have a few options. You could change p1
so that it explicitly looks for a space and not an operator:
sepBy anyDigit (char ' ' <* notFollowedBy (char '/'))
Alternatively, have your lexemes eagerly consume any trailing whitespace:
myDigit = anyDigit <* many whitespace
p1 = many1 myDigit
p2 = sepBy p1 (char '/' <* many whitespace)
Another option is to split your parser into an initial lexing phase, which splits the input into lexemes, removing whitespace. Then you wouldn't be able to use string-parsers
, but purescript-parsing
would be able to work on the stream of tokens.