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 theplusparser. The.repthen "creates" a parser that repeats theplusparser 0 to n times and concatenates the result into aSeq[Plus].Second, if using the repeat operation
rep,Parsers returnSeqand notListIf you really need a list, use map to convertSeqtoList.