【问题标题】:Scala Combinator Parser not working with spacesScala Combinator Parser 不使用空格
【发布时间】:2014-01-29 20:38:22
【问题描述】:

为什么这个简单的 scala 组合器解析器示例会失败?

def test: Parser[String] = "&lt; " ~> ident <~ " &gt;"

当我提供以下字符串时:

"&lt; a &gt;"

我收到此错误:

[1.8] failure: ` &gt;' expected but `&' found

&lt; a &gt;
       ^

为什么它会在太空中绊倒?

【问题讨论】:

    标签: scala parsing combinators


    【解决方案1】:

    您可能正在使用RegexParsers。在documentation,你可以发现:

    解析方法调用方法skipWhitespace(默认为true) 如果为真,则在调用每个解析器之前跳过任何空格。

    要改变这个:

    object MyParsers extends RegexParsers {
      override def skipWhitespace = false
    
      //your parsers...
    }
    

    【讨论】:

    • 天哪,谢谢!为什么这是默认值:(
    猜你喜欢
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多