diff --git a/parsley/shared/src/main/scala/parsley/errors/combinator.scala b/parsley/shared/src/main/scala/parsley/errors/combinator.scala index ec105e5af..bd59b98ee 100644 --- a/parsley/shared/src/main/scala/parsley/errors/combinator.scala +++ b/parsley/shared/src/main/scala/parsley/errors/combinator.scala @@ -570,8 +570,8 @@ object combinator { */ @deprecated("This combinator will be removed in 5.0.0, without direct replacement", "4.2.0") def !(msggen: A => String): Parsley[Nothing] = partialAmendThenDislodge { - parsley.position.internalOffsetSpan(entrench(con(p))).flatMap { case (os, x, oe) => - combinator.fail(oe - os, msggen(x)) + parsley.position.withWidth(entrench(con(p))).flatMap { case (x, width) => + combinator.fail(width, msggen(x)) } } @@ -592,8 +592,8 @@ object combinator { */ @deprecated("This combinator will be removed in 5.0.0, without direct replacement", "4.2.0") def unexpected(msggen: A => String): Parsley[Nothing] = partialAmendThenDislodge { - parsley.position.internalOffsetSpan(entrench(con(p))).flatMap { case (os, x, oe) => - combinator.unexpected(oe - os, msggen(x)) + parsley.position.withWidth(entrench(con(p))).flatMap { case (x, width) => + combinator.unexpected(width, msggen(x)) } } // $COVERAGE-ON$ diff --git a/parsley/shared/src/main/scala/parsley/errors/patterns.scala b/parsley/shared/src/main/scala/parsley/errors/patterns.scala index 7a431730a..382f3970c 100644 --- a/parsley/shared/src/main/scala/parsley/errors/patterns.scala +++ b/parsley/shared/src/main/scala/parsley/errors/patterns.scala @@ -6,9 +6,8 @@ package parsley.errors import parsley.Parsley, Parsley.{atomic, select, unit} -import parsley.implicits.zipped.Zipped3 import parsley.errors.combinator.{ErrorMethods, amend} -import parsley.position.offset +import parsley.position.withWidth /** This module contains combinators that help facilitate the error message generational patterns ''Verified Errors'' and ''Preventative Errors''. * @@ -112,11 +111,7 @@ object patterns { def verifiedUnexpected(reason: A => String): Parsley[Nothing] = this.verifiedWithVanillaRaw(x => Some(reason(x))) // TODO: document and test - def verifiedWith(err: ErrorGen[A]) = amend { - err((offset, atomic(con(p)).newHide, offset).zipped { - (s, x, e) => (x, e-s) - }) - } + def verifiedWith(err: ErrorGen[A]) = amend(err(withWidth(atomic(con(p)).newHide))) @inline private def verifiedWithVanilla(unexGen: A => UnexpectedItem, reasonGen: A => Option[String]) = verifiedWith { new VanillaGen[A] { @@ -143,10 +138,7 @@ object patterns { // TODO: document and test def preventWith(err: ErrorGen[A], labels: String*) = { - val inner: Parsley[Either[(A, Int), Unit]] = - (offset, atomic(con(p)).newHide, offset).zipped { - (s, x, e) => (x, e-s) - } <+> unit + val inner: Parsley[Either[(A, Int), Unit]] = withWidth(atomic(con(p)).newHide) <+> unit val labelledErr = labels match { case l1 +: ls => err.parser.label(l1, ls: _*) case _ => err.parser diff --git a/parsley/shared/src/main/scala/parsley/position.scala b/parsley/shared/src/main/scala/parsley/position.scala index 55db05f9a..0b4db63aa 100644 --- a/parsley/shared/src/main/scala/parsley/position.scala +++ b/parsley/shared/src/main/scala/parsley/position.scala @@ -106,7 +106,6 @@ object position { */ val offset: Parsley[Int] = internalOffset - private [parsley] def spanWith[A, S](end: Parsley[S])(p: Parsley[A]): Parsley[(S, A, S)] = (end, p, end).zipped - // this is subject to change at the slightest notice, do NOT expose - private [parsley] def internalOffsetSpan[A](p: Parsley[A]): Parsley[(Int, A, Int)] = spanWith(internalOffset)(p) + //TODO: document and test + def withWidth[A](p: Parsley[A]): Parsley[(A, Int)] = (offset, p, offset).zipped((s, x, e) => (x, e-s)) }