Merge failures from a,b in a|b when a,b fail on the same input position.

Previously, only the failures from b were used.
This commit is contained in:
Mark Harrah 2013-06-17 12:06:13 -04:00
parent d4f6b9cf78
commit ac3bfc16ae
1 changed files with 9 additions and 8 deletions

View File

@ -108,18 +108,18 @@ object Parser extends ParserMain
def flatMap[B](f: Nothing => Result[B]) = this def flatMap[B](f: Nothing => Result[B]) = this
def or[B](b: => Result[B]): Result[B] = b match { def or[B](b: => Result[B]): Result[B] = b match {
case v: Value[B] => v case v: Value[B] => v
case f: Failure => if(definitive) this else concatErrors(f) case f: Failure => if(definitive) this else this ++ f
} }
def either[B](b: => Result[B]): Result[Either[Nothing,B]] = b match { def either[B](b: => Result[B]): Result[Either[Nothing,B]] = b match {
case Value(v) => Value(Right(v)) case Value(v) => Value(Right(v))
case f: Failure => if(definitive) this else concatErrors(f) case f: Failure => if(definitive) this else this ++ f
} }
def filter(f: Nothing => Boolean, msg: => String) = this def filter(f: Nothing => Boolean, msg: => String) = this
def app[B,C](b: => Result[B])(f: (Nothing, B) => C): Result[C] = this def app[B,C](b: => Result[B])(f: (Nothing, B) => C): Result[C] = this
def &&(b: => Result[_]) = this def &&(b: => Result[_]) = this
def toEither = Left(() => errors) def toEither = Left(() => errors)
private[this] def concatErrors(f: Failure) = mkFailures(errors ++ f.errors) private[sbt] def ++(f: Failure) = mkFailures(errors ++ f.errors)
} }
def mkFailures(errors: => Seq[String], definitive: Boolean = false): Failure = new Failure(errors.distinct, definitive) def mkFailures(errors: => Seq[String], definitive: Boolean = false): Failure = new Failure(errors.distinct, definitive)
def mkFailure(error: => String, definitive: Boolean = false): Failure = new Failure(error :: Nil, definitive) def mkFailure(error: => String, definitive: Boolean = false): Failure = new Failure(error :: Nil, definitive)
@ -393,11 +393,12 @@ trait ParserMain
else else
t t
def homParser[A](a: Parser[A], b: Parser[A]): Parser[A] = def homParser[A](a: Parser[A], b: Parser[A]): Parser[A] = (a,b) match {
if(a.valid) case (Invalid(af), Invalid(bf)) => Invalid(af ++ bf)
if(b.valid) new HomParser(a, b) else a case (Invalid(_), bv) => bv
else case (av, Invalid(_)) => av
b case (av, bv) => new HomParser(a, b)
}
@deprecated("Explicitly specify the failure message.", "0.12.2") @deprecated("Explicitly specify the failure message.", "0.12.2")
def not(p: Parser[_]): Parser[Unit] = not(p, "Excluded.") def not(p: Parser[_]): Parser[Unit] = not(p, "Excluded.")