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>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/sexpr/options.h"
|
2014-02-18 00:10:11 +00:00
|
|
|
#include "kernel/expr.h"
|
2013-08-17 01:34:11 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
|
|
|
\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;
|
2014-02-18 00:10:11 +00:00
|
|
|
#if 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-12-13 00:33:31 +00:00
|
|
|
virtual format operator()(ro_environment const & env, options const & opts) = 0;
|
2013-12-09 00:53:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Return environment object associated with this formatter.
|
|
|
|
Not every formatter has an associated environment object.
|
|
|
|
*/
|
2013-12-13 00:33:31 +00:00
|
|
|
virtual optional<ro_environment> get_environment() const { return optional<ro_environment>(); }
|
2014-02-18 00:10:11 +00:00
|
|
|
#endif
|
2013-08-17 01:34:11 +00:00
|
|
|
};
|
2013-09-04 06:15:37 +00:00
|
|
|
/**
|
|
|
|
\brief Smart-pointer for the actual formatter object (aka \c formatter_cell).
|
|
|
|
*/
|
2013-08-17 18:29:43 +00:00
|
|
|
class formatter {
|
|
|
|
std::shared_ptr<formatter_cell> m_cell;
|
|
|
|
formatter(formatter_cell * c):m_cell(c) {}
|
2013-12-08 23:39:26 +00:00
|
|
|
public:
|
2013-09-05 16:51:17 +00:00
|
|
|
format operator()(expr const & e, options const & opts = options()) const { return (*m_cell)(e, opts); }
|
2014-02-18 00:10:11 +00:00
|
|
|
#if 0
|
2013-09-05 16:51:17 +00:00
|
|
|
format operator()(object const & obj, options const & opts = options()) const { return (*m_cell)(obj, opts); }
|
2013-12-13 00:33:31 +00:00
|
|
|
format operator()(ro_environment const & env, options const & opts = options()) const { return (*m_cell)(env, opts); }
|
|
|
|
optional<ro_environment> get_environment() { return m_cell->get_environment(); }
|
2014-02-18 00:10:11 +00:00
|
|
|
#endif
|
2013-12-09 02:54:04 +00:00
|
|
|
template<typename FCell> friend formatter mk_formatter(FCell && fcell);
|
2013-08-17 18:29:43 +00:00
|
|
|
};
|
2013-12-08 23:39:26 +00:00
|
|
|
|
2013-12-09 02:54:04 +00:00
|
|
|
template<typename FCell> formatter mk_formatter(FCell && fcell) {
|
|
|
|
return formatter(new FCell(std::forward<FCell>(fcell)));
|
|
|
|
}
|
2014-02-18 00:10:11 +00:00
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & out, expr const & e);
|
|
|
|
/**
|
|
|
|
\brief Create a simple formatter object based on operator<<
|
|
|
|
*/
|
|
|
|
formatter mk_simple_formatter();
|
2013-08-17 01:34:11 +00:00
|
|
|
}
|