Skip to content

Commit

Permalink
Ltac2 Util: Add various destKind helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross committed Oct 6, 2022
1 parent 08eb6f3 commit 40cb50f
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 0 deletions.
17 changes: 17 additions & 0 deletions _CoqProject.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ src/Rewriter/Util/Tactics2/Array.v
src/Rewriter/Util/Tactics2/Char.v
src/Rewriter/Util/Tactics2/Constr.v
src/Rewriter/Util/Tactics2/DecomposeLambda.v
src/Rewriter/Util/Tactics2/DestApp.v
src/Rewriter/Util/Tactics2/DestCase.v
src/Rewriter/Util/Tactics2/DestCast.v
src/Rewriter/Util/Tactics2/DestCoFix.v
src/Rewriter/Util/Tactics2/DestConstant.v
src/Rewriter/Util/Tactics2/DestConstructor.v
src/Rewriter/Util/Tactics2/DestEvar.v
src/Rewriter/Util/Tactics2/DestFix.v
src/Rewriter/Util/Tactics2/DestInd.v
src/Rewriter/Util/Tactics2/DestLambda.v
src/Rewriter/Util/Tactics2/DestLetIn.v
src/Rewriter/Util/Tactics2/DestMeta.v
src/Rewriter/Util/Tactics2/DestProd.v
src/Rewriter/Util/Tactics2/DestProj.v
src/Rewriter/Util/Tactics2/DestRel.v
src/Rewriter/Util/Tactics2/DestSort.v
src/Rewriter/Util/Tactics2/DestVar.v
src/Rewriter/Util/Tactics2/FixNotationsForPerformance.v
src/Rewriter/Util/Tactics2/Head.v
src/Rewriter/Util/Tactics2/HeadReference.v
Expand Down
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestApp.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_an_app (kind) ].
Ltac2 destApp (c : constr) :=
let k := kind c in
match k with
| App f args => (f, args)
| _ => Control.throw (Not_an_app k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestCase.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_case (kind) ].
Ltac2 destCase (c : constr) :=
let k := kind c in
match k with
| Case a b c d e => (a, b, c, d, e)
| _ => Control.throw (Not_a_case k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestCast.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_cast (kind) ].
Ltac2 destCast (c : constr) :=
let k := kind c in
match k with
| Cast x y z => (x, y, z)
| _ => Control.throw (Not_a_cast k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestCoFix.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_cofix (kind) ].
Ltac2 destCoFix (c : constr) :=
let k := kind c in
match k with
| CoFix x y z => (x, y, z)
| _ => Control.throw (Not_a_cofix k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestConstant.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_constant (kind) ].
Ltac2 destConstant (c : constr) :=
let k := kind c in
match k with
| Constant e inst => (e, inst)
| _ => Control.throw (Not_a_constant k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestConstructor.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_constructor (kind) ].
Ltac2 destConstructor (c : constr) :=
let k := kind c in
match k with
| Constructor e inst => (e, inst)
| _ => Control.throw (Not_a_constructor k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestEvar.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_an_evar (kind) ].
Ltac2 destEvar (c : constr) :=
let k := kind c in
match k with
| Evar e inst => (e, inst)
| _ => Control.throw (Not_an_evar k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestFix.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_fix (kind) ].
Ltac2 destFix (c : constr) :=
let k := kind c in
match k with
| Fix x y z w => (x, y, z, w)
| _ => Control.throw (Not_a_fix k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestInd.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_an_ind (kind) ].
Ltac2 destInd (c : constr) :=
let k := kind c in
match k with
| Ind e inst => (e, inst)
| _ => Control.throw (Not_an_ind k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestLambda.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_lambda (kind) ].
Ltac2 destLambda (c : constr) :=
let k := kind c in
match k with
| Lambda x f => (x, f)
| _ => Control.throw (Not_a_lambda k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestLetIn.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_let_in (kind) ].
Ltac2 destLetIn (c : constr) :=
let k := kind c in
match k with
| LetIn x y z => (x, y, z)
| _ => Control.throw (Not_a_let_in k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestMeta.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_meta (kind) ].
Ltac2 destMeta (c : constr) :=
let k := kind c in
match k with
| Meta e => e
| _ => Control.throw (Not_a_meta k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestProd.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_prod (kind) ].
Ltac2 destProd (c : constr) :=
let k := kind c in
match k with
| Prod x f => (x, f)
| _ => Control.throw (Not_a_prod k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestProj.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_proj (kind) ].
Ltac2 destProj (c : constr) :=
let k := kind c in
match k with
| Proj p v => (p, v)
| _ => Control.throw (Not_a_proj k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestRel.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_rel (kind) ].
Ltac2 destRel (c : constr) :=
let k := kind c in
match k with
| Rel i => i
| _ => Control.throw (Not_a_rel k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestSort.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_sort (kind) ].
Ltac2 destSort (c : constr) :=
let k := kind c in
match k with
| Sort s => s
| _ => Control.throw (Not_a_sort k)
end.
11 changes: 11 additions & 0 deletions src/Rewriter/Util/Tactics2/DestVar.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Require Import Ltac2.Ltac2.
Require Export Rewriter.Util.FixCoqMistakes.
Import Ltac2.Constr.Unsafe.

Ltac2 Type exn ::= [ Not_a_var (kind) ].
Ltac2 destVar (c : constr) :=
let k := kind c in
match k with
| Var v => v
| _ => Control.throw (Not_a_var k)
end.

0 comments on commit 40cb50f

Please sign in to comment.