2014-02-18 00:10:11 +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
|
|
|
|
*/
|
2014-05-17 19:30:03 +00:00
|
|
|
#include <utility>
|
2015-03-13 19:42:57 +00:00
|
|
|
#include "util/sexpr/option_declarations.h"
|
2014-02-18 00:10:11 +00:00
|
|
|
#include "kernel/formatter.h"
|
|
|
|
|
2015-03-13 19:42:57 +00:00
|
|
|
#ifndef LEAN_DEFAULT_FORMATTER_HIDE_FULL_TERMS
|
|
|
|
#define LEAN_DEFAULT_FORMATTER_HIDE_FULL_TERMS false
|
|
|
|
#endif
|
|
|
|
|
2014-02-18 00:10:11 +00:00
|
|
|
namespace lean {
|
2015-03-13 19:42:57 +00:00
|
|
|
static name * g_formatter_hide_full = nullptr;
|
|
|
|
|
|
|
|
name const & get_formatter_hide_full_terms_name() { return *g_formatter_hide_full; }
|
|
|
|
bool get_formatter_hide_full_terms(options const & opts) { return opts.get_bool(*g_formatter_hide_full, LEAN_DEFAULT_FORMATTER_HIDE_FULL_TERMS); }
|
|
|
|
|
2014-09-23 19:09:13 +00:00
|
|
|
static std::function<void(std::ostream &, expr const & e)> * g_print = nullptr;
|
2014-08-01 22:07:01 +00:00
|
|
|
|
2014-08-22 17:26:45 +00:00
|
|
|
void set_print_fn(std::function<void(std::ostream &, expr const &)> const & fn) {
|
2015-03-28 19:16:39 +00:00
|
|
|
delete g_print;
|
2014-09-23 19:09:13 +00:00
|
|
|
g_print = new std::function<void(std::ostream &, expr const &)>(fn);
|
2014-05-17 19:30:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 17:26:45 +00:00
|
|
|
std::ostream & operator<<(std::ostream & out, expr const & e) {
|
|
|
|
if (g_print) {
|
|
|
|
(*g_print)(out, e);
|
2014-06-26 21:58:59 +00:00
|
|
|
} else {
|
2014-08-22 17:26:45 +00:00
|
|
|
throw exception("print function is not available, Lean was not initialized correctly");
|
2014-02-18 00:10:11 +00:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print(lean::expr const & a) { std::cout << a << std::endl; }
|
2014-09-23 19:09:13 +00:00
|
|
|
|
2015-03-13 19:42:57 +00:00
|
|
|
void initialize_formatter() {
|
|
|
|
g_formatter_hide_full = new name{"formatter", "hide_full_terms"};
|
|
|
|
register_bool_option(*g_formatter_hide_full, LEAN_DEFAULT_FORMATTER_HIDE_FULL_TERMS,
|
|
|
|
"(formatter) replace terms which do not contain metavariables with `...`");
|
|
|
|
}
|
2014-09-23 19:09:13 +00:00
|
|
|
|
|
|
|
void finalize_formatter() {
|
2015-03-13 19:42:57 +00:00
|
|
|
delete g_formatter_hide_full;
|
2015-03-28 19:16:39 +00:00
|
|
|
delete g_print;
|
2014-09-23 19:09:13 +00:00
|
|
|
}
|
2014-02-18 00:10:11 +00:00
|
|
|
}
|