moving -tr --tree to -n --nodes, and --no-wrap gives up its -n short flag.

This commit is contained in:
Jeremy Ashkenas 2010-02-25 18:42:35 -05:00
parent c62f93f930
commit 9d4e06e8a8
4 changed files with 12 additions and 12 deletions

View File

@ -38,11 +38,11 @@
return (parser.parse(lexer.tokenize(code))).compile(options); return (parser.parse(lexer.tokenize(code))).compile(options);
}; };
// Just the tokens. // Just the tokens.
exports.tokenize = function tokenize(code) { exports.tokens = function tokens(code) {
return lexer.tokenize(code); return lexer.tokenize(code);
}; };
// Just the nodes. // Just the nodes.
exports.tree = function tree(code) { exports.nodes = function nodes(code) {
return parser.parse(lexer.tokenize(code)); return parser.parse(lexer.tokenize(code));
}; };
// Activate CoffeeScript in the browser by having it compile and eval // Activate CoffeeScript in the browser by having it compile and eval

View File

@ -5,7 +5,7 @@
optparse = require('optparse'); optparse = require('optparse');
CoffeeScript = require('coffee-script'); CoffeeScript = require('coffee-script');
BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee"; 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'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-n', '--no-wrap', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-tr', '--tree', 'print the parse tree that Jison produces'], ['-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'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['--no-wrap', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
options = {}; options = {};
sources = []; sources = [];
option_parser = null; option_parser = null;
@ -82,9 +82,9 @@
o = options; o = options;
try { try {
if (o.tokens) { if (o.tokens) {
return print_tokens(CoffeeScript.tokenize(code)); return print_tokens(CoffeeScript.tokens(code));
} else if (o.tree) { } else if (o.nodes) {
return puts(CoffeeScript.tree(code).toString()); return puts(CoffeeScript.nodes(code).toString());
} else { } else {
js = CoffeeScript.compile(code, compile_options()); js = CoffeeScript.compile(code, compile_options());
if (o.run) { if (o.run) {

View File

@ -31,11 +31,11 @@ exports.compile: (code, options) ->
(parser.parse lexer.tokenize code).compile(options) (parser.parse lexer.tokenize code).compile(options)
# Just the tokens. # Just the tokens.
exports.tokenize: (code) -> exports.tokens: (code) ->
lexer.tokenize code lexer.tokenize code
# Just the nodes. # Just the nodes.
exports.tree: (code) -> exports.nodes: (code) ->
parser.parse lexer.tokenize code parser.parse lexer.tokenize code
# Activate CoffeeScript in the browser by having it compile and eval # Activate CoffeeScript in the browser by having it compile and eval

View File

@ -19,9 +19,9 @@ SWITCHES: [
['-l', '--lint', 'pipe the compiled JavaScript through JSLint'] ['-l', '--lint', 'pipe the compiled JavaScript through JSLint']
['-s', '--stdio', 'listen for and compile scripts over stdio'] ['-s', '--stdio', 'listen for and compile scripts over stdio']
['-e', '--eval', 'compile a string from the command line'] ['-e', '--eval', 'compile a string from the command line']
['-n', '--no-wrap', 'compile without the top-level function wrapper'] [ '--no-wrap', 'compile without the top-level function wrapper']
['-t', '--tokens', 'print the tokens that the lexer produces'] ['-t', '--tokens', 'print the tokens that the lexer produces']
['-tr','--tree', 'print the parse tree that Jison produces'] ['-n', '--nodes', 'print the parse tree that Jison produces']
['-v', '--version', 'display CoffeeScript version'] ['-v', '--version', 'display CoffeeScript version']
['-h', '--help', 'display this help message'] ['-h', '--help', 'display this help message']
] ]
@ -73,8 +73,8 @@ compile_scripts: ->
compile_script: (source, code) -> compile_script: (source, code) ->
o: options o: options
try try
if o.tokens then print_tokens CoffeeScript.tokenize code if o.tokens then print_tokens CoffeeScript.tokens code
else if o.tree then puts CoffeeScript.tree(code).toString() else if o.nodes then puts CoffeeScript.nodes(code).toString()
else else
js: CoffeeScript.compile code, compile_options() js: CoffeeScript.compile code, compile_options()
if o.run then eval js if o.run then eval js