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
keyword in my input, leaving the expression parser unable to match. I would like END
to not be matched by words
, which will allow expression
to successfully parse.
Is this what you are looking for?
If you would like more details, you can check out this blog post