Parse empty / whitespace with RegexParsers

What is the problem with gap / gap analysis?

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>
+3
source share
1 answer

The lexer for scala removes spaces. try override val skipWhitespace = false to avoid this.

the question has already been resolved, so it seems ... Scala Parser comparators for a language embedded in html or text (e.g. php)

+4
source

Source: https://habr.com/ru/post/1761475/


All Articles