Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 5424f51

Browse files
committed
feat(tactic/tidy): add tidy? syntax for reporting a tactic script
1 parent 177b5eb commit 5424f51

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

docs/tactics.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,18 +487,19 @@ same type, or the type `α → β → tactic γ → tactic γ` or
487487
In particular, `tidy` uses the `chain` tactic to repeatedly apply a list of tactics to
488488
the goal and recursively on new goals, until no tactic makes further progress.
489489

490-
`tidy` can report the tactic script it found using `tidy { trace_result := tt }`. As an example
490+
`tidy` can report the tactic script it found using `tidy?`. As an example
491491
```lean
492492
example : ∀ x : unit, x = unit.star :=
493493
begin
494-
tidy {trace_result:=tt} -- Prints the trace message: "intros x, exact dec_trivial"
494+
tidy? -- Prints the trace message: "intros x, exact dec_trivial"
495495
end
496496
```
497497

498498
The default list of tactics can be found by looking up the definition of
499499
[`default_tidy_tactics`](https://github.com/leanprover/mathlib/blob/master/tactic/tidy.lean).
500500

501-
This list can be overriden using `tidy { tactics := ... }`. (The list must be a list of `tactic string`.)
501+
This list can be overriden using `tidy { tactics := ... }`. (The list must be a list of
502+
`tactic string`, so that `tidy?` can report a usable tactic script.)
502503

503504
## linarith
504505

src/tactic/tidy.lean

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ meta def name_to_tactic (n : name) : tactic string :=
2121
do d ← get_decl n,
2222
e ← mk_const n,
2323
let t := d.type,
24-
if (t =ₐ `(tactic unit)) then
24+
if (t =ₐ `(tactic unit)) then
2525
(eval_expr (tactic unit) e) >>= (λ t, t >> pure n.to_string)
2626
else if (t =ₐ `(tactic string)) then
2727
(eval_expr (tactic string) e) >>= (λ t, t)
@@ -40,7 +40,7 @@ do ng ← num_goals,
4040
else "ext1"
4141

4242
meta def default_tactics : list (tactic string) :=
43-
[ reflexivity >> pure "refl",
43+
[ reflexivity >> pure "refl",
4444
`[exact dec_trivial] >> pure "exact dec_trivial",
4545
propositional_goal >> assumption >> pure "assumption",
4646
ext1_wrapper,
@@ -49,7 +49,7 @@ meta def default_tactics : list (tactic string) :=
4949
`[apply_auto_param] >> pure "apply_auto_param",
5050
`[dsimp at *] >> pure "dsimp at *",
5151
`[simp at *] >> pure "simp at *",
52-
fsplit >> pure "fsplit",
52+
fsplit >> pure "fsplit",
5353
injections_and_clear >> pure "injections_and_clear",
5454
propositional_goal >> (`[solve_by_elim]) >> pure "solve_by_elim",
5555
`[unfold_aux] >> pure "unfold_aux",
@@ -74,11 +74,14 @@ end tidy
7474
meta def tidy (cfg : tidy.cfg := {}) := tactic.tidy.core cfg >> skip
7575

7676
namespace interactive
77-
meta def tidy (cfg : tidy.cfg := {}) := tactic.tidy cfg
77+
open lean.parser interactive
78+
79+
meta def tidy (trace : parse $ optional (tk "?")) (cfg : tidy.cfg := {}) :=
80+
tactic.tidy { trace_result := trace.is_some, ..cfg }
7881
end interactive
7982

8083
@[hole_command] meta def tidy_hole_cmd : hole_command :=
81-
{ name := "tidy",
84+
{ name := "tidy",
8285
descr := "Use `tidy` to complete the goal.",
8386
action := λ _, do script ← tidy.core, return [("begin " ++ (", ".intercalate script) ++ " end", "by tidy")] }
8487

test/tidy.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ namespace tidy.test
1010

1111
meta def interactive_simp := `[simp]
1212

13-
def tidy_test_0 : ∀ x : unit, x = unit.star :=
13+
def tidy_test_0 : ∀ x : unit, x = unit.star :=
1414
begin
1515
success_if_fail { chain [ interactive_simp ] },
1616
intro1,
1717
induction x,
1818
refl
1919
end
20-
def tidy_test_1 (a : string): ∀ x : unit, x = unit.star :=
20+
def tidy_test_1 (a : string): ∀ x : unit, x = unit.star :=
2121
begin
2222
tidy -- intros x, exact dec_trivial
2323
end
2424

2525
structure A :=
2626
(z : ℕ)
2727

28-
structure B :=
28+
structure B :=
2929
(a : A)
3030
(aa : a.z = 0)
3131

@@ -41,14 +41,14 @@ structure D :=
4141

4242
open tactic
4343

44-
def d : D :=
44+
def d : D :=
4545
begin
46-
tidy,
46+
tidy,
4747
-- /- obviously says -/ fsplit, work_on_goal 0 { fsplit, work_on_goal 0 { fsplit }, work_on_goal 1 { refl } }, work_on_goal 0 { fsplit, work_on_goal 0 { fsplit }, work_on_goal 1 { fsplit, work_on_goal 0 { fsplit }, work_on_goal 1 { refl } }, work_on_goal 1 { refl } }, refl
4848
end.
4949

5050
def f : unit → unit → unit := by tidy -- intros a a_1, cases a_1, cases a, fsplit
5151

5252
def g (P Q : Prop) (p : P) (h : P ↔ Q) : Q := by tidy
5353

54-
end tidy.test
54+
end tidy.test

0 commit comments

Comments
 (0)