-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
47 lines (45 loc) · 1.07 KB
/
cli.js
File metadata and controls
47 lines (45 loc) · 1.07 KB
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
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
var program = require('commander'),
readline = require('readline'),
fs = require('fs'),
lisp = require('./lisp'),
node_lisp = require('./node_lisp'),
tests = require('./lisp_tests');
program
.version('0.0.1')
.option('-f, --file <file>', 'File to run')
.option('-t, --test', 'Run tests')
.parse(process.argv);
lisp.Lisp.reset();
if(program.file){
console.log('Running "' + program.file + '"');
fs.readFile(program.file, function(err, data){
if(err)
throw err;
//console.log(data.toString());
node_lisp.report(data.toString(), false);
});
}
else if(program.test){
console.log('Running test cases');
tests.validate();
}
else{
// repl
var rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt('> ');
rl.prompt();
rl.on('line', function(line){
try{
node_lisp.report(line, false);
}
catch(err){
console.log(err);
}
rl.prompt();
})
.on('close', function(){
console.log('');
process.exit(0);
});
}