views:

38

answers:

1

What is the problem with parsing the blank/whitespace?

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  A: 

the lexer for scala throws blankspaces away. try override val skipWhitespace = false to avoid this.

the question was already solved so it seems... http://stackoverflow.com/questions/3347552/scala-parser-combinators-for-language-embedded-in-html-or-text-like-php

tarrasch