I wrote the following Parser with the intent of fail
-ing on whitespace:
import scala.util.parsing.combinator._
object Foo extends JavaTokenParsers {
val wsTest = not(whiteSpace) // uses whitespace inherited from `RegexParsers`
}
Why is parsing a bunch of whitespace successfull?
scala> Foo.parseAll(Foo.wsTest, " ")
res5: Foo.ParseResult[Unit] = [1.11] parsed: ()
scala> res5.successful
res6: Boolean = true
Looking at Parsers#not
from the project, I would've expected a Failure
for my above test.
/** Wrap a parser so that its failures and errors become success and
* vice versa -- it never consumes any input.
*/
def not[T](p: => Parser[T]): Parser[Unit] = Parser { in =>
p(in) match {
case Success(_, _) => Failure("Expected failure", in)
case _ => Success((), in)
}
}