fix(frontends/lean/builtin_cmds): print patterns
This commit is contained in:
parent
05477d34bb
commit
e4e9c30e66
3 changed files with 41 additions and 14 deletions
|
@ -231,6 +231,23 @@ static void print_metaclasses(parser const & p) {
|
||||||
p.regular_stream() << "[" << n << "]" << endl;
|
p.regular_stream() << "[" << n << "]" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_patterns(io_state_stream const & out, environment const & env, name const & n) {
|
||||||
|
if (auto lemma = get_hi_lemma(env, n)) {
|
||||||
|
if (lemma->m_multi_patterns) {
|
||||||
|
out << "(multi-)patterns:\n";
|
||||||
|
for (multi_pattern const & mp : lemma->m_multi_patterns) {
|
||||||
|
out << "{";
|
||||||
|
bool first = true;
|
||||||
|
for (expr const & p : mp) {
|
||||||
|
if (first) first = false; else out << ", ";
|
||||||
|
out << p;
|
||||||
|
}
|
||||||
|
out << "}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void print_definition(parser const & p, name const & n, pos_info const & pos) {
|
static void print_definition(parser const & p, name const & n, pos_info const & pos) {
|
||||||
environment const & env = p.env();
|
environment const & env = p.env();
|
||||||
declaration d = env.get(n);
|
declaration d = env.get(n);
|
||||||
|
@ -244,20 +261,6 @@ static void print_definition(parser const & p, name const & n, pos_info const &
|
||||||
if (!d.is_definition())
|
if (!d.is_definition())
|
||||||
throw parser_error(sstream() << "invalid 'print definition', '" << n << "' is not a definition", pos);
|
throw parser_error(sstream() << "invalid 'print definition', '" << n << "' is not a definition", pos);
|
||||||
new_out << d.get_value() << endl;
|
new_out << d.get_value() << endl;
|
||||||
if (auto lemma = get_hi_lemma(env, n)) {
|
|
||||||
if (lemma->m_multi_patterns) {
|
|
||||||
new_out << "(multi-)patterns:\n";
|
|
||||||
for (multi_pattern const & mp : lemma->m_multi_patterns) {
|
|
||||||
new_out << "{";
|
|
||||||
bool first = true;
|
|
||||||
for (expr const & p : mp) {
|
|
||||||
if (first) first = false; else new_out << ", ";
|
|
||||||
new_out << p;
|
|
||||||
}
|
|
||||||
new_out << "}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_attributes(parser const & p, name const & n) {
|
static void print_attributes(parser const & p, name const & n) {
|
||||||
|
@ -414,6 +417,7 @@ bool print_id_info(parser const & p, name const & id, bool show_value, pos_info
|
||||||
if (show_value)
|
if (show_value)
|
||||||
print_definition(p, c, pos);
|
print_definition(p, c, pos);
|
||||||
}
|
}
|
||||||
|
print_patterns(out, env, c);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (exception & ex) {}
|
} catch (exception & ex) {}
|
||||||
|
|
17
tests/lean/run/pattern2.lean
Normal file
17
tests/lean/run/pattern2.lean
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
constant f : nat → nat → nat
|
||||||
|
constant g : nat → nat → nat
|
||||||
|
attribute g [no_pattern]
|
||||||
|
|
||||||
|
namespace foo
|
||||||
|
|
||||||
|
definition lemma1 [forward] {a b : nat} : f a b = g a b :=
|
||||||
|
sorry
|
||||||
|
|
||||||
|
end foo
|
||||||
|
|
||||||
|
print foo.lemma1
|
||||||
|
open foo
|
||||||
|
print foo.lemma1
|
||||||
|
attribute foo.lemma1 [forward]
|
||||||
|
|
||||||
|
print foo.lemma1
|
6
tests/lean/run/pattern3.lean
Normal file
6
tests/lean/run/pattern3.lean
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
constant Sum : (nat → nat) → nat → nat
|
||||||
|
|
||||||
|
lemma l1 [forward] (f : nat → nat) : Sum f 0 = 0 :=
|
||||||
|
sorry
|
||||||
|
|
||||||
|
print l1
|
Loading…
Reference in a new issue