我试图弄清楚如何使用关键字终止单词的重复。一个例子:
class CAQueryLanguage extends JavaTokenParsers {
def expression = ("START" ~ words ~ "END") ^^ { x =>
println("expression: " + x);
x
}
def words = rep(word) ^^ { x =>
println("words: " + x)
x
}
def word = """\w+""".r
}
当我执行
val caql = new CAQueryLanguage
caql.parseAll(caql.expression, "START one two END")
它打印words: List(one, two, END)
,表明words
解析器已经使用了END
我输入中的关键字,导致表达式解析器无法匹配。我END
不想被 匹配words
,这将允许expression
成功解析。