| 1 |
Require Import Ltac2.Init. |
| 2 |
Require Ltac2.Control. |
| 3 |
Require Ltac2.Ltac1. |
| 4 |
|
| 5 |
Ltac2 drop_first_success (tac : unit -> 'a) := |
| 6 |
match Control.case tac with |
| 7 |
| Val v |
| 8 |
=> let (first_success, next) := v in |
| 9 |
fun (v : unit) => next (Tactic_failure None) |
| 10 |
| Err err => Control.zero err |
| 11 |
end. |
| 12 |
|
| 13 |
Ltac drop_first_success tac := |
| 14 |
let f := ltac2:(tac1 |- drop_first_success (fun () => Ltac1.run tac1) ()) in |
| 15 |
f tac. |
| 16 |
|
| 17 |
Ltac drop_n_success n tac := |
| 18 |
lazymatch n with |
| 19 |
| O => tac |
| 20 |
| S ?n => drop_n_success n ltac:(drop_first_success tac) |
| 21 |
end. |
| 22 |
|
| 23 |
Ltac only_nth_success n tac := |
| 24 |
once (drop_n_success n tac). |
| 25 |
|
| 26 |
Set Default Proof Mode "Classic". |
| 27 |
|
| 28 |
Goal True \/ False. |
| 29 |
drop_first_success ltac:(idtac "a"; constructor). |
| 30 |
(* Error: Uncaught Ltac2 exception: Tactic_failure (None) *) |
| 31 |
Abort. |