Nicer-looking --tokenize, more in line with what Ruby's doing

This commit is contained in:
Jeremy Ashkenas
2010-02-13 09:59:13 -05:00
parent 4bad3e0f4f
commit 02ac3edebf
2 changed files with 16 additions and 2 deletions

View File

@@ -55,7 +55,7 @@
return posix.cat(source).addCallback(function(code) {
var js;
if (opts.tokens) {
puts(coffee.tokenize(code).join(' '));
puts(exports.tokenize(code));
} else if (opts.tree) {
puts(coffee.tree(code).toString());
} else {
@@ -83,6 +83,14 @@
return posix.write(fd, js);
});
};
// Pretty-print the token stream.
exports.tokenize = function tokenize(code) {
var strings;
strings = coffee.tokenize(code).map(function(token) {
return '[' + token[0] + ' ' + token[1].toString().replace(/\n/, '\\n') + ']';
});
return strings.join(' ');
};
// Pipe compiled JS through JSLint (requires a working 'jsl' command).
exports.lint = function lint(js) {
var jsl;