| 1 |
Require Import Ltac2.Ltac2. |
| 2 |
|
| 3 |
Ltac2 Type exn ::= [ Got (Std.intro_pattern option) ]. |
| 4 |
|
| 5 |
(* we can't return a value from a ltac1 notation so we get it out using Control.zero *) |
| 6 |
Tactic Notation "foo" simple_intropattern(x) := |
| 7 |
let f := ltac2:(y |- Control.zero (Got (Ltac1.to_intro_pattern y))) in |
| 8 |
f x. |
| 9 |
|
| 10 |
Ltac2 Notation "ipat" x(intropattern) := x. |
| 11 |
|
| 12 |
Goal nat. (* we need an open goal because ltac1 auto focuses *) |
| 13 |
Ltac2 Eval match Control.case (fun () => ltac1:(foo y%nat)) with |
| 14 |
| Err (Got (Some (Std.IntroAction |
| 15 |
(Std.IntroApplyOn |
| 16 |
c |
| 17 |
(Std.IntroNaming (Std.IntroIdentifier id)))))) => |
| 18 |
Control.assert_true (Ident.equal id @y); |
| 19 |
match! c () with |
| 20 |
| nat => () |
| 21 |
| _ => Control.throw Assertion_failure |
| 22 |
end |
| 23 |
| Val _ | Err _ => Control.throw Assertion_failure |
| 24 |
end. |
| 25 |
|
| 26 |
Ltac2 Eval match Ltac1.to_intro_pattern (Ltac1.of_intro_pattern (ipat ?w)) with |
| 27 |
| Some (Std.IntroNaming (Std.IntroFresh id)) => Control.assert_true (Ident.equal id @w) |
| 28 |
| _ => Control.throw Assertion_failure |
| 29 |
end. |
| 30 |
|
| 31 |
Ltac2 Eval |
| 32 |
ltac1:( |
| 33 |
let n := numgoals in |
| 34 |
let t := ltac2:(n |- |
| 35 |
match Ltac1.to_int n with |
| 36 |
| Some 1 => () |
| 37 |
| _ => Control.throw Assertion_failure |
| 38 |
end) |
| 39 |
in |
| 40 |
t n). |
| 41 |
|
| 42 |
Fail Ltac2 Eval |
| 43 |
ltac1:( |
| 44 |
let n := numgoals in |
| 45 |
let t := ltac2:(n |- |
| 46 |
match Ltac1.to_int n with |
| 47 |
| None => () |
| 48 |
| _ => Control.throw Assertion_failure |
| 49 |
end) |
| 50 |
in |
| 51 |
t n). |
| 52 |
|
| 53 |
Ltac2 Eval |
| 54 |
ltac1:(n |- do n assert False; [| | |]) (Ltac1.of_int 2). |
| 55 |
|
| 56 |
Abort. |