feat(frontends/lean/pp): pretty print numerals

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-14 09:11:34 -07:00
parent ebbca0d613
commit 28b7d87f1f
4 changed files with 34 additions and 0 deletions

View file

@ -15,6 +15,7 @@ Author: Leonardo de Moura
#include "library/placeholder.h" #include "library/placeholder.h"
#include "library/private.h" #include "library/private.h"
#include "library/explicit.h" #include "library/explicit.h"
#include "library/num.h"
#include "frontends/lean/pp.h" #include "frontends/lean/pp.h"
#include "frontends/lean/pp_options.h" #include "frontends/lean/pp_options.h"
#include "frontends/lean/token_table.h" #include "frontends/lean/token_table.h"
@ -403,6 +404,10 @@ auto pretty_fn::pp_macro(expr const & e) -> result {
} }
} }
auto pretty_fn::pp_num(mpz const & n) -> result {
return mk_result(format(n));
}
auto pretty_fn::pp(expr const & e) -> result { auto pretty_fn::pp(expr const & e) -> result {
if (m_depth > m_max_depth || m_num_steps > m_max_steps) if (m_depth > m_max_depth || m_num_steps > m_max_steps)
return mk_result(m_unicode ? g_ellipsis_n_fmt : g_ellipsis_fmt); return mk_result(m_unicode ? g_ellipsis_n_fmt : g_ellipsis_fmt);
@ -413,6 +418,7 @@ auto pretty_fn::pp(expr const & e) -> result {
if (is_show(e)) return pp_show(e); if (is_show(e)) return pp_show(e);
if (is_let(e)) return pp_let(e); if (is_let(e)) return pp_let(e);
if (is_have(e)) return pp_have(e); if (is_have(e)) return pp_have(e);
if (auto n = to_num(e)) return pp_num(*n);
if (!m_metavar_args && is_meta(e)) return pp_meta(get_app_fn(e)); if (!m_metavar_args && is_meta(e)) return pp_meta(get_app_fn(e));
switch (e.kind()) { switch (e.kind()) {

View file

@ -70,6 +70,7 @@ private:
result pp_show(expr const & e); result pp_show(expr const & e);
result pp_macro(expr const & e); result pp_macro(expr const & e);
result pp_explicit(expr const & e); result pp_explicit(expr const & e);
result pp_num(mpz const & n);
void set_options_core(options const & o); void set_options_core(options const & o);
public: public:

15
tests/lean/num.lean Normal file
View file

@ -0,0 +1,15 @@
import data.num
using num
check 10
check 20
check 3
check 1
check 0
check 12
check 13
check 12138
check 1221
check 11
check 5
check 21

View file

@ -0,0 +1,12 @@
10 : num
20 : num
3 : num
1 : num
0 : num
12 : num
13 : num
12138 : num
1221 : num
11 : num
5 : num
21 : num