You should replace rep
with rep1
.
rep
is always successful (unless it is an Error
), so in rep(char) | token
right part (token
) is useless - you'll get an empty successful result of rep(char)
.
Also, you could either replace """[a-z]""".r
with accept('a' to 'z')
or define str
as def str: Parser[String] = """[a-z]+""".r
. Usage of Regex
to match a single Char
is an overkill.