parser combinator: how to terminate repetition on keyword
问题 I'm trying to figure out how to terminate a repetition of words using a keyword. An example: 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 } When I execute val caql = new CAQueryLanguage caql.parseAll(caql.expression, "START one two END") It prints words: List(one, two, END) , indicating the words parser has consumed the END