Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 80 lines (67 sloc) 2.031 kb
#!/usr/bin/env node
"use strict";
var fs = require('fs'),
readline = require('readline'),
tty = require('tty'),
Runner = require('./src/runner.js');
var optimist = require('optimist')
.usage('Usage: $0 -e eval')
.alias('h', 'help').describe('h', 'show this help message')
.describe('dump_ast', 'dump abstract syntax tree')
.boolean('dump_ast')
.describe('dump_token', 'dump tokens')
.boolean('dump_token')
.alias('D', 'dump_js')
.describe('dump_js', 'dump translated javascript source code')
.boolean('D')
;
var argv = optimist.argv;
if (argv.h) {
console.log(optimist.help());
process.exit(0);
}
var runner = new Runner();
runner.dump_ast = argv.dump_ast;
runner.dump_token = argv.dump_token;
runner.dump_js = argv.dump_js;
if (typeof argv.e !== 'undefined') {
// -e means eval mode
var src = '' + argv.e;
global.ARGV = argv._;
runner.runString(src);
} else if (argv._.length > 0) {
var fname = argv._[0];
global.ARGV = argv._.slice(1);
runner.runFile(fname);
} else if (tty.isatty(process.stdin.fd)) {
global.ARGV = argv._;
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.setPrompt('✖╹◡╹✖ ☆☆☆ ');
rl.prompt();
rl.on('line', function(src) {
try {
console.log(runner.runString(''+src.trim()));
} catch (e) { console.log(e); }
rl.prompt();
}).on('close', function () {
process.exit(0);
});
} else {
(function () {
var fname = argv._[0];
global.ARGV = argv._;
var fs = require("fs");
var fd = process.stdin.fd;
var content = "";
var BUFFER_SIZE = 4096;
var buffer = new Buffer(BUFFER_SIZE);
var n;
while( (n = fs.readSync(fd, buffer, 0, BUFFER_SIZE)) > 0) {
content += buffer.slice(0, n).toString();
}
runner.runString(content);
})();
}
Jump to Line
Something went wrong with that request. Please try again.