1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/lib/coffee_script/repl.js
2010-01-29 22:51:51 -05:00

33 lines
No EOL
889 B
JavaScript

(function(){
var coffee, prompt, quit, readline, run;
// A CoffeeScript port/version of the Node.js REPL.
// Required modules.
coffee = require('./coffee-script');
process.mixin(require('sys'));
// Shortcut variables.
prompt = 'coffee> ';
quit = function quit() {
return process.stdio.close();
};
// The main REPL function. Called everytime a line of code is entered.
readline = function readline(code) {
return coffee.compile(code, run);
};
// Attempt to evaluate the command. If there's an exception, print it.
run = function run(js) {
var val;
try {
val = eval(js);
if (val !== undefined) {
p(val);
}
} catch (err) {
puts(err.stack || err.toString());
}
return print(prompt);
};
// Start up the REPL.
process.stdio.open();
process.stdio.addListener('data', readline);
print(prompt);
})();