I would expect the result for plusses to be some kind of array
case class Plus()
val plus: P[Plus] = P ("+") map {_ => Plus()}
val plusses: P[List[Plus]] = P ( plus.rep.! ) // type mismatch; found: Parser[String] required: Parser[List[Plus]]
but compiler says
type mismatch; found : Parser[String] required: Parser[List[Plus]]
Answer
First, you don't need to capture something with
.!
as you already have a result in theplus
parser. The.rep
then "creates" a parser that repeats theplus
parser 0 to n times and concatenates the result into aSeq[Plus]
.Second, if using the repeat operation
rep
,Parser
s returnSeq
and notList
If you really need a list, use map to convertSeq
toList
.