Add highlight_keyword, highlight_builtin, highlight_command for consistent formatting

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-08-15 08:32:13 -07:00
parent c5db989e38
commit 577256fedc
4 changed files with 28 additions and 4 deletions

View file

@ -10,7 +10,7 @@ Author: Leonardo de Moura
namespace lean { namespace lean {
// TODO: delete hardcoded // TODO: delete hardcoded
format pp_object_kind(char const * n) { return highlight(format(n), format::format_color::BLUE); } format pp_object_kind(char const * n) { return highlight_command(format(n)); }
constexpr unsigned indentation = 2; // TODO: must be option constexpr unsigned indentation = 2; // TODO: must be option
// //

View file

@ -17,9 +17,9 @@ struct pp_fn {
pp_fn(environment const * env):m_env(env) {} pp_fn(environment const * env):m_env(env) {}
unsigned indent() const { return 2; } unsigned indent() const { return 2; }
format pp_keyword(char const * k) { return highlight(format(k), format::format_color::ORANGE); } format pp_keyword(char const * k) { return highlight_keyword(format(k)); }
format pp_type_kwd() { return highlight(format("Type"), format::format_color::PINK); } format pp_type_kwd() { return highlight_builtin(format("Type")); }
format pp_eq_kwd() { return highlight(format(" = "), format::format_color::BLUE); } format pp_eq_kwd() { return format(" = "); }
format pp_lambda_kwd() { return pp_keyword("\u03BB "); } format pp_lambda_kwd() { return pp_keyword("\u03BB "); }
format pp_lambda_sep() { return format(","); } format pp_lambda_sep() { return format(","); }
format pp_pi_kwd() { return pp_keyword("\u03A0 "); } format pp_pi_kwd() { return pp_keyword("\u03A0 "); }

View file

@ -23,6 +23,18 @@
#define LEAN_DEFAULT_PP_COLORS true #define LEAN_DEFAULT_PP_COLORS true
#endif #endif
#ifndef LEAN_KEYWORD_HIGHLIGHT_COLOR
#define LEAN_KEYWORD_HIGHLIGHT_COLOR format::ORANGE
#endif
#ifndef LEAN_BUILTIN_HIGHLIGHT_COLOR
#define LEAN_BUILTIN_HIGHLIGHT_COLOR format::CYAN
#endif
#ifndef LEAN_COMMAND_HIGHLIGHT_COLOR
#define LEAN_COMMAND_HIGHLIGHT_COLOR format::BLUE
#endif
namespace lean { namespace lean {
static name g_pp_indent{"pp", "indent"}; static name g_pp_indent{"pp", "indent"};
static name g_pp_colors{"pp", "colors"}; static name g_pp_colors{"pp", "colors"};
@ -99,6 +111,15 @@ format nest(int i, format const & f) {
format highlight(format const & f, format::format_color const c) { format highlight(format const & f, format::format_color const c) {
return format(format::sexpr_highlight(f.m_value, c)); return format(format::sexpr_highlight(f.m_value, c));
} }
format highlight_keyword(format const & f) {
return highlight(f, LEAN_KEYWORD_HIGHLIGHT_COLOR);
}
format highlight_builtin(format const & f) {
return highlight(f, LEAN_BUILTIN_HIGHLIGHT_COLOR);
}
format highlight_command(format const & f) {
return highlight(f, LEAN_COMMAND_HIGHLIGHT_COLOR);
}
// Commonly used format objects // Commonly used format objects
format mk_line() { format mk_line() {
return format(format::sexpr_line()); return format(format::sexpr_line());

View file

@ -214,6 +214,9 @@ format wrap(format const & f1, format const & f2);
format compose(format const & f1, format const & f2); format compose(format const & f1, format const & f2);
format nest(int i, format const & f); format nest(int i, format const & f);
format highlight(format const & f, format::format_color const c); format highlight(format const & f, format::format_color const c);
format highlight_keyword(format const & f);
format highlight_builtin(format const & f);
format highlight_command(format const & f);
format const & line(); format const & line();
format const & space(); format const & space();
format const & lp(); format const & lp();