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;

View File

@@ -63,7 +63,7 @@ exports.compile_scripts: ->
return unless source: @sources.shift()
opts: @options
posix.cat(source).addCallback (code) ->
if opts.tokens then puts coffee.tokenize(code).join(' ')
if opts.tokens then puts exports.tokenize(code)
else if opts.tree then puts coffee.tree(code).toString()
else
js: coffee.compile code
@@ -81,6 +81,12 @@ exports.write_js: (source, js) ->
posix.open(js_path, process.O_CREAT | process.O_WRONLY | process.O_TRUNC, parseInt('0755', 8)).addCallback (fd) ->
posix.write(fd, js)
# Pretty-print the token stream.
exports.tokenize: (code) ->
strings: coffee.tokenize(code).map (token) ->
'[' + token[0] + ' ' + token[1].toString().replace(/\n/, '\\n') + ']'
strings.join(' ')
# Pipe compiled JS through JSLint (requires a working 'jsl' command).
exports.lint: (js) ->
jsl: process.createChildProcess('jsl', ['-nologo', '-stdin'])