2014-06-11 00:02:06 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2014-06-11 18:52:58 +00:00
|
|
|
#include "library/io_state_stream.h"
|
2014-06-11 18:44:16 +00:00
|
|
|
#include "frontends/lean/parser.h"
|
2014-06-11 00:02:06 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-06-12 03:56:10 +00:00
|
|
|
static name g_raw("raw");
|
2014-06-11 18:52:58 +00:00
|
|
|
environment print_cmd(parser & p) {
|
|
|
|
if (p.curr() == scanner::token_kind::String) {
|
2014-06-12 03:56:10 +00:00
|
|
|
p.regular_stream() << p.get_str_val() << "\n";
|
2014-06-11 18:52:58 +00:00
|
|
|
p.next();
|
2014-06-12 03:56:10 +00:00
|
|
|
} else if (p.curr_is_token(g_raw)) {
|
|
|
|
p.next();
|
|
|
|
expr e = p.parse_expr();
|
|
|
|
p.regular_stream() << e << "\n";
|
2014-06-11 18:52:58 +00:00
|
|
|
} else {
|
|
|
|
throw parser_error("invalid print command", p.pos());
|
|
|
|
}
|
|
|
|
return p.env();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_table init_cmd_table() {
|
|
|
|
cmd_table r;
|
|
|
|
add_cmd(r, cmd_info("print", "print a string", print_cmd));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-06-11 00:02:06 +00:00
|
|
|
cmd_table get_builtin_cmds() {
|
2014-06-11 18:52:58 +00:00
|
|
|
static optional<cmd_table> r;
|
|
|
|
if (!r)
|
|
|
|
r = init_cmd_table();
|
|
|
|
return *r;
|
2014-06-11 00:02:06 +00:00
|
|
|
}
|
|
|
|
}
|