有没有更简洁的方法将字符串映射到解析器组合器中的枚举值?
object Mode extends Enumeration {
type Mode = Value
val View, Add, Modify, Delete = Value
}
import Mode._
object ModeParser extends JavaTokenParsers {
def mode: Parser[Mode] = ("^(" + Mode.values.mkString("|") + ")$").r ^^ {
Mode.withName(_)
}
}