Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate old error methods #147

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions parsley/shared/src/main/scala/parsley/errors/combinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ object combinator {
}
private [parsley] def fail(msg: String, msgs: String*): Parsley[Nothing] = attempt(this.hide).fail(_ => msg +: msgs)

// TODO: deprecate, and stress there is no _direct_ equivalent available moving forward
// $COVERAGE-OFF$
/** This combinator parses this parser and then fails, using the result of this parser to customise the error message.
*
* Similar to `fail`, but first parses this parser: if it succeeded, then its result `x` is used to form the error
Expand All @@ -468,11 +468,27 @@ object combinator {
* @return a parser that always fails, with the given generator used to produce the error message if this parser succeeded.
* @note $partialAmend
* @group fail
* @deprecated this combinator has not proven to be particularly useful, and will be replaced by a more appropriate,
* not exactly the same, `fail` combinator.
*/
@deprecated("This combinator will be removed in 5.0.0, without direct replacement", "4.2.0")
def !(msggen: A => String): Parsley[Nothing] = new Parsley(new frontend.FastFail(con(p).internal, msggen))

// TODO: I think this can probably be deprecated for future removal soon...
// It will be replaced by one that generates reasons too!
/** This combinator parses this parser and then fails, using the result of this parser to customise the unexpected component
* of the error message.
*
* @group fail
* @see [[unexpectedLegacy `unexpectedLegacy`]]
* @deprecated this combinator has not proven to be particularly useful in its current state, and will be replaced by a more
* appropriate, not exactly the same, `unexpected` combinator in 4.4.0. This will be removed from the source API in
* 4.3.0 to reduce risk of conflation with the new combinator, and legitimate uses of this combinator should switch
* to `unexpectedLegacy` instead, which will be removed in 5.0.0.
*/
@deprecated("This combinator will be binary removed in 5.0.0 and source removed in 4.3.0, use unexpectedLegacy until 5.0.0", "4.2.0")
def unexpected(msggen: A => String): Parsley[Nothing] = new Parsley(new frontend.FastUnexpected(con(p).internal, msggen))

/** This combinator parses this parser and then fails, using the result of this parser to customise the unexpected component
* of the error message.
*
Expand All @@ -484,8 +500,12 @@ object combinator {
* @return a parser that always fails, with the given generator used to produce an unexpected message if this parser succeeded.
* @note $partialAmend
* @group fail
* @deprecated this combinator has not proven to be particularly useful and will be removed in 5.0.0.
* @since 4.2.0
*/
def unexpected(msggen: A => String): Parsley[Nothing] = new Parsley(new frontend.FastUnexpected(con(p).internal, msggen))
@deprecated("This combinator will be removed in 5.0.0", "4.2.0")
def unexpectedLegacy(msggen: A => String): Parsley[Nothing] = new Parsley(new frontend.FastUnexpected(con(p).internal, msggen))
// $COVERAGE-ON$

// TODO: Documentation and testing ahead of future release
// like notFollowedBy, but does consume input on "success" and always fails (FIXME: this needs intrinsic support to get right)
Expand Down
2 changes: 0 additions & 2 deletions parsley/shared/src/test/scala/parsley/ErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class ErrorTests extends ParsleyTest {
(Parsley.empty ~> 'a').parse("a") shouldBe a [Failure[_]]
(pfail("") ~> 'a').parse("a") shouldBe a [Failure[_]]
(unexpected("x") *> 'a').parse("a") shouldBe a [Failure[_]]
(('a' ! (_ => "")) *> 'b').parse("ab") shouldBe a [Failure[_]]
('a'.unexpected(_ => "x") *> 'b').parse("ab") shouldBe a [Failure[_]]
}

"filtering parsers" should "function correctly" in {
Expand Down