feat(frontends/lean): add 'coercions' and 'instances' to 'print' command, closes #71
This commit is contained in:
parent
c9e5e40477
commit
16562adb87
4 changed files with 45 additions and 1 deletions
|
@ -15,7 +15,7 @@
|
|||
"options" "precedence" "postfix" "prefix" "calc_trans" "calc_subst" "calc_refl"
|
||||
"infix" "infixl" "infixr" "notation" "eval" "check" "exit" "coercion" "end"
|
||||
"using" "namespace" "instance" "class" "section"
|
||||
"set_option" "add_rewrite" "extends" "include" "omit")
|
||||
"set_option" "add_rewrite" "extends" "include" "omit" "instances" "coercions" "raw")
|
||||
"lean keywords")
|
||||
|
||||
(defconst lean-syntax-table
|
||||
|
|
|
@ -29,8 +29,29 @@ Author: Leonardo de Moura
|
|||
#include "frontends/lean/class.h"
|
||||
#include "frontends/lean/tactic_hint.h"
|
||||
#include "frontends/lean/tokens.h"
|
||||
#include "frontends/lean/pp_options.h"
|
||||
|
||||
namespace lean {
|
||||
static void print_coercions(parser & p, optional<name> const & C) {
|
||||
environment const & env = p.env();
|
||||
options opts = p.regular_stream().get_options();
|
||||
opts = opts.update(get_pp_coercions_option_name(), true);
|
||||
io_state_stream out = p.regular_stream().update_options(opts);
|
||||
char const * arrow = get_pp_unicode(opts) ? "↣" : ">->";
|
||||
for_each_coercion_user(env, [&](name const & C1, name const & D, expr const & c, level_param_names const &, unsigned) {
|
||||
if (!C || *C == C1)
|
||||
out << C1 << " " << arrow << " " << D << " : " << c << endl;
|
||||
});
|
||||
for_each_coercion_sort(env, [&](name const & C1, expr const & c, level_param_names const &, unsigned) {
|
||||
if (!C || *C == C1)
|
||||
out << C1 << " " << arrow << " [sort-class] : " << c << endl;
|
||||
});
|
||||
for_each_coercion_fun(env, [&](name const & C1, expr const & c, level_param_names const &, unsigned) {
|
||||
if (!C || *C == C1)
|
||||
out << C1 << " " << arrow << " [fun-class] : " << c << endl;
|
||||
});
|
||||
}
|
||||
|
||||
environment print_cmd(parser & p) {
|
||||
if (p.curr() == scanner::token_kind::String) {
|
||||
p.regular_stream() << p.get_str_val() << endl;
|
||||
|
@ -42,6 +63,19 @@ environment print_cmd(parser & p) {
|
|||
} else if (p.curr_is_token_or_id(get_options_tk())) {
|
||||
p.next();
|
||||
p.regular_stream() << p.ios().get_options() << endl;
|
||||
} else if (p.curr_is_token_or_id(get_instances_tk())) {
|
||||
p.next();
|
||||
name c = p.check_constant_next("invalid 'print instances', constant expected");
|
||||
environment const & env = p.env();
|
||||
for (name const & i : get_class_instances(env, c)) {
|
||||
p.regular_stream() << i << " : " << env.get(i).get_type() << endl;
|
||||
}
|
||||
} else if (p.curr_is_token_or_id(get_coercions_tk())) {
|
||||
p.next();
|
||||
optional<name> C;
|
||||
if (p.curr_is_identifier())
|
||||
C = p.check_constant_next("invalid 'print coercions', constant expected");
|
||||
print_coercions(p, C);
|
||||
} else {
|
||||
throw parser_error("invalid print command", p.pos());
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ static name * g_raw = nullptr;
|
|||
static name * g_true = nullptr;
|
||||
static name * g_false = nullptr;
|
||||
static name * g_options = nullptr;
|
||||
static name * g_instances = nullptr;
|
||||
static name * g_coercions = nullptr;
|
||||
static name * g_arrow = nullptr;
|
||||
static name * g_declarations = nullptr;
|
||||
static name * g_decls = nullptr;
|
||||
|
@ -116,6 +118,8 @@ void initialize_tokens() {
|
|||
g_true = new name("true");
|
||||
g_false = new name("false");
|
||||
g_options = new name("options");
|
||||
g_instances = new name("instances");
|
||||
g_coercions = new name("coercions");
|
||||
g_arrow = new name("->");
|
||||
g_declarations = new name("declarations");
|
||||
g_decls = new name("decls");
|
||||
|
@ -206,6 +210,8 @@ void finalize_tokens() {
|
|||
delete g_true;
|
||||
delete g_false;
|
||||
delete g_options;
|
||||
delete g_instances;
|
||||
delete g_coercions;
|
||||
delete g_arrow;
|
||||
delete g_declarations;
|
||||
delete g_decls;
|
||||
|
@ -275,6 +281,8 @@ name const & get_raw_tk() { return *g_raw; }
|
|||
name const & get_true_tk() { return *g_true; }
|
||||
name const & get_false_tk() { return *g_false; }
|
||||
name const & get_options_tk() { return *g_options; }
|
||||
name const & get_instances_tk() { return *g_instances; }
|
||||
name const & get_coercions_tk() { return *g_coercions; }
|
||||
name const & get_arrow_tk() { return *g_arrow; }
|
||||
name const & get_declarations_tk() { return *g_declarations; }
|
||||
name const & get_decls_tk() { return *g_decls; }
|
||||
|
|
|
@ -39,6 +39,8 @@ name const & get_raw_tk();
|
|||
name const & get_true_tk();
|
||||
name const & get_false_tk();
|
||||
name const & get_options_tk();
|
||||
name const & get_instances_tk();
|
||||
name const & get_coercions_tk();
|
||||
name const & get_arrow_tk();
|
||||
name const & get_declarations_tk();
|
||||
name const & get_decls_tk();
|
||||
|
|
Loading…
Reference in a new issue