mirror of
https://github.com/kanaka/mal.git
synced 2024-11-09 18:06:35 +03:00
e439350417
js/web/jqconsole.min.js and web/ansi.css are from https://github.com/replit/jq-console and licensed MIT.
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
if (typeof module !== 'undefined') {
|
|
var types = require('./types');
|
|
var readline = require('./node_readline');
|
|
var reader = require('./reader');
|
|
var printer = require('./printer');
|
|
}
|
|
|
|
// read
|
|
function READ(str) {
|
|
return reader.read_str(str);
|
|
}
|
|
|
|
// eval
|
|
function EVAL(ast, env) {
|
|
return ast;
|
|
}
|
|
|
|
// print
|
|
function PRINT(exp) {
|
|
return printer._pr_str(exp, true);
|
|
}
|
|
|
|
// repl
|
|
var re = function(str) { return EVAL(READ(str), {}); };
|
|
var rep = function(str) { return PRINT(EVAL(READ(str), {})); };
|
|
|
|
// repl loop
|
|
if (typeof require !== 'undefined' && require.main === module) {
|
|
// Synchronous node.js commandline mode
|
|
while (true) {
|
|
var line = readline.readline("user> ");
|
|
if (line === null) { break; }
|
|
try {
|
|
if (line) { printer.println(rep(line)); }
|
|
} catch (exc) {
|
|
if (exc instanceof reader.BlankException) { continue; }
|
|
if (exc.stack) { printer.println(exc.stack); }
|
|
else { printer.println(exc); }
|
|
}
|
|
}
|
|
}
|