lean4-htt/library/init/meta/hole_command.lean
2017-06-13 21:12:29 -07:00

48 lines
1.5 KiB
Text

/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.tactic
/--
The front-end (e.g., Emacs, VS Code) can invoke commands for holes {! ... !} in
a declaration. A command is a tactic that takes the optional pre-term in the
hole, and returns a list of expressions. The Lean server converts the list
into a list of strings using the pretty printer, and return it to the front-end.
Each string represents a different way to fill the hole.
The front-end is responsible for replacing the hole with the user selected alternative.
This infra-structure can be use to implement auto-fill and/or refine commands.
An action may return an empty list. This is useful for actions that just return
information such as the type of an expression, its normal form, etc.
-/
meta structure hole_command :=
(name : string)
(descr : string)
(action : option pexpr → tactic (list expr))
open tactic
@[hole_command]
meta def infer_type_cmd : hole_command :=
{ name := "Infer",
descr := "Infer type of the expression in the hole",
action := λ o, do
some p ← return o | fail "Infer command, hole does not contain a term",
e ← to_expr p,
t ← infer_type e,
trace t,
return []
}
@[hole_command]
meta def show_goal_cmd : hole_command :=
{ name := "Show",
descr := "Show the current goal",
action := λ _, do
trace_state,
return []
}