summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-05-06 15:38:18 +0000
committerPaul Phillips <paulp@improving.org>2009-05-06 15:38:18 +0000
commit98be3213152ccec134da3e7856b8096beafcc6d8 (patch)
tree8e6cb835f6ff31843ef9787cc1b551b099eb806b /src/library
parent5b1da4217f7f36eab1ba14b5b95667de5bda09ed (diff)
downloadscala-98be3213152ccec134da3e7856b8096beafcc6d8.tar.gz
scala-98be3213152ccec134da3e7856b8096beafcc6d8.tar.bz2
scala-98be3213152ccec134da3e7856b8096beafcc6d8.zip
Added NoSuccess extractor to combinator lib.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/util/parsing/combinator/Parsers.scala19
1 files changed, 14 insertions, 5 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)
}
}