简体   繁体   English

Scala Combinator Parser不使用空格

[英]Scala Combinator Parser not working with spaces

Why does this simple example of a scala combinator parser fail? 为什么这个scala组合子解析器的简单示例失败了?

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

When I provide the following string: 当我提供以下字符串时:

"&lt; a &gt;"

I get this error: 我收到此错误:

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

&lt; a &gt;
       ^

Why is it tripping up on the space? 为什么它会在这个空间上绊倒?

You are probably using RegexParsers . 您可能正在使用RegexParsers In documentation , you can find that: 文档中 ,您可以找到:

The parsing methods call the method skipWhitespace (defaults to true) and, if true, skip any whitespace before each parser is called. 解析方法调用方法skipWhitespace(默认为true),如果为true,则在调用每个解析器之前跳过任何空格。

To change this: 要改变这个:

object MyParsers extends RegexParsers {
  override def skipWhitespace = false

  //your parsers...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM