From 171b4ddcd9c33e38fe3725c76b3e505db26bf09a Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 12 May 2021 09:20:31 -0400 Subject: [PATCH] parse: deprecate `try_`, rename new function `try_opt` --- src/core/CCParse.ml | 4 +++- src/core/CCParse.mli | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/CCParse.ml b/src/core/CCParse.ml index a069052b..d26d86b3 100644 --- a/src/core/CCParse.ml +++ b/src/core/CCParse.ml @@ -457,7 +457,9 @@ let fix f = and f_self = lazy (f self) in self -let try_ p : _ t = { +let try_ p = p + +let try_opt p : _ t = { run=fun st ~ok ~err:_ -> p.run st ~ok:(fun st x -> ok st (Some x)) diff --git a/src/core/CCParse.mli b/src/core/CCParse.mli index 1a2d5aa3..cba724aa 100644 --- a/src/core/CCParse.mli +++ b/src/core/CCParse.mli @@ -229,7 +229,15 @@ val optional : _ t -> unit t succeeded or failed. Cannot fail. @since NEXT_RELEASE *) -val try_ : 'a t -> 'a option t +val try_ : 'a t -> 'a t +(** [try_ p] is just like [p] (it used to play a role in backtracking + semantics but no more). + + @deprecated since NEXT_RELEASE it can just be removed. See {!try_opt} if you want + to detect failure. *) +[@@deprecated "plays no role anymore"] + +val try_opt : 'a t -> 'a option t (** [try_ p] tries to parse using [p], and return [Some x] if [p] succeeded with [x]. Otherwise it returns [None]. This cannot fail. @since NEXT_RELEASE *)