分开可以在parboiled2中工作

时间:2015-12-17 17:25:38

标签: scala parboiled2

这看起来很简单!

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
  }
}

我试试:

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)) 
}

但我明白了:

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

我希望Vector有两个独立的元素:piped1piped2

我做了什么笨蛋错误?

0 个答案:

没有答案