feat(frontends/lean): display eval/check/find_decl results using flycheck

This commit is contained in:
Leonardo de Moura 2014-11-24 08:35:49 -08:00
parent fe638f0ee7
commit a005c8f4d0
9 changed files with 35 additions and 15 deletions

View file

@ -34,6 +34,11 @@
(minimal-match (minimal-match
(message (one-or-more (zero-or-more not-newline) (? "\r") "\n"))) (message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
"FLYCHECK_END" (? "\r") line-end) "FLYCHECK_END" (? "\r") line-end)
(warning line-start "FLYCHECK_BEGIN INFORMATION" (? "\r") "\n"
(file-name) ":" line ":" (? column ":") " information: "
(minimal-match
(message (one-or-more (zero-or-more not-newline) (? "\r") "\n")))
"FLYCHECK_END" (? "\r") line-end)
(warning line-start "FLYCHECK_BEGIN WARNING" (? "\r") "\n" (warning line-start "FLYCHECK_BEGIN WARNING" (? "\r") "\n"
(file-name) ":" line ":" (? column ":") " warning: " (file-name) ":" line ":" (? column ":") " warning: "
(minimal-match (minimal-match

View file

@ -21,6 +21,7 @@ Author: Leonardo de Moura
#include "library/reducible.h" #include "library/reducible.h"
#include "library/normalize.h" #include "library/normalize.h"
#include "library/print.h" #include "library/print.h"
#include "library/flycheck.h"
#include "library/definitional/projection.h" #include "library/definitional/projection.h"
#include "frontends/lean/util.h" #include "frontends/lean/util.h"
#include "frontends/lean/parser.h" #include "frontends/lean/parser.h"
@ -252,6 +253,11 @@ environment check_cmd(parser & p) {
fmt = fmt.update_options(opts); fmt = fmt.update_options(opts);
unsigned indent = get_pp_indent(opts); unsigned indent = get_pp_indent(opts);
format r = group(fmt(e) + space() + colon() + nest(indent, line() + fmt(type))); format r = group(fmt(e) + space() + colon() + nest(indent, line() + fmt(type)));
flycheck_information info(p.regular_stream());
if (info.enabled()) {
p.display_information_pos(p.cmd_pos());
p.regular_stream() << "check result:\n";
}
reg << mk_pair(r, opts) << endl; reg << mk_pair(r, opts) << endl;
return p.env(); return p.env();
} }
@ -278,6 +284,11 @@ environment eval_cmd(parser & p) {
transparent_scope scope; transparent_scope scope;
r = normalize(p.env(), ls, e); r = normalize(p.env(), ls, e);
} }
flycheck_information info(p.regular_stream());
if (info.enabled()) {
p.display_information_pos(p.cmd_pos());
p.regular_stream() << "eval result:\n";
}
p.regular_stream() << r << endl; p.regular_stream() << r << endl;
return p.env(); return p.env();
} }

View file

@ -10,6 +10,7 @@ Author: Leonardo de Moura
#include "library/unifier.h" #include "library/unifier.h"
#include "library/type_util.h" #include "library/type_util.h"
#include "library/reducible.h" #include "library/reducible.h"
#include "library/flycheck.h"
#include "frontends/lean/parser.h" #include "frontends/lean/parser.h"
#include "frontends/lean/util.h" #include "frontends/lean/util.h"
#include "frontends/lean/tokens.h" #include "frontends/lean/tokens.h"
@ -102,6 +103,10 @@ environment find_cmd(parser & p) {
parse_filters(p, pos_names, neg_names); parse_filters(p, pos_names, neg_names);
environment env = p.env(); environment env = p.env();
auto tc = mk_opaque_type_checker(env, p.mk_ngen()); auto tc = mk_opaque_type_checker(env, p.mk_ngen());
flycheck_information info(p.regular_stream());
if (info.enabled()) {
p.display_information_pos(p.cmd_pos());
}
p.regular_stream() << "find_decl result:\n"; p.regular_stream() << "find_decl result:\n";
unsigned max_steps = get_find_max_steps(p.get_options()); unsigned max_steps = get_find_max_steps(p.get_options());

View file

@ -212,6 +212,10 @@ void parser::display_warning_pos(unsigned line, unsigned pos) {
} }
void parser::display_warning_pos(pos_info p) { display_warning_pos(p.first, p.second); } void parser::display_warning_pos(pos_info p) { display_warning_pos(p.first, p.second); }
void parser::display_information_pos(pos_info pos) {
::lean::display_information_pos(regular_stream(), get_stream_name().c_str(), pos.first, pos.second);
}
void parser::display_error_pos(unsigned line, unsigned pos) { void parser::display_error_pos(unsigned line, unsigned pos) {
::lean::display_error_pos(regular_stream(), get_stream_name().c_str(), line, pos); ::lean::display_error_pos(regular_stream(), get_stream_name().c_str(), line, pos);
} }

