lean4-htt/tests/lean/interactive/rb_map_ts.lean
Leonardo de Moura 54f7bf9391 fix(frontends/lean, library/tactic): remove redundant error messages, and fix position of error messages
Summary:

We minimize the number of "'sorry' used warning messages".  We also
re-target the error to the main declaration. Example: foo._main ==> foo
We do not report for auxiliary declarations such as "_example" and
"foo.equations._eqn_1"

Get rid of the redundant error message "error : failed" for tactics.
We added "silent failures" in the tactic framework.

We do not store line/col information for tactics nested in notation
declarations.  Before this commit, we would have tactics such
as (tactic.save_info line col) nested inside of notation declarations.
2017-02-07 20:25:28 -08:00

83 lines
2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

meta def mytac :=
state_t (name_map nat) tactic
meta instance : monad mytac :=
state_t.monad _ _
meta instance : monad.has_monad_lift tactic mytac :=
monad.monad_transformer_lift (state_t (name_map nat)) tactic
meta instance (α : Type) : has_coe (tactic α) (mytac α) :=
⟨monad.monad_lift⟩
namespace mytac
meta def step {α : Type} (t : mytac α) : mytac unit :=
t >> return ()
meta def rstep {α : Type} (line : nat) (col : nat) (t : mytac α) : mytac unit :=
λ v s, tactic_result.cases_on (@scope_trace _ line col (t v s))
(λ ⟨a, v⟩ new_s, tactic_result.success ((), v) new_s)
(λ opt_msg_thunk e new_s, match opt_msg_thunk with
| some msg_thunk := let msg := msg_thunk () ++ format.line ++ to_fmt "value: " ++ to_fmt v ++ format.line ++ to_fmt "state:" ++ format.line ++ new_s^.to_format in
(tactic.report_error line col msg >> tactic.silent_fail) new_s | none := tactic.silent_fail new_s end)
meta def execute (tac : mytac unit) : tactic unit :=
tac (name_map.mk nat) >> return ()
meta def save_info (line col : nat) : mytac unit :=
do v ← state_t.read,
s ← tactic.read,
tactic.save_info_thunk line col
(λ _, to_fmt "Custom state: " ++ to_fmt v ++ format.line ++
tactic_state.to_format s)
namespace interactive
meta def intros : mytac unit :=
tactic.intros >> return ()
meta def constructor : mytac unit :=
tactic.constructor
meta def trace (s : string) : mytac unit :=
tactic.trace s
meta def assumption : mytac unit :=
tactic.assumption
open interactive.types
meta def add (n : ident) (v : nat) : mytac unit :=
do m ← state_t.read, state_t.write (m^.insert n v)
end interactive
end mytac
lemma ex₁ (p q : Prop) : p → q → p ∧ q :=
begin [mytac]
intros,
add x 10,
trace "test",
--^ "command": "info"
constructor,
add y 20,
assumption,
--^ "command": "info"
assumption
end
print ex₁
lemma ex₂ (p q : Prop) : p → q → p ∧ q :=
begin [mytac]
intros,
add x 10,
trace "test",
constructor,
add y 20,
assumption,
--^ "command": "info"
assumption
end
print ex₂