-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
36 lines (32 loc) · 1.06 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const stdin = process.openStdin();
const lisp = require('./lisp');
lisp.evaluate(lisp.parse('(load parser)'));
lisp.evaluate(lisp.parse('(load std-lib)'));
// lisp.evaluate(lisp.parse('(load tests)'));
// lisp.evaluate(lisp.parse('(load defs)'));
// const parse = makeParser('./xml.cfg');
// console.log('cli:', lisp.prettyPrint(lisp.evaluate(parse('<main x="10"><main/></main>'))));
// lisp.evaluate(parse('(load polyfill)'));
// lisp.evaluate(parse('(load bot-lib)'));
// console.log('--------------');
stdin.addListener('data', function(d) {
const str = d.toString().substring(0, d.length-1).trim();
// Added for compliance with chatbot input format
if ((/^\/\(.+\)$/).test(str)){
str = str.slice(1);
} else if ((/^\/.+/).test(str)){
str = "(" + str.slice(1) + ")";
} else if ((/^\(.+\)/).test(str)){
str = str;
}
if (str.length > 0) {
// try {
const AST = lisp.parse(str);
const output = lisp.evaluate(AST);
const pretty = lisp.prettyPrint(output);
console.log(pretty);
// } catch (e) {
// console.log(e);
// }
}
});