return position at which parsing fails

This commit is contained in:
Mark Harrah 2011-02-18 20:57:39 -05:00
parent 16cd2e7fdc
commit 6688918349
1 changed files with 10 additions and 11 deletions

View File

@ -214,19 +214,18 @@ trait ParserMain
// intended to be temporary pending proper error feedback
def result[T](p: Parser[T], s: String): Either[(String,Int), T] =
{
/* def loop(i: Int, a: Parser[T]): Either[(String,Int), T] =
a.err match
def loop(i: Int, a: Parser[T]): Either[(String,Int), T] =
if(a.valid)
{
case Some(msg) => Left((msg, i))
case None =>
val ci = i+1
if(ci >= s.length)
a.resultEmpty.toRight(("", i))
else
loop(ci, a derive s(ci))
val ci = i+1
if(ci >= s.length)
a.resultEmpty.toRight(("Unexpected end of input", ci))
else
loop(ci, a derive s(ci) )
}
loop(-1, p)*/
apply(p)(s).resultEmpty.toRight(("Parse error", 0))
else
Left(("Parse error",i))
loop(-1, p)
}
def apply[T](p: Parser[T])(s: String): Parser[T] =