2013-08-17 01:34:11 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include "context.h"
|
2013-08-20 19:19:28 +00:00
|
|
|
#include "options.h"
|
2013-08-17 01:34:11 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
class environment;
|
2013-08-17 17:55:42 +00:00
|
|
|
class object;
|
2013-08-17 01:34:11 +00:00
|
|
|
/**
|
|
|
|
\brief API for formatting expressions, contexts and environments.
|
|
|
|
*/
|
2013-08-17 18:29:43 +00:00
|
|
|
class formatter_cell {
|
2013-08-17 01:34:11 +00:00
|
|
|
public:
|
2013-08-17 18:29:43 +00:00
|
|
|
virtual ~formatter_cell() {}
|
2013-08-17 01:34:11 +00:00
|
|
|
/** \brief Format the given expression. */
|
2013-08-20 19:19:28 +00:00
|
|
|
virtual format operator()(expr const & e, options const & opts) = 0;
|
2013-08-17 01:34:11 +00:00
|
|
|
/** \brief Format the given context. */
|
2013-08-20 19:19:28 +00:00
|
|
|
virtual format operator()(context const & c, options const & opts) = 0;
|
2013-08-17 01:34:11 +00:00
|
|
|
/**
|
|
|
|
\brief Format the given expression with respect to the given
|
|
|
|
context.
|
|
|
|
|
|
|
|
\remark If format_ctx == false, then the context is not formatted. It just provides names
|
|
|
|
for the free variables
|
|
|
|
*/
|
2013-08-20 19:19:28 +00:00
|
|
|
virtual format operator()(context const & c, expr const & e, bool format_ctx, options const & opts) = 0;
|
2013-08-17 17:55:42 +00:00
|
|
|
/** \brief Format the given object */
|
2013-08-20 19:19:28 +00:00
|
|
|
virtual format operator()(object const & obj, options const & opts) = 0;
|
2013-08-17 01:34:11 +00:00
|
|
|
/** \brief Format the given environment */
|
2013-08-20 19:19:28 +00:00
|
|
|
virtual format operator()(environment const & env, options const & opts) = 0;
|
2013-08-24 23:11:35 +00:00
|
|
|
/** \brief Request interruption */
|
|
|
|
virtual void set_interrupt(bool flag) {}
|
2013-08-17 01:34:11 +00:00
|
|
|
};
|
2013-08-24 20:16:43 +00:00
|
|
|
class kernel_exception;
|
2013-08-17 18:29:43 +00:00
|
|
|
class formatter {
|
|
|
|
std::shared_ptr<formatter_cell> m_cell;
|
|
|
|
public:
|
|
|
|
formatter(formatter_cell * c):m_cell(c) {}
|
|
|
|
formatter(std::shared_ptr<formatter_cell> const & c):m_cell(c) {}
|
2013-08-20 19:19:28 +00:00
|
|
|
format operator()(expr const & e, options const & opts = options()) { return (*m_cell)(e, opts); }
|
|
|
|
format operator()(context const & c, options const & opts = options()) { return (*m_cell)(c, opts); }
|
|
|
|
format operator()(context const & c, expr const & e, bool format_ctx = false, options const & opts = options()) { return (*m_cell)(c, e, format_ctx, opts); }
|
|
|
|
format operator()(object const & obj, options const & opts = options()) { return (*m_cell)(obj, opts); }
|
|
|
|
format operator()(environment const & env, options const & opts = options()) { return (*m_cell)(env, opts); }
|
2013-08-24 20:16:43 +00:00
|
|
|
/** \brief Pretty print a kernel exception using the this formatter */
|
|
|
|
format operator()(kernel_exception const & ex, options const & opts = options());
|
2013-08-24 23:11:35 +00:00
|
|
|
void set_interrupt(bool flag) { m_cell->set_interrupt(flag); }
|
2013-08-17 18:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
formatter mk_simple_formatter();
|
2013-08-17 01:34:11 +00:00
|
|
|
}
|