feat(library/attribute_manager, frontends/lean/builtin_cmds): use attribute manager information when pretty print definitions
This commit is contained in:
parent
45dbf76df9
commit
d81b2d0f29
5 changed files with 56 additions and 37 deletions
|
@ -23,7 +23,6 @@ Author: Leonardo de Moura
|
||||||
#include "library/locals.h"
|
#include "library/locals.h"
|
||||||
#include "library/coercion.h"
|
#include "library/coercion.h"
|
||||||
#include "library/constants.h"
|
#include "library/constants.h"
|
||||||
#include "library/reducible.h"
|
|
||||||
#include "library/light_lt_manager.h"
|
#include "library/light_lt_manager.h"
|
||||||
#include "library/normalize.h"
|
#include "library/normalize.h"
|
||||||
#include "library/print.h"
|
#include "library/print.h"
|
||||||
|
@ -36,8 +35,8 @@ Author: Leonardo de Moura
|
||||||
#include "library/pp_options.h"
|
#include "library/pp_options.h"
|
||||||
#include "library/composition_manager.h"
|
#include "library/composition_manager.h"
|
||||||
#include "library/aux_recursors.h"
|
#include "library/aux_recursors.h"
|
||||||
#include "library/relation_manager.h"
|
|
||||||
#include "library/projection.h"
|
#include "library/projection.h"
|
||||||
|
#include "library/attribute_manager.h"
|
||||||
#include "library/private.h"
|
#include "library/private.h"
|
||||||
#include "library/decl_stats.h"
|
#include "library/decl_stats.h"
|
||||||
#include "library/app_builder.h"
|
#include "library/app_builder.h"
|
||||||
|
@ -46,7 +45,6 @@ Author: Leonardo de Moura
|
||||||
#include "library/congr_lemma_manager.h"
|
#include "library/congr_lemma_manager.h"
|
||||||
#include "library/abstract_expr_manager.h"
|
#include "library/abstract_expr_manager.h"
|
||||||
#include "library/definitional/projection.h"
|
#include "library/definitional/projection.h"
|
||||||
#include "library/blast/simplifier/simp_rule_set.h"
|
|
||||||
#include "library/blast/blast.h"
|
#include "library/blast/blast.h"
|
||||||
#include "library/blast/simplifier/simplifier.h"
|
#include "library/blast/simplifier/simplifier.h"
|
||||||
#include "library/blast/backward/backward_rule_set.h"
|
#include "library/blast/backward/backward_rule_set.h"
|
||||||
|
@ -294,33 +292,35 @@ static void print_definition(parser const & p, name const & n, pos_info const &
|
||||||
static void print_attributes(parser const & p, name const & n) {
|
static void print_attributes(parser const & p, name const & n) {
|
||||||
environment const & env = p.env();
|
environment const & env = p.env();
|
||||||
io_state_stream out = p.regular_stream();
|
io_state_stream out = p.regular_stream();
|
||||||
if (is_coercion(env, n))
|
buffer<char const *> attrs;
|
||||||
out << " [coercion]";
|
get_attributes(attrs);
|
||||||
if (is_class(env, n))
|
for (char const * attr : attrs) {
|
||||||
out << " [class]";
|
if (strcmp(attr, "semireducible") == 0)
|
||||||
if (is_instance(env, n))
|
continue;
|
||||||
out << " [instance]";
|
if (has_attribute(env, attr, n)) {
|
||||||
if (is_simp_rule(env, n))
|
out << " " << get_attribute_token(attr);
|
||||||
out << " [simp]";
|
switch (get_attribute_kind(attr)) {
|
||||||
if (is_congr_rule(env, n))
|
case attribute_kind::Default:
|
||||||
out << " [congr]";
|
break;
|
||||||
if (auto light_arg = is_light_rule(env, n))
|
case attribute_kind::Prioritized: {
|
||||||
out << " [light " << *light_arg << "]";
|
unsigned prio = get_attribute_prio(env, attr, n);
|
||||||
if (is_backward_rule(env, n))
|
if (prio != LEAN_DEFAULT_PRIORITY)
|
||||||
out << " [backward]";
|
out << " [priority " << prio << "]";
|
||||||
if (is_no_pattern(env, n))
|
break;
|
||||||
out << " [no_pattern]";
|
}
|
||||||
if (is_forward_lemma(env, n))
|
case attribute_kind::Parametric:
|
||||||
out << " [forward]";
|
case attribute_kind::OptParametric:
|
||||||
if (is_elim_lemma(env, n))
|
out << " " << get_attribute_param(env, attr, n) << "]";
|
||||||
out << " [elim]";
|
break;
|
||||||
if (is_intro_lemma(env, n))
|
case attribute_kind::MultiParametric: {
|
||||||
out << " [intro]";
|
list<unsigned> ps = get_attribute_params(env, attr, n);
|
||||||
switch (get_reducible_status(env, n)) {
|
for (auto p : ps) {
|
||||||
case reducible_status::Reducible: out << " [reducible]"; break;
|
out << " " << p;
|
||||||
case reducible_status::Irreducible: out << " [irreducible]"; break;
|
}
|
||||||
case reducible_status::Quasireducible: out << " [quasireducible]"; break;
|
out << "]";
|
||||||
case reducible_status::Semireducible: break;
|
break;
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,6 +180,24 @@ char const * get_attribute_from_token(char const * tk) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Decls>
|
||||||
|
char const * get_attribute_token(Decls const & decls, char const * attr) {
|
||||||
|
for (auto const & d : decls) {
|
||||||
|
if (d.m_id == attr)
|
||||||
|
return d.m_token.c_str();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const * get_attribute_token(char const * attr) {
|
||||||
|
if (auto r = get_attribute_token(*g_default_attrs, attr)) return r;
|
||||||
|
if (auto r = get_attribute_token(*g_prio_attrs, attr)) return r;
|
||||||
|
if (auto r = get_attribute_token(*g_param_attrs, attr)) return r;
|
||||||
|
if (auto r = get_attribute_token(*g_opt_param_attrs, attr)) return r;
|
||||||
|
if (auto r = get_attribute_token(*g_params_attrs, attr)) return r;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
attribute_kind get_attribute_kind (char const * attr) {
|
attribute_kind get_attribute_kind (char const * attr) {
|
||||||
lean_assert(is_attribute(attr));
|
lean_assert(is_attribute(attr));
|
||||||
if (is_attribute(*g_default_attrs, attr)) return attribute_kind::Default;
|
if (is_attribute(*g_default_attrs, attr)) return attribute_kind::Default;
|
||||||
|
|
|
@ -47,6 +47,7 @@ bool is_attribute(char const * attr);
|
||||||
void get_attributes(buffer<char const *> &);
|
void get_attributes(buffer<char const *> &);
|
||||||
void get_attribute_tokens(buffer<char const *> &);
|
void get_attribute_tokens(buffer<char const *> &);
|
||||||
char const * get_attribute_from_token(char const * attr_token);
|
char const * get_attribute_from_token(char const * attr_token);
|
||||||
|
char const * get_attribute_token(char const * attr);
|
||||||
attribute_kind get_attribute_kind (char const * attr);
|
attribute_kind get_attribute_kind (char const * attr);
|
||||||
|
|
||||||
environment set_attribute(environment const & env, io_state const & ios, char const * attr,
|
environment set_attribute(environment const & env, io_state const & ios, char const * attr,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
definition id [reducible] : Π {A : Type}, A → A :=
|
definition id [reducible] [unfold_full] : Π {A : Type}, A → A :=
|
||||||
λ (A : Type) (a : A), a
|
λ (A : Type) (a : A), a
|
||||||
|
|
||||||
definition category.id [reducible] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a :=
|
definition category.id [reducible] [unfold 1] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a :=
|
||||||
ID
|
ID
|
||||||
-----------
|
-----------
|
||||||
definition id [reducible] : Π {A : Type}, A → A
|
definition id [reducible] [unfold_full] : Π {A : Type}, A → A
|
||||||
λ (A : Type) (a : A), a
|
λ (A : Type) (a : A), a
|
||||||
|
|
||||||
definition category.id [reducible] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a
|
definition category.id [reducible] [unfold 1] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a
|
||||||
ID
|
ID
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
constant H [backward] : A → B
|
constant H [intro] : A → B
|
||||||
constant G [backward] : A → B → C
|
constant G [intro] : A → B → C
|
||||||
constant f [backward] : T → A
|
constant f [intro] : T → A
|
||||||
backward rules
|
backward rules
|
||||||
exists_unique ==> exists_unique.intro
|
exists_unique ==> exists_unique.intro
|
||||||
B ==> H
|
B ==> H
|
||||||
|
|
Loading…
Reference in a new issue