diff options
-rw-r--r-- | src/library/scala/util/parsing/combinator/Parsers.scala | 19 | ||||
-rw-r--r-- | test/files/run/packrat1.scala | 5 | ||||
-rw-r--r-- | test/files/run/packrat2.scala | 3 | ||||
-rw-r--r-- | test/files/run/packrat3.scala | 3 |
4 files changed, 18 insertions, 12 deletions
diff --git a/src/library/scala/util/parsing/combinator/Parsers.scala b/src/library/scala/util/parsing/combinator/Parsers.scala index 29fbbebc28..b2c72153fe 100644 --- a/src/library/scala/util/parsing/combinator/Parsers.scala +++ b/src/library/scala/util/parsing/combinator/Parsers.scala @@ -153,6 +153,17 @@ trait Parsers { def get: Nothing = error("No result when parsing failed") } + /** An extractor so NoSuccess(msg, next) can be used in matches + * Note: case class inheritance is currently sketchy and may be + * deprecated, so an explicit extractor is better. + */ + object NoSuccess { + def unapply[T](x: ParseResult[T]) = x match { + case Failure(msg, next) => Some(msg, next) + case Error(msg, next) => Some(msg, next) + case _ => None + } + } /** The failure case of ParseResult: contains an error-message and the remaining input. * Parsing will back-track when a failure occurs. @@ -304,8 +315,7 @@ trait Parsers { case (s1 @ Success(_, _), _) => s1 case (_, s2 @ Success(_, _)) => s2 case (e1 @ Error(_, _), _) => e1 - case (f1 @ Failure(_, next1), f2 @ Failure(_, next2)) => if (next2.pos < next1.pos) f1 else f2 - case (f1 @ Failure(_, next1), e2 @ Error(_, next2)) => if (next2.pos < next1.pos) f1 else e2 + case (f1 @ Failure(_, next1), ns2 @ NoSuccess(_, next2)) => if (next2.pos < next1.pos) f1 else ns2 } } override def toString = "|||" @@ -699,9 +709,8 @@ trait Parsers { */ def not[T](p: => Parser[T]): Parser[Unit] = Parser { in => p(in) match { - case s @ Success(_, _) => Failure("Expected failure", in) - case e @ Error(_, _) => Success((), in) - case f @ Failure(msg, next) => Success((), in) + case Success(_, _) => Failure("Expected failure", in) + case _ => Success((), in) } } diff --git a/test/files/run/packrat1.scala b/test/files/run/packrat1.scala index 69eb8c5fc9..26fa8e76f2 100644 --- a/test/files/run/packrat1.scala +++ b/test/files/run/packrat1.scala @@ -22,10 +22,9 @@ object Test extends Application{ object grammars extends StandardTokenParsers with PackratParsers{ - def extractResult(r : ParseResult[_]) = r match{ + def extractResult(r : ParseResult[_]) = r match { case Success(a,_) => a - case Failure(a,_) => a - case Error(a,_) => a + case NoSuccess(a,_) => a } lexical.delimiters ++= List("+","-","*","/","(",")") diff --git a/test/files/run/packrat2.scala b/test/files/run/packrat2.scala index 3361552561..dda9a32906 100644 --- a/test/files/run/packrat2.scala +++ b/test/files/run/packrat2.scala @@ -25,8 +25,7 @@ object grammars2 extends StandardTokenParsers with PackratParsers{ def extractResult(r : ParseResult[_]) = r match{ case Success(a,_) => a - case Failure(a,_) => a - case Error(a,_) => a + case NoSuccess(a,_) => a } lexical.delimiters ++= List("+","-","*","/","(",")") diff --git a/test/files/run/packrat3.scala b/test/files/run/packrat3.scala index 34695ef2ed..09acb6e7ff 100644 --- a/test/files/run/packrat3.scala +++ b/test/files/run/packrat3.scala @@ -27,8 +27,7 @@ object grammars3 extends StandardTokenParsers with PackratParsers { def extractResult(r: ParseResult[_]) = r match { case Success(a,_) => a - case Failure(a,_) => a - case Error(a,_) => a + case NoSuccess(a,_) => a } |