cpp-peglib/language/repl.cc

32 lines
698 B
C++
Raw Normal View History

2015-05-28 23:19:46 +00:00
#include "linenoise.hpp"
#include "repl.hpp"
#include <iostream>
using namespace std;
2015-06-01 21:56:39 +00:00
int repl(shared_ptr<Environment> env, bool print_ast)
2015-05-28 23:19:46 +00:00
{
for (;;) {
auto line = linenoise::Readline("cul> ");
if (line == "exit" || line == "quit") {
break;
}
if (!line.empty()) {
Value val;
string msg;
2015-05-29 01:36:29 +00:00
if (run("(repl)", env, line.c_str(), line.size(), val, msg, print_ast)) {
2015-05-28 23:19:46 +00:00
cout << val << endl;
linenoise::AddHistory(line.c_str());
} else if (!msg.empty()) {
2015-05-29 01:36:29 +00:00
cout << msg;
2015-05-28 23:19:46 +00:00
}
}
}
return 0;
}
// vim: et ts=4 sw=4 cin cino={1s ff=unix