问题
What is the problem with parsing the blank/whitespace?
scala> object BlankParser extends RegexParsers {
def blank: Parser[Any] = " "
def foo: Parser[Any] = "foo"
}
defined module BlankParser
scala> BlankParser.parseAll(BlankParser.foo, "foo")
res15: BlankParser.ParseResult[Any] = [1.4] parsed: foo
scala> BlankParser.parseAll(BlankParser.blank, " ")
res16: BlankParser.ParseResult[Any] =
[1.2] failure: ` ' expected but ` ' found
^
scala>
回答1:
the lexer for scala throws blankspaces away. try override val skipWhitespace = false to avoid this.
the question was already solved so it seems... Scala parser combinators for language embedded in html or text (like php)
来源:https://stackoverflow.com/questions/3564094/parsing-a-blank-whitespace-with-regexparsers