feat(frontends/lean/server): add SET command
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
4bbabfe6d4
commit
9f3f42f6a5
3 changed files with 72 additions and 7 deletions
|
@ -150,3 +150,36 @@ range=, if =[line-number]= is too big, and =-- MISMATCH expected
|
||||||
-- CHECK [line-number]
|
-- CHECK [line-number]
|
||||||
[line]
|
[line]
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
** Set configuration option
|
||||||
|
|
||||||
|
The command
|
||||||
|
|
||||||
|
#+BEGIN_SRC
|
||||||
|
-- SET
|
||||||
|
[option-name] [value]
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
sets a Lean options, =[option-name]= must be a valid Lean option.
|
||||||
|
Any option that can be set using the command =set_option= in a '.lean'
|
||||||
|
file is supported.
|
||||||
|
|
||||||
|
This command produces the output
|
||||||
|
|
||||||
|
#+BEGIN_SRC
|
||||||
|
-- BEGINSET
|
||||||
|
[error]?
|
||||||
|
-- ENDSET
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
where the line =[error]?= is printed if there are errors parsing the
|
||||||
|
=SET= command (e.g., invalid option name).
|
||||||
|
|
||||||
|
Here is an example that forces the Lean pretty printer to display
|
||||||
|
implicit arguments.
|
||||||
|
|
||||||
|
#+BEGIN_SRC
|
||||||
|
-- SET
|
||||||
|
pp.implicit true
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,8 @@ unsigned server::file::find(unsigned linenum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
server::server(environment const & env, io_state const & ios, unsigned num_threads):
|
server::server(environment const & env, io_state const & ios, unsigned num_threads):
|
||||||
m_env(env), m_options(ios.get_options()), m_ios(ios), m_out(ios.get_regular_channel().get_stream()),
|
m_env(env), m_ios(ios), m_out(ios.get_regular_channel().get_stream()),
|
||||||
m_num_threads(num_threads), m_empty_snapshot(m_env, m_options) {
|
m_num_threads(num_threads), m_empty_snapshot(m_env, m_ios.get_options()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string g_load("LOAD");
|
static std::string g_load("LOAD");
|
||||||
|
@ -83,6 +83,7 @@ static std::string g_insert("INSERT");
|
||||||
static std::string g_remove("REMOVE");
|
static std::string g_remove("REMOVE");
|
||||||
static std::string g_check("CHECK");
|
static std::string g_check("CHECK");
|
||||||
static std::string g_info("INFO");
|
static std::string g_info("INFO");
|
||||||
|
static std::string g_set("SET");
|
||||||
|
|
||||||
static bool is_command(std::string const & cmd, std::string const & line) {
|
static bool is_command(std::string const & cmd, std::string const & line) {
|
||||||
return line.compare(0, cmd.size(), cmd) == 0;
|
return line.compare(0, cmd.size(), cmd) == 0;
|
||||||
|
@ -102,6 +103,19 @@ static std::string & trim(std::string & s) {
|
||||||
return ltrim(rtrim(s));
|
return ltrim(rtrim(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct scoped_updt_options {
|
||||||
|
io_state & m_ios;
|
||||||
|
options m_old_options;
|
||||||
|
public:
|
||||||
|
scoped_updt_options(io_state & ios, options const & opts):
|
||||||
|
m_ios(ios), m_old_options(m_ios.get_options()) {
|
||||||
|
m_ios.set_options(join(opts, m_old_options));
|
||||||
|
}
|
||||||
|
~scoped_updt_options() {
|
||||||
|
m_ios.set_options(m_old_options);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void server::process_from(unsigned linenum) {
|
void server::process_from(unsigned linenum) {
|
||||||
unsigned i = m_file->find(linenum);
|
unsigned i = m_file->find(linenum);
|
||||||
m_file->m_snapshots.resize(i);
|
m_file->m_snapshots.resize(i);
|
||||||
|
@ -114,7 +128,7 @@ void server::process_from(unsigned linenum) {
|
||||||
block += '\n';
|
block += '\n';
|
||||||
}
|
}
|
||||||
std::istringstream strm(block);
|
std::istringstream strm(block);
|
||||||
m_ios.set_options(s.m_options);
|
scoped_updt_options updt(m_ios, s.m_options);
|
||||||
parser p(s.m_env, m_ios, strm, m_file->m_fname.c_str(), false, 1, s.m_lds, s.m_eds, s.m_line,
|
parser p(s.m_env, m_ios, strm, m_file->m_fname.c_str(), false, 1, s.m_lds, s.m_eds, s.m_line,
|
||||||
&m_file->m_snapshots, &m_file->m_info);
|
&m_file->m_snapshots, &m_file->m_info);
|
||||||
// p.set_cache(&m_cache);
|
// p.set_cache(&m_cache);
|
||||||
|
@ -153,9 +167,9 @@ void server::show_info(unsigned linenum) {
|
||||||
check_file();
|
check_file();
|
||||||
update();
|
update();
|
||||||
unsigned i = m_file->find(linenum);
|
unsigned i = m_file->find(linenum);
|
||||||
environment const & env = i == 0 ? m_env : m_file->m_snapshots[i-1].m_env;
|
environment const & env = i == 0 ? m_env : m_file->m_snapshots[i-1].m_env;
|
||||||
options const & o = i == 0 ? m_options : m_file->m_snapshots[i-1].m_options;
|
options const & o = i == 0 ? m_ios.get_options() : m_file->m_snapshots[i-1].m_options;
|
||||||
m_ios.set_options(o);
|
scoped_updt_options updt(m_ios, o);
|
||||||
io_state_stream out(env, m_ios);
|
io_state_stream out(env, m_ios);
|
||||||
out << "-- BEGININFO" << endl;
|
out << "-- BEGININFO" << endl;
|
||||||
m_file->m_info.display(out, linenum);
|
m_file->m_info.display(out, linenum);
|
||||||
|
@ -208,6 +222,21 @@ void server::check_line(unsigned linenum, std::string const & line) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void server::set_option(std::string const & line) {
|
||||||
|
std::string cmd = "set_option ";
|
||||||
|
cmd += line;
|
||||||
|
std::istringstream strm(cmd);
|
||||||
|
m_out << "-- BEGINSET" << std::endl;
|
||||||
|
try {
|
||||||
|
parser p(m_env, m_ios, strm, "SET_command", true);
|
||||||
|
p();
|
||||||
|
m_ios.set_options(p.ios().get_options());
|
||||||
|
} catch (exception & ex) {
|
||||||
|
m_out << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
m_out << "-- ENDSET" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
bool server::operator()(std::istream & in) {
|
bool server::operator()(std::istream & in) {
|
||||||
for (std::string line; std::getline(in, line);) {
|
for (std::string line; std::getline(in, line);) {
|
||||||
try {
|
try {
|
||||||
|
@ -237,6 +266,9 @@ bool server::operator()(std::istream & in) {
|
||||||
} else if (is_command(g_info, line)) {
|
} else if (is_command(g_info, line)) {
|
||||||
unsigned linenum = get_linenum(line, g_info);
|
unsigned linenum = get_linenum(line, g_info);
|
||||||
show_info(linenum);
|
show_info(linenum);
|
||||||
|
} else if (is_command(g_set, line)) {
|
||||||
|
read_line(in, line);
|
||||||
|
set_option(line);
|
||||||
} else {
|
} else {
|
||||||
throw exception(sstream() << "unexpected command line: " << line);
|
throw exception(sstream() << "unexpected command line: " << line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ class server {
|
||||||
file_map m_file_map;
|
file_map m_file_map;
|
||||||
file_ptr m_file;
|
file_ptr m_file;
|
||||||
environment m_env;
|
environment m_env;
|
||||||
options m_options;
|
|
||||||
io_state m_ios;
|
io_state m_ios;
|
||||||
std::ostream & m_out;
|
std::ostream & m_out;
|
||||||
unsigned m_num_threads;
|
unsigned m_num_threads;
|
||||||
|
@ -52,6 +51,7 @@ class server {
|
||||||
void check_line(unsigned linenum, std::string const & line);
|
void check_line(unsigned linenum, std::string const & line);
|
||||||
void show_info(unsigned linenum);
|
void show_info(unsigned linenum);
|
||||||
void process_from(unsigned linenum);
|
void process_from(unsigned linenum);
|
||||||
|
void set_option(std::string const & line);
|
||||||
unsigned find(unsigned linenum);
|
unsigned find(unsigned linenum);
|
||||||
void update();
|
void update();
|
||||||
void read_line(std::istream & in, std::string & line);
|
void read_line(std::istream & in, std::string & line);
|
||||||
|
|
Loading…
Add table
Reference in a new issue