object Working extends App {
class Parser(string: String) extends StandardTokenParsers {
def value: Parser[Any] = numericLit
println(phrase(value)(new lexical.Scanner(string)))
}
new Parser("123")
}
返回:[1.4]解析:123
object NotWorking extends App {
class Parser(string: String) extends StandardTokenParsers {
def value: Parser[Any] = stringLit
println(phrase(value)(new lexical.Scanner(string)))
}
val p = new Parser("asd")
}
[1.1]失败:字符串文字预期
ASD ^
他想要什么?!
答案 0 :(得分:1)
字符串文字应该用引号括起来。以下几行可行:
val p1 = new Parser("'asd'")
val p2 = new Parser("\"asd\"")