feat(frontends/lean/pp): add option to hide binder types

This commit is contained in:
Sebastian Ullrich 2016-05-24 11:42:06 -04:00 committed by Leonardo de Moura
parent e44f9a0e62
commit f2200fab65
7 changed files with 36 additions and 7 deletions

View file

@ -292,6 +292,7 @@ void pretty_fn::set_options_core(options const & _o) {
m_numerals = get_pp_numerals(o);
m_abbreviations = get_pp_abbreviations(o);
m_preterm = get_pp_preterm(o);
m_binder_types = get_pp_binder_types(o);
m_hide_full_terms = get_formatter_hide_full_terms(o);
m_num_nat_coe = m_numerals && !m_coercion;
}
@ -669,8 +670,10 @@ format pretty_fn::pp_binder(expr const & local) {
if (bi != binder_info())
r += format(open_binder_string(bi, m_unicode));
r += format(local_pp_name(local));
if (m_binder_types) {
r += space();
r += compose(colon(), nest(m_indent, compose(line(), pp_child(mlocal_type(local), 0).fmt())));
}
if (bi != binder_info())
r += format(close_binder_string(bi, m_unicode));
return r;
@ -678,12 +681,16 @@ format pretty_fn::pp_binder(expr const & local) {
format pretty_fn::pp_binder_block(buffer<name> const & names, expr const & type, binder_info const & bi) {
format r;
if (m_binder_types || bi != binder_info())
r += format(open_binder_string(bi, m_unicode));
for (name const & n : names) {
r += format(n);
r += space();
}
if (m_binder_types) {
r += space();
r += compose(colon(), nest(m_indent, compose(line(), pp_child(type, 0).fmt())));
}
if (m_binder_types || bi != binder_info())
r += format(close_binder_string(bi, m_unicode));
return group(r);
}

View file

@ -70,6 +70,7 @@ private:
bool m_abbreviations;
bool m_hide_full_terms;
bool m_preterm;
bool m_binder_types;
name mk_metavar_name(name const & m);
name mk_local_name(name const & n, name const & suggested);

View file

@ -387,7 +387,7 @@ static bool print_constant(parser const & p, char const * kind, declaration cons
out << "protected ";
out << kind << " " << to_user_name(p.env(), d.get_name());
print_attributes(p, d.get_name());
out << " : " << d.get_type();
out.update_options(out.get_options().update((name {"pp", "binder_types"}), true)) << " : " << d.get_type();
if (is_def)
out << " :=";
out << "\n";

View file

@ -75,6 +75,10 @@ Author: Leonardo de Moura
#define LEAN_DEFAULT_PP_GOAL_MAX_HYPS 200
#endif
#ifndef LEAN_DEFAULT_PP_BINDER_TYPES
#define LEAN_DEFAULT_PP_BINDER_TYPES false
#endif
#ifndef LEAN_DEFAULT_PP_ALL
#define LEAN_DEFAULT_PP_ALL false
#endif
@ -97,6 +101,7 @@ static name * g_pp_abbreviations = nullptr;
static name * g_pp_preterm = nullptr;
static name * g_pp_goal_compact = nullptr;
static name * g_pp_goal_max_hyps = nullptr;
static name * g_pp_binder_types = nullptr;
static name * g_pp_all = nullptr;
static list<options> * g_distinguishing_pp_options = nullptr;
@ -119,6 +124,7 @@ void initialize_pp_options() {
g_pp_all = new name{"pp", "all"};
g_pp_goal_compact = new name{"pp", "goal", "compact"};
g_pp_goal_max_hyps = new name{"pp", "goal", "max_hypotheses"};
g_pp_binder_types = new name{"pp", "binder_types"};
register_unsigned_option(*g_pp_max_depth, LEAN_DEFAULT_PP_MAX_DEPTH,
"(pretty printer) maximum expression depth, after that it will use ellipsis");
@ -156,6 +162,8 @@ void initialize_pp_options() {
"(pretty printer) try to display goal in a single line when possible");
register_unsigned_option(*g_pp_goal_max_hyps, LEAN_DEFAULT_PP_GOAL_MAX_HYPS,
"(pretty printer) maximum number of hypotheses to be displayed");
register_bool_option(*g_pp_binder_types, LEAN_DEFAULT_PP_BINDER_TYPES,
"(pretty printer) display types of lambda and Pi parameters");
register_bool_option(*g_pp_all, LEAN_DEFAULT_PP_ALL,
"(pretty printer) display coercions, implicit parameters, fully qualified names, universes, "
"and disable abbreviations, beta reduction and notation during pretty printing");
@ -223,6 +231,7 @@ bool get_pp_abbreviations(options const & opts) { return opts.get_bool(*g_
bool get_pp_preterm(options const & opts) { return opts.get_bool(*g_pp_preterm, LEAN_DEFAULT_PP_PRETERM); }
bool get_pp_goal_compact(options const & opts) { return opts.get_bool(*g_pp_goal_compact, LEAN_DEFAULT_PP_GOAL_COMPACT); }
unsigned get_pp_goal_max_hyps(options const & opts) { return opts.get_unsigned(*g_pp_goal_max_hyps, LEAN_DEFAULT_PP_GOAL_MAX_HYPS); }
bool get_pp_binder_types(options const & opts) { return opts.get_bool(*g_pp_binder_types, LEAN_DEFAULT_PP_BINDER_TYPES); }
bool get_pp_all(options const & opts) { return opts.get_bool(*g_pp_all, LEAN_DEFAULT_PP_ALL); }
list<options> const & get_distinguishing_pp_options() { return *g_distinguishing_pp_options; }

View file

@ -37,6 +37,7 @@ bool get_pp_abbreviations(options const & opts);
bool get_pp_preterm(options const & opts);
bool get_pp_goal_compact(options const & opts);
unsigned get_pp_goal_max_hyps(options const & opts);
bool get_pp_binder_types(options const & opts);
bool get_pp_all(options const & opts);
list<options> const & get_distinguishing_pp_options();

View file

@ -0,0 +1,7 @@
open nat
definition f (n : nat) (H : n = n) := λm, id (n + m)
print f
set_option pp.binder_types true
print f

View file

@ -0,0 +1,4 @@
definition f : Π (n : ), n = n → :=
λ n H m, id (n + m)
definition f : Π (n : ), n = n → :=
λ (n : ) (H : n = n) (m : ), id (n + m)