refactor(frontends/lean/parser): cleanup method apply_tactics
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
1ff6013594
commit
e4dff52d7a
1 changed files with 33 additions and 52 deletions
|
@ -1521,31 +1521,13 @@ class parser::imp {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Try to fill the 'holes' in \c val using tactics.
|
\brief Try to fill the 'holes' in \c val using tactics.
|
||||||
The expression \c expected_type is the type of \c val.
|
|
||||||
The metavar_env \c menv contains the definition of the metavariables occurring in \c val.
|
The metavar_env \c menv contains the definition of the metavariables occurring in \c val.
|
||||||
|
|
||||||
If a 'hole' is associated with a "hint tactic" ('show-by' and 'by' constructs),
|
If a 'hole' is associated with a "hint tactic" ('show-by' and 'by' constructs),
|
||||||
then this will be the tactic used to "fill" the hole. Otherwise,
|
then this will be the tactic used to "fill" the hole. Otherwise,
|
||||||
a tactic command sequence is expected in the input stream being parsed.
|
a tactic command sequence is expected in the input stream being parsed.
|
||||||
*/
|
*/
|
||||||
expr apply_tactics(expr const & expected_type, expr const & val, metavar_env & menv) {
|
expr apply_tactics(expr const & val, metavar_env & menv) {
|
||||||
if (is_metavar(val)) {
|
|
||||||
// simple case
|
|
||||||
if (!m_type_inferer.is_proposition(expected_type))
|
|
||||||
throw exception("failed to synthesize metavar, its type is not a proposition");
|
|
||||||
proof_state s = to_proof_state(m_frontend, context(), expected_type);
|
|
||||||
std::pair<tactic, pos_info> hint_and_pos = get_tactic_tactic_for(val);
|
|
||||||
if (hint_and_pos.first) {
|
|
||||||
// metavariable has an associated tactic hint
|
|
||||||
s = apply_tactic(s, hint_and_pos.first, hint_and_pos.second).first;
|
|
||||||
return mk_proof_for(s, hint_and_pos.second, context(), expected_type);
|
|
||||||
} else {
|
|
||||||
display_proof_state_if_interactive(s);
|
|
||||||
show_tactic_prompt();
|
|
||||||
check_period_next("invalid theorem, '.' expected before tactical proof");
|
|
||||||
return parse_tactic_cmds(s, context(), expected_type);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buffer<expr> mvars;
|
buffer<expr> mvars;
|
||||||
for_each(val, [&](expr const & e, unsigned) {
|
for_each(val, [&](expr const & e, unsigned) {
|
||||||
if (is_metavar(e)) {
|
if (is_metavar(e)) {
|
||||||
|
@ -1586,7 +1568,6 @@ class parser::imp {
|
||||||
}
|
}
|
||||||
return instantiate_metavars(val, menv);
|
return instantiate_metavars(val, menv);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Auxiliary method used for parsing definitions and theorems. */
|
/** \brief Auxiliary method used for parsing definitions and theorems. */
|
||||||
void parse_def_core(bool is_definition) {
|
void parse_def_core(bool is_definition) {
|
||||||
|
@ -1629,7 +1610,7 @@ class parser::imp {
|
||||||
if (has_metavar(type))
|
if (has_metavar(type))
|
||||||
throw exception("invalid definition, type still contains metavariables after elaboration");
|
throw exception("invalid definition, type still contains metavariables after elaboration");
|
||||||
if (!is_definition && has_metavar(val)) {
|
if (!is_definition && has_metavar(val)) {
|
||||||
val = apply_tactics(type, val, menv);
|
val = apply_tactics(val, menv);
|
||||||
}
|
}
|
||||||
if (has_metavar(val))
|
if (has_metavar(val))
|
||||||
throw exception("invalid definition, value still contains metavariables after elaboration");
|
throw exception("invalid definition, value still contains metavariables after elaboration");
|
||||||
|
|
Loading…
Reference in a new issue