2014-07-09 08:12:36 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <utility>
|
|
|
|
#include <limits>
|
2014-08-19 23:28:58 +00:00
|
|
|
#include "util/pair.h"
|
2014-07-09 08:12:36 +00:00
|
|
|
#include "util/name_map.h"
|
|
|
|
#include "util/name_set.h"
|
|
|
|
#include "util/sexpr/options.h"
|
|
|
|
#include "util/sexpr/format.h"
|
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "kernel/type_checker.h"
|
2014-10-19 15:40:56 +00:00
|
|
|
#include "frontends/lean/token_table.h"
|
2014-07-09 08:12:36 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-10-19 15:40:56 +00:00
|
|
|
class notation_entry;
|
|
|
|
|
2014-07-09 08:12:36 +00:00
|
|
|
class pretty_fn {
|
|
|
|
public:
|
2014-10-19 15:40:56 +00:00
|
|
|
static unsigned max_bp() { return std::numeric_limits<unsigned>::max(); }
|
|
|
|
class result {
|
|
|
|
unsigned m_lbp;
|
|
|
|
unsigned m_rbp;
|
|
|
|
format m_fmt;
|
|
|
|
public:
|
|
|
|
result():m_lbp(max_bp()), m_rbp(max_bp()) {}
|
|
|
|
result(format const & fmt):m_lbp(max_bp()), m_rbp(max_bp()), m_fmt(fmt) {}
|
|
|
|
result(unsigned rbp, format const & fmt):m_lbp(max_bp()), m_rbp(rbp), m_fmt(fmt) {}
|
|
|
|
result(unsigned lbp, unsigned rbp, format const & fmt):m_lbp(lbp), m_rbp(rbp), m_fmt(fmt) {}
|
|
|
|
unsigned lbp() const { return m_lbp; }
|
|
|
|
unsigned rbp() const { return m_rbp; }
|
|
|
|
format const & fmt() const { return m_fmt; }
|
|
|
|
};
|
2014-07-09 08:12:36 +00:00
|
|
|
private:
|
2014-10-19 15:40:56 +00:00
|
|
|
environment m_env;
|
|
|
|
type_checker m_tc;
|
|
|
|
token_table const & m_token_table;
|
|
|
|
unsigned m_num_steps;
|
|
|
|
unsigned m_depth;
|
|
|
|
name m_meta_prefix;
|
|
|
|
unsigned m_next_meta_idx;
|
|
|
|
name_map<name> m_purify_meta_table;
|
|
|
|
name_map<name> m_purify_local_table;
|
|
|
|
name_set m_purify_used_locals;
|
2014-07-09 08:12:36 +00:00
|
|
|
// cached configuration
|
2014-10-19 15:40:56 +00:00
|
|
|
options m_options;
|
|
|
|
unsigned m_indent;
|
|
|
|
unsigned m_max_depth;
|
|
|
|
unsigned m_max_steps;
|
|
|
|
bool m_implict; //!< if true show implicit arguments
|
|
|
|
bool m_unicode; //!< if true use unicode chars
|
|
|
|
bool m_coercion; //!< if true show coercions
|
|
|
|
bool m_notation;
|
|
|
|
bool m_universes;
|
|
|
|
bool m_full_names;
|
|
|
|
bool m_private_names;
|
|
|
|
bool m_metavar_args;
|
|
|
|
bool m_beta;
|
2014-07-09 08:12:36 +00:00
|
|
|
|
|
|
|
name mk_metavar_name(name const & m);
|
2014-07-10 13:13:51 +00:00
|
|
|
name mk_local_name(name const & n, name const & suggested);
|
2014-07-09 08:12:36 +00:00
|
|
|
level purify(level const & l);
|
|
|
|
expr purify(expr const & e);
|
|
|
|
bool is_implicit(expr const & f);
|
|
|
|
bool is_prop(expr const & e);
|
2014-09-03 00:09:57 +00:00
|
|
|
bool has_implicit_args(expr const & f);
|
2014-10-01 18:24:45 +00:00
|
|
|
optional<name> is_aliased(name const & n) const;
|
2014-07-09 08:12:36 +00:00
|
|
|
|
|
|
|
format pp_binder_block(buffer<name> const & names, expr const & type, binder_info const & bi);
|
|
|
|
format pp_binders(buffer<expr> const & locals);
|
|
|
|
format pp_level(level const & l);
|
|
|
|
|
2014-10-19 15:40:56 +00:00
|
|
|
bool match(level const & p, level const & l);
|
|
|
|
bool match(expr const & p, expr const & e, buffer<optional<expr>> & args);
|
|
|
|
result pp_notation_child(expr const & e, unsigned lbp, unsigned rbp);
|
|
|
|
optional<result> pp_notation(notation_entry const & entry, buffer<optional<expr>> & args);
|
|
|
|
optional<result> pp_notation(expr const & e);
|
|
|
|
|
2014-09-20 16:56:46 +00:00
|
|
|
result pp_coercion_fn(expr const & e, unsigned sz);
|
2014-09-09 19:46:55 +00:00
|
|
|
result pp_coercion(expr const & e, unsigned bp);
|
|
|
|
result pp_child_core(expr const & e, unsigned bp);
|
2014-07-09 08:12:36 +00:00
|
|
|
result pp_child(expr const & e, unsigned bp);
|
|
|
|
result pp_var(expr const & e);
|
|
|
|
result pp_sort(expr const & e);
|
|
|
|
result pp_const(expr const & e);
|
|
|
|
result pp_meta(expr const & e);
|
|
|
|
result pp_local(expr const & e);
|
|
|
|
result pp_app(expr const & e);
|
|
|
|
result pp_lambda(expr const & e);
|
|
|
|
result pp_pi(expr const & e);
|
2014-07-27 04:35:26 +00:00
|
|
|
result pp_have(expr const & e);
|
2014-07-27 04:56:35 +00:00
|
|
|
result pp_show(expr const & e);
|
2014-07-09 08:12:36 +00:00
|
|
|
result pp_macro(expr const & e);
|
2014-07-29 21:26:27 +00:00
|
|
|
result pp_explicit(expr const & e);
|
2014-08-29 01:20:58 +00:00
|
|
|
result pp_let(expr e);
|
2014-08-14 16:11:34 +00:00
|
|
|
result pp_num(mpz const & n);
|
2014-07-27 16:41:25 +00:00
|
|
|
void set_options_core(options const & o);
|
2014-07-09 08:12:36 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
pretty_fn(environment const & env, options const & o);
|
|
|
|
result pp(expr const & e);
|
2014-07-27 16:41:25 +00:00
|
|
|
void set_options(options const & o);
|
|
|
|
options const & get_options() const { return m_options; }
|
2014-07-09 08:12:36 +00:00
|
|
|
format operator()(expr const & e);
|
|
|
|
};
|
|
|
|
|
2014-07-10 17:32:00 +00:00
|
|
|
formatter_factory mk_pretty_formatter_factory();
|
2014-09-23 17:00:36 +00:00
|
|
|
void initialize_pp();
|
|
|
|
void finalize_pp();
|
2014-07-09 08:12:36 +00:00
|
|
|
}
|