I\'m trying to figure out how to terminate a repetition of words using a keyword. An example:
class CAQueryLanguage extends JavaTokenParsers {
def expres
Is this what you are looking for?
import scala.util.parsing.combinator.syntactical._
object CAQuery extends StandardTokenParsers {
lexical.reserved += ("START", "END")
lexical.delimiters += (" ")
def query:Parser[Any]= "START" ~> rep1(ident) <~ "END"
def parse(s:String) = {
val tokens = new lexical.Scanner(s)
phrase(query)(tokens)
}
}
println(CAQuery.parse("""START a END""")) //List(a)
println(CAQuery.parse("""START a b c END""")) //List(a, b, c)
If you would like more details, you can check out this blog post