mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 11:01:25 -05:00
added the ability to print the parse tree
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
posix = require('posix');
|
||||
coffee = require('coffee-script');
|
||||
BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee";
|
||||
SWITCHES = [['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-r', '--run', 'compile and run a CoffeeScript'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-e', '--eval', 'compile a cli scriptlet or read from stdin'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--no-wrap', 'raw output, no function safety wrapper'], ['-g', '--globals', 'attach all top-level variables as globals'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||
SWITCHES = [['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-r', '--run', 'compile and run a CoffeeScript'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-e', '--eval', 'compile a cli scriptlet or read from stdin'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['--tree', 'print the parse tree that Jison produces'], ['-n', '--no-wrap', 'raw output, no function safety wrapper'], ['-g', '--globals', 'attach all top-level variables as globals'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||
WATCH_INTERVAL = 0.5;
|
||||
// The CommandLine handles all of the functionality of the `coffee` utility.
|
||||
exports.run = function run() {
|
||||
@@ -53,16 +53,17 @@
|
||||
}
|
||||
opts = this.options;
|
||||
return posix.cat(source).addCallback(function(code) {
|
||||
var js;
|
||||
if (opts.tokens) {
|
||||
return puts(coffee.tokenize(code).join(' '));
|
||||
}
|
||||
js = coffee.compile(code);
|
||||
if (opts.tree) {
|
||||
return puts(coffee.tree(code).toString());
|
||||
}
|
||||
if (opts.run) {
|
||||
return eval(js);
|
||||
return eval(coffee.compile(code));
|
||||
}
|
||||
if (opts.print) {
|
||||
return puts(js);
|
||||
return puts(coffee.compile(code));
|
||||
}
|
||||
return exports.compile_scripts();
|
||||
});
|
||||
@@ -98,6 +99,9 @@
|
||||
oparser.add('tokens', function() {
|
||||
return opts.tokens = true;
|
||||
});
|
||||
oparser.add('tree', function() {
|
||||
return opts.tree = true;
|
||||
});
|
||||
oparser.add('help', (function(__this) {
|
||||
var __func = function() {
|
||||
return this.usage();
|
||||
|
||||
Reference in New Issue
Block a user