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