8000 Restored lastNoSuccess to Parsers. · dragos/scala-parser-combinators@7cc4cf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cc4cf9

Browse files
paulpadriaanm
authored andcommitted
Restored lastNoSuccess to Parsers.
It was in 2.9.2 and can't be removed without deprecation.
1 parent ae25b13 commit 7cc4cf9

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/library/scala/util/parsing/combinator/Parsers.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,20 @@ trait Parsers {
155155
val successful = true
156156
}
157157

158-
private lazy val lastNoSuccess = new DynamicVariable[Option[NoSuccess]](None)
158+
private lazy val lastNoSuccessVar = new DynamicVariable[Option[NoSuccess]](None)
159+
160+
@deprecated("lastNoSuccess was not thread-safe and will be removed in 2.11.0", "2.10.0")
161+
def lastNoSuccess: NoSuccess = lastNoSuccessVar.value.orNull
162+
163+
@deprecated("lastNoSuccess was not thread-safe and will be removed in 2.11.0", "2.10.0")
164+
def lastNoSuccess_=(x: NoSuccess): Unit = lastNoSuccessVar.value = Option(x)
159165

160166
/** A common super-class for unsuccessful parse results. */
161167
sealed abstract class NoSuccess(val msg: String, override val next: Input) extends ParseResult[Nothing] { // when we don't care about the difference between Failure and Error
162168
val successful = false
163169

164-
if (lastNoSuccess.value map { v => !(next.pos < v.next.pos) } getOrElse true)
165-
lastNoSuccess.value = Some(this)
170+
if (lastNoSuccessVar.value forall (v => !(next.pos < v.next.pos)))
171+
lastNoSuccessVar.value = Some(this)
166172

167173
def map[U](f: Nothing => U) = this
168174
def mapPartial[U](f: PartialFunction[Nothing, U], error: Nothing => String): ParseResult[U] = this
@@ -881,14 +887,14 @@ trait Parsers {
881887
* if `p` consumed all the input.
882888
*/
883889
def phrase[T](p: Parser[T]) = new Parser[T] {
884-
def apply(in: Input) = lastNoSuccess.withValue(None) {
890+
def apply(in: Input) = lastNoSuccessVar.withValue(None) {
885891
p(in) match {
886-
case s @ Success(out, in1) =>
887-
if (in1.atEnd)
888-
s
889-
else
890-
lastNoSuccess.value filterNot { _.next.pos < in1.pos } getOrElse Failure("end of input expected", in1)
891-
case ns => lastNoSuccess.value.getOrElse(ns)
892+
case s @ Success(out, in1) =>
893+
if (in1.atEnd)
894+
s
895+
else
896+
lastNoSuccessVar.value filterNot { _.next.pos < in1.pos } getOrElse Failure("end of input expected", in1)
897+
case ns => lastNoSuccessVar.value.getOrElse(ns)
892898
}
893899
}
894900
}

0 commit comments

Comments
 (0)
0