lean2/src/kernel/formatter.cpp
Leonardo de Moura d843d432d3 refactor(kernel): move printer and formatter objects to the kernel
The printer and formatter objects are not trusted code.
We moved them to the kernel to be able to provide them as an argument to the trace objects.
Another motivation is to eliminate the kernel_exception_formatter hack.
With the formatter in the kernel, we can implement the pretty printer for kernel exceptions as a virtual method.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-22 08:15:36 -07:00

38 lines
1.2 KiB
C++

/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <sstream>
#include "kernel/kernel_exception.h"
#include "kernel/printer.h"
#include "kernel/formatter.h"
namespace lean {
class simple_formatter_cell : public formatter_cell {
public:
virtual format operator()(expr const & e, options const &) {
std::ostringstream s; s << e; return format(s.str());
}
virtual format operator()(context const & c, options const &) {
std::ostringstream s; s << c; return format(s.str());
}
virtual format operator()(context const & c, expr const & e, bool format_ctx, options const &) {
std::ostringstream s;
if (format_ctx)
s << c << " |- ";
s << mk_pair(e, c);
return format(s.str());
}
virtual format operator()(object const & obj, options const &) {
std::ostringstream s; s << obj; return format(s.str());
}
virtual format operator()(environment const & env, options const &) {
std::ostringstream s; s << env; return format(s.str());
}
};
formatter mk_simple_formatter() {
return formatter(new simple_formatter_cell());
}
}