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/coercion.h"
|
||||
#include "library/constants.h"
|
||||
#include "library/reducible.h"
|
||||
#include "library/light_lt_manager.h"
|
||||
#include "library/normalize.h"
|
||||
#include "library/print.h"
|
||||
|
@ -36,8 +35,8 @@ Author: Leonardo de Moura
|
|||
#include "library/pp_options.h"
|
||||
#include "library/composition_manager.h"
|
||||
#include "library/aux_recursors.h"
|
||||
#include "library/relation_manager.h"
|
||||
#include "library/projection.h"
|
||||
#include "library/attribute_manager.h"
|
||||
#include "library/private.h"
|
||||
#include "library/decl_stats.h"
|
||||
#include "library/app_builder.h"
|
||||
|
@ -46,7 +45,6 @@ Author: Leonardo de Moura
|
|||
#include "library/congr_lemma_manager.h"
|
||||
#include "library/abstract_expr_manager.h"
|
||||
#include "library/definitional/projection.h"
|
||||
#include "library/blast/simplifier/simp_rule_set.h"
|
||||
#include "library/blast/blast.h"
|
||||
#include "library/blast/simplifier/simplifier.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) {
|
||||
environment const & env = p.env();
|
||||
io_state_stream out = p.regular_stream();
|
||||
if (is_coercion(env, n))
|
||||
out << " [coercion]";
|
||||
if (is_class(env, n))
|
||||
out << " [class]";
|
||||
if (is_instance(env, n))
|
||||
out << " [instance]";
|
||||
if (is_simp_rule(env, n))
|
||||
out << " [simp]";
|
||||
if (is_congr_rule(env, n))
|
||||
out << " [congr]";
|
||||
if (auto light_arg = is_light_rule(env, n))
|
||||
out << " [light " << *light_arg << "]";
|
||||
if (is_backward_rule(env, n))
|
||||
out << " [backward]";
|
||||
if (is_no_pattern(env, n))
|
||||
out << " [no_pattern]";
|
||||
if (is_forward_lemma(env, n))
|
||||
out << " [forward]";
|
||||
if (is_elim_lemma(env, n))
|
||||
out << " [elim]";
|
||||
if (is_intro_lemma(env, n))
|
||||
out << " [intro]";
|
||||
switch (get_reducible_status(env, n)) {
|
||||
case reducible_status::Reducible: out << " [reducible]"; break;
|
||||
case reducible_status::Irreducible: out << " [irreducible]"; break;
|
||||
case reducible_status::Quasireducible: out << " [quasireducible]"; break;
|
||||
case reducible_status::Semireducible: break;
|
||||
buffer<char const *> attrs;
|
||||
get_attributes(attrs);
|
||||
for (char const * attr : attrs) {
|
||||
if (strcmp(attr, "semireducible") == 0)
|
||||
continue;
|
||||
if (has_attribute(env, attr, n)) {
|
||||
out << " " << get_attribute_token(attr);
|
||||
switch (get_attribute_kind(attr)) {
|
||||
case attribute_kind::Default:
|
||||
break;
|
||||
case attribute_kind::Prioritized: {
|
||||
unsigned prio = get_attribute_prio(env, attr, n);
|
||||
if (prio != LEAN_DEFAULT_PRIORITY)
|
||||
out << " [priority " << prio << "]";
|
||||
break;
|
||||
}
|
||||
case attribute_kind::Parametric:
|
||||
case attribute_kind::OptParametric:
|
||||
out << " " << get_attribute_param(env, attr, n) << "]";
|
||||
break;
|
||||
case attribute_kind::MultiParametric: {
|
||||
list<unsigned> ps = get_attribute_params(env, attr, n);
|
||||
for (auto p : ps) {
|
||||
out << " " << p;
|
||||
}
|
||||
out << "]";
|
||||
break;
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -180,6 +180,24 @@ char const * get_attribute_from_token(char const * tk) {
|
|||
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) {
|
||||
lean_assert(is_attribute(attr));
|
||||
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_attribute_tokens(buffer<char const *> &);
|
||||
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);
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
-----------
|
||||
definition id [reducible] : Π {A : Type}, A → A
|
||||
definition id [reducible] [unfold_full] : Π {A : Type}, 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
constant H [backward] : A → B
|
||||
constant G [backward] : A → B → C
|
||||
constant f [backward] : T → A
|
||||
constant H [intro] : A → B
|
||||
constant G [intro] : A → B → C
|
||||
constant f [intro] : T → A
|
||||
backward rules
|
||||
exists_unique ==> exists_unique.intro
|
||||
B ==> H
|
||||
|
|
Loading…
Reference in a new issue