feat(frontends/lean/builtin_cmds): improve print <id> when <id> is a not yet revealed theorem

We add a remark saying the command `reveal <id>` should be used to
access `<id>` definition.
This commit is contained in:
Leonardo de Moura 2015-06-13 12:12:22 -07:00
parent 591fb91f34
commit 8a85e4ee87
5 changed files with 26 additions and 2 deletions

View file

@ -304,7 +304,13 @@ bool print_polymorphic(parser & p) {
} else if (is_hits_decl(env, c)) {
print_constant(p, "builtin-HIT-constant", d);
} else if (d.is_axiom()) {
print_constant(p, "axiom", d);
if (p.in_theorem_queue(d.get_name())) {
print_constant(p, "theorem", d);
out << "'" << d.get_name() << "' is still in the theorem queue, use command 'reveal "
<< d.get_name() << "' to access its definition.\n";
} else {
print_constant(p, "axiom", d);
}
} else {
print_constant(p, "constant", d);
}

View file

@ -1859,10 +1859,12 @@ bool parser::curr_is_command_like() const {
void parser::add_delayed_theorem(environment const & env, name const & n, level_param_names const & ls,
expr const & t, expr const & v) {
m_theorem_queue_set.insert(n);
m_theorem_queue.add(env, n, ls, get_local_level_decls(), t, v);
}
void parser::add_delayed_theorem(certified_declaration const & cd) {
m_theorem_queue_set.insert(cd.get_declaration().get_name());
m_theorem_queue.add(cd);
}
@ -1873,6 +1875,7 @@ environment parser::reveal_theorems(buffer<name> const & ds) {
if (m_env.get(thm_name).is_axiom() &&
std::any_of(ds.begin(), ds.end(), [&](name const & n) { return n == thm_name; })) {
m_env = m_env.replace(thm);
m_theorem_queue_set.erase(thm_name);
}
}
});

View file

@ -14,7 +14,6 @@ Author: Leonardo de Moura
#include "util/exception.h"
#include "util/thread_script_state.h"
#include "util/script_exception.h"
#include "util/worker_queue.h"
#include "util/name_generator.h"
#include "kernel/environment.h"
#include "kernel/expr_maps.h"
@ -123,6 +122,7 @@ class parser {
optional<bool> m_has_tactic_decls;
// We process theorems in parallel
theorem_queue m_theorem_queue;
name_set m_theorem_queue_set; // set of theorem names in m_theorem_queue
// info support
snapshot_vector * m_snapshot_vector;
@ -307,6 +307,7 @@ public:
void add_delayed_theorem(environment const & env, name const & n, level_param_names const & ls, expr const & t, expr const & v);
void add_delayed_theorem(certified_declaration const & cd);
environment reveal_theorems(buffer<name> const & ds);
bool in_theorem_queue(name const & n) const { return m_theorem_queue_set.contains(n); }
/** \brief Read the next token. */
void scan() { m_curr = m_scanner.scan(m_env); }

10
tests/lean/print_thm.lean Normal file
View file

@ -0,0 +1,10 @@
open nat
theorem simple (a : nat) : a ≥ 0 :=
zero_le a
print simple
reveal simple
print simple

View file

@ -0,0 +1,4 @@
theorem simple : ∀ (a : ), a ≥ 0
'simple' is still in the theorem queue, use command 'reveal simple' to access its definition.
theorem simple : ∀ (a : ), a ≥ 0 :=
zero_le