2
我在寫一個cron解析器,但編譯器抱怨非法規則組合,parboiled2非法規則組合
我的解析器出了什麼問題?
import org.parboiled2._
sealed trait Part
case class Fixed(points: Seq[Int]) extends Part
case class Range(start: Int, end: Int) extends Part
case class Every(start: Int, interval: Int) extends Part
case object Full extends Part
case object Ignore extends Part
class CronParser(val input: ParserInput) extends Parser {
def number = rule { capture(digits) ~> (_.toInt) }
def digits = rule { oneOrMore(CharPredicate.Digit) }
def fixed = rule { oneOrMore(number).separatedBy(",") ~> Fixed }
def range = rule { digits ~ '-' ~ digits ~> Range }
def every= rule { digits ~ '/' ~ digits ~> Every }
def full= rule { '*' ~ push(Full) }
def ignore = rule { '?' ~ push(Ignore) }
def part = rule { fixed | range | every | full | ignore }
def expr = rule { part ~ part ~ part ~ part ~ part}
}