feat(frontends/lean): improve '--info' command line option

see issue #756
This commit is contained in:
Leonardo de Moura 2015-07-30 11:05:39 -07:00
parent c390550340
commit a39cac4fad
2 changed files with 26 additions and 4 deletions

View file

@ -169,7 +169,7 @@ static bool uses_some_token(unsigned num, notation::transition const * ts, buffe
std::any_of(tokens.begin(), tokens.end(), [&](name const & token) { return uses_token(num, ts, token); });
}
static bool print_parse_table(parser const & p, parse_table const & t, bool nud, buffer<name> const & tokens) {
static bool print_parse_table(parser const & p, parse_table const & t, bool nud, buffer<name> const & tokens, bool tactic_table = false) {
bool found = false;
io_state ios = p.ios();
options os = ios.get_options();
@ -180,8 +180,10 @@ static bool print_parse_table(parser const & p, parse_table const & t, bool nud,
optional<token_table> tt(get_token_table(p.env()));
t.for_each([&](unsigned num, notation::transition const * ts, list<pair<unsigned, expr>> const & overloads) {
if (uses_some_token(num, ts, tokens)) {
found = true;
io_state_stream out = regular(p.env(), ios);
if (tactic_table)
out << "tactic notation ";
found = true;
notation::display(out, num, ts, overloads, nud, tt);
}
});
@ -410,6 +412,13 @@ bool print_token_info(parser const & p, name const & tk) {
if (print_parse_table(p, get_led_table(p.env()), false, tokens)) {
found = true;
}
bool tactic_table = true;
if (print_parse_table(p, get_tactic_nud_table(p.env()), true, tokens, tactic_table)) {
found = true;
}
if (print_parse_table(p, get_tactic_led_table(p.env()), false, tokens, tactic_table)) {
found = true;
}
return found;
}

View file

@ -176,10 +176,15 @@ void parser::scan() {
name const & id = get_name_val();
if (p.second <= m_info_at_col && m_info_at_col < p.second + id.size()) {
print_lean_info_header(regular_stream().get_stream());
bool ok = true;
try {
bool show_value = false;
print_id_info(*this, id, show_value, p);
} catch (exception &) {}
ok = print_id_info(*this, id, show_value, p);
} catch (exception &) {
ok = false;
}
if (!ok)
regular_stream() << "unknown identifier '" << id << "'\n";
print_lean_info_footer(regular_stream().get_stream());
m_info_at = false;
}
@ -193,6 +198,14 @@ void parser::scan() {
print_lean_info_footer(regular_stream().get_stream());
m_info_at = false;
}
} else if (curr_is_command()) {
name const & tk = get_token_info().token();
if (p.second <= m_info_at_col && m_info_at_col < p.second + tk.size()) {
print_lean_info_header(regular_stream().get_stream());
regular_stream() << "'" << tk << "' is a command\n";
print_lean_info_footer(regular_stream().get_stream());
m_info_at = false;
}
}
}
} else {