为什么这个简单的 scala 组合器解析器示例会失败?
def test: Parser[String] = "< " ~> ident <~ " >"
当我提供以下字符串时:
"< a >"
我收到此错误:
[1.8] failure: ` >' expected but `&' found
< a >
^
为什么它会在太空中绊倒?
为什么这个简单的 scala 组合器解析器示例会失败?
def test: Parser[String] = "< " ~> ident <~ " >"
当我提供以下字符串时:
"< a >"
我收到此错误:
[1.8] failure: ` >' expected but `&' found
< a >
^
为什么它会在太空中绊倒?
您可能正在使用RegexParsers
. 在文档中,您可以找到:
解析方法调用方法skipWhitespace(默认为true),如果为true,则在调用每个解析器之前跳过任何空格。
要改变这一点:
object MyParsers extends RegexParsers {
override def skipWhitespace = false
//your parsers...
}