aboutsummaryrefslogtreecommitdiffhomepage
path: root/tactics
diff options
context:
space:
mode:
authorGravatar Arnaud Spiwack <arnaud@spiwack.net>2014-12-19 10:28:58 +0100
committerGravatar Arnaud Spiwack <arnaud@spiwack.net>2014-12-19 16:27:45 +0100
commitfb9815baafc008a6e67e542eb8c2adf7a6375fe8 (patch)
tree206244b9fb02320c8ab6b7c0381e9da4eaeb19b5 /tactics
parenta07648ca9c6b06414b271632c620122e51bf0f4a (diff)
Add a backtracking version of Ltac's [match].
[multimatch … with …] returns every possible successes: every matching branch and every successes of these matching branch, so that subsequent tactics can backtrack as well.
Diffstat (limited to 'tactics')
-rw-r--r--tactics/tacinterp.ml35
1 files changed, 21 insertions, 14 deletions
diff --git a/tactics/tacinterp.ml b/tactics/tacinterp.ml
index bbeb23c78..a8da8c81f 100644
--- a/tactics/tacinterp.ml
+++ b/tactics/tacinterp.ml
@@ -1547,20 +1547,27 @@ and interp_match_success ist { TacticMatching.subst ; context ; terms ; lhs } =
matching of successes [s]. If [lz] is set to true, then only the
first success is considered, otherwise further successes are tried
if the left-hand side fails. *)
-and interp_match_successes lz ist tac =
- if lz then
- (** Only keep the first matching result, we don't backtrack on it *)
- let tac = Proofview.tclONCE tac in
- tac >>= fun ans -> interp_match_success ist ans
- else
- let break (e, info) = match e with
- | FailError (0, _) -> None
- | FailError (n, s) -> Some (FailError (pred n, s), info)
- | _ -> None
- in
- let tac = Proofview.tclBREAK break tac >>= fun ans -> interp_match_success ist ans in
- (** Once a tactic has succeeded, do not backtrack anymore *)
- Proofview.tclONCE tac
+and interp_match_successes lz ist s =
+ let general =
+ let break (e, info) = match e with
+ | FailError (0, _) -> None
+ | FailError (n, s) -> Some (FailError (pred n, s), info)
+ | _ -> None
+ in
+ Proofview.tclBREAK break s >>= fun ans -> interp_match_success ist ans
+ in
+ match lz with
+ | General ->
+ general
+ | Lazy ->
+ begin
+ (** Only keep the first matching result, we don't backtrack on it *)
+ let s = Proofview.tclONCE s in
+ s >>= fun ans -> interp_match_success ist ans
+ end
+ | Once ->
+ (** Once a tactic has succeeded, do not backtrack anymore *)
+ Proofview.tclONCE general
(* Interprets the Match expressions *)
and interp_match ist lz constr lmr =