DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / js / step1_read_print.js
1 if (typeof module !== 'undefined') {
2 var types = require('./types');
3 var readline = require('./node_readline');
4 var reader = require('./reader');
5 var printer = require('./printer');
6 }
7
8 // read
9 function READ(str) {
10 return reader.read_str(str);
11 }
12
13 // eval
14 function EVAL(ast, env) {
15 return ast;
16 }
17
18 // print
19 function PRINT(exp) {
20 return printer._pr_str(exp, true);
21 }
22
23 // repl
24 var re = function(str) { return EVAL(READ(str), {}); };
25 var rep = function(str) { return PRINT(EVAL(READ(str), {})); };
26
27 // repl loop
28 if (typeof require !== 'undefined' && require.main === module) {
29 // Synchronous node.js commandline mode
30 while (true) {
31 var line = readline.readline("user> ");
32 if (line === null) { break; }
33 try {
34 if (line) { printer.println(rep(line)); }
35 } catch (exc) {
36 if (exc instanceof reader.BlankException) { continue }
37 if (exc instanceof Error) { console.warn(exc.stack) }
38 else { console.warn("Error: " + printer._pr_str(exc, true)) }
39 }
40 }
41 }