Reputation: 2148
Let's say I have the following:
case class Var(s: String)
class MyParser extends JavaTokensParser {
def variableExpr = "?" ~ identifier ^^ { case "?" ~ id => Var(id) }
def identifier = //...
}
I want this to accept inputs of the form ?X
but not ? X
(with a space in between). How would this be expressed?
Thanks!
Upvotes: 0
Views: 50
Reputation: 38045
JavaTokensParser
by default allows white spaces between any parsers. You could change this behavior this way:
override def skipWhitespace = false
Now you have to specify all white spaces manually:
def ws: Parser[Seq[Char]] = rep(' ')
def variableExpr = ws ~> "?" ~ identifier ^^ { case "?" ~ id => Var(id) }
Upvotes: 2