Question

Why does this simple example of a scala combinator parser fail?

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?

Was it helpful?

Solution

You are probably using 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.

To change this:

object MyParsers extends RegexParsers {
  override def skipWhitespace = false

  //your parsers...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top