View file

@ -415,6 +415,7 @@ public:
void declare_sorry(); void declare_sorry();
parser_pos_provider get_pos_provider() const { return parser_pos_provider(m_pos_table, get_stream_name(), m_last_cmd_pos); } parser_pos_provider get_pos_provider() const { return parser_pos_provider(m_pos_table, get_stream_name(), m_last_cmd_pos); }
void display_information_pos(pos_info p);
/** parse all commands in the input stream */ /** parse all commands in the input stream */
bool operator()() { return parse_commands(); } bool operator()() { return parse_commands(); }

View file

@ -42,6 +42,11 @@ void display_warning_pos(io_state_stream const & ios, char const * strm_name, un
ios << " warning:"; ios << " warning:";
} }
void display_information_pos(io_state_stream const & ios, char const * strm_name, unsigned line, unsigned pos) {
display_pos(ios, strm_name, line, pos);
ios << " information:";
}
void display_error_pos(io_state_stream const & ios, pos_info_provider const * p, expr const & e) { void display_error_pos(io_state_stream const & ios, pos_info_provider const * p, expr const & e) {
if (p) { if (p) {
auto pos = p->get_pos_info_or_some(e); auto pos = p->get_pos_info_or_some(e);

View file

@ -19,6 +19,7 @@ void display_error_pos(io_state_stream const & ios, pos_info_provider const * p,
void display_error_pos(io_state_stream const & ios, char const * strm_name, unsigned line, unsigned pos); void display_error_pos(io_state_stream const & ios, char const * strm_name, unsigned line, unsigned pos);
/** \brief Similar to #display_error_pos, but displays a "warning:" */ /** \brief Similar to #display_error_pos, but displays a "warning:" */
void display_warning_pos(io_state_stream const & ios, char const * strm_name, unsigned line, unsigned pos); void display_warning_pos(io_state_stream const & ios, char const * strm_name, unsigned line, unsigned pos);
void display_information_pos(io_state_stream const & ios, char const * strm_name, unsigned line, unsigned pos);
/** /**
\brief Display exception in the regular stream of \c ios, using the configuration options and formatter from \c ios. \brief Display exception in the regular stream of \c ios, using the configuration options and formatter from \c ios.
Exceptions that contain expressions use the given \c pos_info_provider (if available) to retrieve line number information. Exceptions that contain expressions use the given \c pos_info_provider (if available) to retrieve line number information.

View file

@ -15,13 +15,4 @@ flycheck_scope::flycheck_scope(io_state_stream const & ios, char const * kind):
flycheck_scope::~flycheck_scope() { flycheck_scope::~flycheck_scope() {
if (m_flycheck) m_ios << "FLYCHECK_END" << endl; if (m_flycheck) m_ios << "FLYCHECK_END" << endl;
} }
flyinfo_scope::flyinfo_scope(io_state_stream const & ios):
m_ios(ios),
m_flyinfo(m_ios.get_options().get_bool("flyinfo", false)) {
if (m_flyinfo) m_ios << "FLYCHECK_BEGIN INFO" << endl;
}
flyinfo_scope::~flyinfo_scope() {
if (m_flyinfo) m_ios << "FLYCHECK_END" << endl;
}
} }

View file

@ -15,6 +15,7 @@ class flycheck_scope {
public: public:
flycheck_scope(io_state_stream const & ios, char const * kind); flycheck_scope(io_state_stream const & ios, char const * kind);
~flycheck_scope(); ~flycheck_scope();
bool enabled() const { return m_flycheck; }
}; };
struct flycheck_error : public flycheck_scope { struct flycheck_error : public flycheck_scope {
@ -25,11 +26,7 @@ struct flycheck_warning : public flycheck_scope {
flycheck_warning(io_state_stream const & ios):flycheck_scope(ios, "WARNING") {} flycheck_warning(io_state_stream const & ios):flycheck_scope(ios, "WARNING") {}
}; };
class flyinfo_scope { struct flycheck_information : public flycheck_scope {
io_state_stream const & m_ios; flycheck_information(io_state_stream const & ios):flycheck_scope(ios, "INFORMATION") {}
bool m_flyinfo;
public:
flyinfo_scope(io_state_stream const & ios);
~flyinfo_scope();
}; };
} }