1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

things are in motion -- bin/node_coffee is the new JS-only command line ... it can pass some of the tests

This commit is contained in:
Jeremy Ashkenas 2010-02-11 01:57:33 -05:00
parent f761c25dcd
commit 872b36c11d
83 changed files with 8312 additions and 226 deletions

View file

@ -1,11 +1,44 @@
(function(){
var compiler, path;
var compiler, lexer, parser, path;
process.mixin(require('./nodes'));
lexer = new (require('./lexer').Lexer)();
parser = require('./parser').parser;
// Thin wrapper for Jison compatibility around the real lexer.
parser.lexer = {
lex: function lex() {
var token;
token = this.tokens[this.pos] || [""];
this.pos += 1;
this.yylineno = token[2];
this.yytext = token[1];
return token[0];
},
setInput: function setInput(tokens) {
this.tokens = tokens;
return this.pos = 0;
},
upcomingInput: function upcomingInput() {
return "";
},
showPosition: function showPosition() {
return this.pos;
}
};
exports.VERSION = '0.5.0';
// Compile CoffeeScript to JavaScript, using the Coffee/Jison compiler.
exports.compile = function compile(code) {
var nodes, tokens;
tokens = lexer.tokenize(code);
nodes = parser.parse(tokens);
return nodes.compile();
};
//---------- Below this line is obsolete, for the Ruby compiler. ----------------
// Executes the `coffee` Ruby program to convert from CoffeeScript to JavaScript.
path = require('path');
// The path to the CoffeeScript executable.
compiler = path.normalize(path.dirname(__filename) + '/../../bin/coffee');
// Compile a string over stdin, with global variables, for the REPL.
exports.compile = function compile(code, callback) {
exports.ruby_compile = function ruby_compile(code, callback) {
var coffee, js;
js = '';
coffee = process.createChildProcess(compiler, ['--eval', '--no-wrap', '--globals']);
@ -21,7 +54,7 @@
return coffee.close();
};
// Compile a list of CoffeeScript files on disk.
exports.compile_files = function compile_files(paths, callback) {
exports.ruby_compile_files = function ruby_compile_files(paths, callback) {
var coffee, exit_ran, js;
js = '';
coffee = process.createChildProcess(compiler, ['--print'].concat(paths));