fix(frontends/lean): pretty print numeral notation from algebra
This commit is contained in:
parent
7083f2fccd
commit
cfeb426cd7
4 changed files with 44 additions and 8 deletions
|
@ -767,12 +767,14 @@ bool pretty_fn::match(expr const & p, expr const & e, buffer<optional<expr>> & a
|
||||||
return match(sort_level(p), sort_level(e));
|
return match(sort_level(p), sort_level(e));
|
||||||
} else if (is_app(e)) {
|
} else if (is_app(e)) {
|
||||||
buffer<expr> p_args, e_args;
|
buffer<expr> p_args, e_args;
|
||||||
expr const & p_fn = get_app_args(p, p_args);
|
expr p_fn = get_app_args(p, p_args);
|
||||||
expr const & e_fn = get_app_args(e, e_args);
|
bool consume = is_consume_args(p_fn);
|
||||||
|
if (consume)
|
||||||
|
p_fn = get_consume_args_arg(p_fn);
|
||||||
|
expr e_fn = get_app_args(e, e_args);
|
||||||
if (!match(p_fn, e_fn, args))
|
if (!match(p_fn, e_fn, args))
|
||||||
return false;
|
return false;
|
||||||
bool expl = is_explicit(p);
|
if (is_explicit(p)) {
|
||||||
if (expl) {
|
|
||||||
if (p_args.size() != e_args.size())
|
if (p_args.size() != e_args.size())
|
||||||
return false;
|
return false;
|
||||||
for (unsigned i = 0; i < p_args.size(); i++) {
|
for (unsigned i = 0; i < p_args.size(); i++) {
|
||||||
|
@ -786,14 +788,16 @@ bool pretty_fn::match(expr const & p, expr const & e, buffer<optional<expr>> & a
|
||||||
unsigned j = 0;
|
unsigned j = 0;
|
||||||
for (unsigned i = 0; i < e_args.size(); i++) {
|
for (unsigned i = 0; i < e_args.size(); i++) {
|
||||||
fn_type = m_tc.ensure_pi(fn_type).first;
|
fn_type = m_tc.ensure_pi(fn_type).first;
|
||||||
if (is_explicit(binding_info(fn_type))) {
|
expr const & body = binding_body(fn_type);
|
||||||
|
binder_info const & info = binding_info(fn_type);
|
||||||
|
if ((!consume || closed(body)) && is_explicit(info)) {
|
||||||
if (j >= p_args.size())
|
if (j >= p_args.size())
|
||||||
return false;
|
return false;
|
||||||
if (!match(p_args[j], e_args[i], args))
|
if (!match(p_args[j], e_args[i], args))
|
||||||
return false;
|
return false;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
fn_type = instantiate(binding_body(fn_type), e_args[i]);
|
fn_type = instantiate(body, e_args[i]);
|
||||||
}
|
}
|
||||||
return j == p_args.size();
|
return j == p_args.size();
|
||||||
} catch (exception&) {
|
} catch (exception&) {
|
||||||
|
|
|
@ -5,10 +5,19 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Author: Leonardo de Moura
|
Author: Leonardo de Moura
|
||||||
*/
|
*/
|
||||||
#include "library/head_map.h"
|
#include "library/head_map.h"
|
||||||
|
#include "library/explicit.h"
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
head_index::head_index(expr const & e) {
|
head_index::head_index(expr const & e) {
|
||||||
expr const & f = get_app_fn(e);
|
expr f = get_app_fn(e);
|
||||||
|
while (true) {
|
||||||
|
if (is_explicit(f))
|
||||||
|
f = get_explicit_arg(f);
|
||||||
|
else if (is_consume_args(f))
|
||||||
|
f = get_consume_args_arg(f);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
m_kind = f.kind();
|
m_kind = f.kind();
|
||||||
if (is_constant(f))
|
if (is_constant(f))
|
||||||
m_const_name = const_name(f);
|
m_const_name = const_name(f);
|
||||||
|
|
19
tests/lean/pp_algebra_num_bug.lean
Normal file
19
tests/lean/pp_algebra_num_bug.lean
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import algebra.group
|
||||||
|
open algebra
|
||||||
|
|
||||||
|
variable {A : Type}
|
||||||
|
variable [s : group A]
|
||||||
|
variable (a : A)
|
||||||
|
|
||||||
|
check 1 * 1 * a
|
||||||
|
set_option pp.notation false
|
||||||
|
check 1 * a
|
||||||
|
|
||||||
|
variable [s2 : add_comm_group A]
|
||||||
|
|
||||||
|
set_option pp.notation true
|
||||||
|
|
||||||
|
check 0 + a
|
||||||
|
|
||||||
|
set_option pp.notation false
|
||||||
|
check 0 + a
|
4
tests/lean/pp_algebra_num_bug.lean.expected.out
Normal file
4
tests/lean/pp_algebra_num_bug.lean.expected.out
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
1 * 1 * a : A
|
||||||
|
has_mul.mul (has_one.one A) a : A
|
||||||
|
0 + a : A
|
||||||
|
has_add.add (has_zero.zero A) a : A
|
Loading…
Reference in a new issue