Getting separatedBy to work in parboiled2

82 views Asked by At

This seems pretty simple!

class SeparatedParser(val input: ParserInput, val delimiter: String = ",") extends Parser {

  def pipedField = rule { (zeroOrMore(field).separatedBy("|")) }
  def field = rule { capture(zeroOrMore(noneOf(delimiter))) }

  def d = delimiter

  def record = rule {
    field ~ d ~ pipedField ~ d ~ field ~ EOI
  }
}

I try:

val parser = new SeparatedParser("""49798,piped1|piped2,sklw""")
val parsed = parser.record.run()
parsed match {
  case Success(rel) => println(rel)
  case Failure(pe:ParseError) =>println(parser.formatError(pe)) 
}

But I get:

49798 :: Vector(piped1|piped2) :: sklw :: HNil

I would expect the Vector to have two separate elements: piped1 and piped2.

What dumbass mistake am I making?

0

There are 0 answers