convenience functions for testing parsers

This commit is contained in:
Mark Harrah 2012-03-10 14:16:40 -05:00
parent d81f2b5870
commit 65f51cdb85
1 changed files with 10 additions and 0 deletions

View File

@ -283,6 +283,16 @@ trait ParserMain
ProcessError(str, msgs, pos)
}
def sample(str: String, parser: Parser[_], completions: Boolean = false): Unit =
if(completions) sampleParse(str, parser) else sampleCompletions(str, parser)
def sampleParse(str: String, parser: Parser[_]): Unit =
parse(str, parser) match {
case Left(msg) => println(msg)
case Right(v) => println(v)
}
def sampleCompletions(str: String, parser: Parser[_], level: Int = 1): Unit =
Parser.completions(parser, str, level).get foreach println
// intended to be temporary pending proper error feedback
def result[T](p: Parser[T], s: String): Either[() => (Seq[String],Int), T] =
{