Parsing a blank / whitespace with RegexParsers

别等时光非礼了梦想. 提交于 2020-01-04 02:19:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!