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>
|
2014-02-18 00:10:11 +00:00
|
|
|
#include "kernel/formatter.h"
|
|
|
|
|
|
|
|
namespace lean {
|
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) {
|
2014-09-23 19:09:13 +00:00
|
|
|
if (g_print)
|
|
|
|
delete g_print;
|
|
|
|
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
|
|
|
|
|
|
|
void initialize_formatter() {}
|
|
|
|
|
|
|
|
void finalize_formatter() {
|
|
|
|
if (g_print)
|
|
|
|
delete g_print;
|
|
|
|
}
|
2014-02-18 00:10:11 +00:00
|
|
|
}
|