使用此代码
import scala.util.parsing.combinator.JavaTokenParsers
class TestKeywords extends JavaTokenParsers {
def keywords: Parser[String] = "update"
def identifier: Parser[String] = not(keywords) ~> """[a-zA-Z0-9_$#]+""".r
def script: Parser[Any] = repsep(identifier,",")
}
object TestKeywordsApp extends TestKeywords with App {
val cmd = """updateDet,update"""
parseAll(script,
cmd.stripMargin) match {
case Success(lup, _) => println(lup)
case x => println(x)
}
}
我得到错误
[1.1] 失败:找到匹配正则表达式
\z' expected but
u' 的字符串更新,更新
如何解决?updateDet 不应识别为关键字
斯卡拉 2.10.2