rewriting the Lexer, CommandLine, Nodes, and Rewriter to take advantage of the new DRY object pattern matching.

This commit is contained in:
Jeremy Ashkenas 2010-04-25 22:29:43 -04:00
parent a894db35fd
commit 2d1abd099d
9 changed files with 253 additions and 257 deletions

View File

@ -1,7 +1,7 @@
fs: require 'fs' fs: require 'fs'
helpers: require('./lib/helpers').helpers helpers: require('./lib/helpers').helpers
CoffeeScript: require './lib/coffee-script' CoffeeScript: require './lib/coffee-script'
{spawn: spawn, exec: exec}: require('child_process') {spawn, exec}: require('child_process')
# Run a CoffeeScript through our node/coffee interpreter. # Run a CoffeeScript through our node/coffee interpreter.
run: (args) -> run: (args) ->

View File

@ -173,7 +173,7 @@
lint = function lint(js) { lint = function lint(js) {
var jsl, print_it; var jsl, print_it;
print_it = function print_it(buffer) { print_it = function print_it(buffer) {
return puts(buffer.toString()); return print(buffer.toString());
}; };
jsl = spawn('jsl', ['-nologo', '-stdin']); jsl = spawn('jsl', ['-nologo', '-stdin']);
jsl.stdout.addListener('data', print_it); jsl.stdout.addListener('data', print_it);

View File

@ -1,5 +1,5 @@
(function(){ (function(){
var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, balanced_string, compact, count, helpers, include, starts; var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, _a, balanced_string, compact, count, helpers, include, starts;
var __slice = Array.prototype.slice; var __slice = Array.prototype.slice;
// The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt // The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
// matches against the beginning of the source code. When a match is found, // matches against the beginning of the source code. When a match is found,
@ -17,11 +17,12 @@
helpers = this.helpers; helpers = this.helpers;
} }
// Import the helpers we need. // Import the helpers we need.
include = helpers.include; _a = helpers;
count = helpers.count; include = _a.include;
starts = helpers.starts; count = _a.count;
compact = helpers.compact; starts = _a.starts;
balanced_string = helpers.balanced_string; compact = _a.compact;
balanced_string = _a.balanced_string;
// The Lexer Class // The Lexer Class
// --------------- // ---------------
// The Lexer class reads a stream of CoffeeScript and divvys it up into tagged // The Lexer class reads a stream of CoffeeScript and divvys it up into tagged
@ -106,10 +107,10 @@
// Language extensions get the highest priority, first chance to tag tokens // Language extensions get the highest priority, first chance to tag tokens
// as something else. // as something else.
Lexer.prototype.extension_token = function extension_token() { Lexer.prototype.extension_token = function extension_token() {
var _a, _b, _c, extension; var _b, _c, _d, extension;
_b = Lexer.extensions; _c = Lexer.extensions;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
extension = _b[_a]; extension = _c[_b];
if (extension.call(this)) { if (extension.call(this)) {
return true; return true;
} }
@ -419,7 +420,7 @@
// definitions versus argument lists in function calls. Walk backwards, tagging // definitions versus argument lists in function calls. Walk backwards, tagging
// parameters specially in order to make things easier for the parser. // parameters specially in order to make things easier for the parser.
Lexer.prototype.tag_parameters = function tag_parameters() { Lexer.prototype.tag_parameters = function tag_parameters() {
var _a, i, tok; var _b, i, tok;
if (this.tag() !== ')') { if (this.tag() !== ')') {
return null; return null;
} }
@ -430,11 +431,11 @@
if (!tok) { if (!tok) {
return null; return null;
} }
if ((_a = tok[0]) === 'IDENTIFIER') { if ((_b = tok[0]) === 'IDENTIFIER') {
tok[0] = 'PARAM'; tok[0] = 'PARAM';
} else if (_a === ')') { } else if (_b === ')') {
tok[0] = 'PARAM_END'; tok[0] = 'PARAM_END';
} else if (_a === '(' || _a === 'CALL_START') { } else if (_b === '(' || _b === 'CALL_START') {
tok[0] = 'PARAM_START'; tok[0] = 'PARAM_START';
return tok[0]; return tok[0];
} }
@ -464,23 +465,23 @@
// new Lexer, tokenize the interpolated contents, and merge them into the // new Lexer, tokenize the interpolated contents, and merge them into the
// token stream. // token stream.
Lexer.prototype.interpolate_string = function interpolate_string(str, escape_quotes) { Lexer.prototype.interpolate_string = function interpolate_string(str, escape_quotes) {
var _a, _b, _c, _d, _e, _f, _g, escaped, expr, group, i, idx, inner, interp, interpolated, lexer, match, nested, pi, quote, tag, tok, token, tokens, value; var _b, _c, _d, _e, _f, _g, _h, escaped, expr, group, i, idx, inner, interp, interpolated, lexer, match, nested, pi, quote, tag, tok, token, tokens, value;
if (str.length < 3 || !starts(str, '"')) { if (str.length < 3 || !starts(str, '"')) {
return this.token('STRING', str); return this.token('STRING', str);
} else { } else {
lexer = new Lexer(); lexer = new Lexer();
tokens = []; tokens = [];
quote = str.substring(0, 1); quote = str.substring(0, 1);
_a = [1, 1]; _b = [1, 1];
i = _a[0]; i = _b[0];
pi = _a[1]; pi = _b[1];
while (i < str.length - 1) { while (i < str.length - 1) {
if (starts(str, '\\', i)) { if (starts(str, '\\', i)) {
i += 1; i += 1;
} else if ((match = str.substring(i).match(INTERPOLATION))) { } else if ((match = str.substring(i).match(INTERPOLATION))) {
_b = match; _c = match;
group = _b[0]; group = _c[0];
interp = _b[1]; interp = _c[1];
if (starts(interp, '@')) { if (starts(interp, '@')) {
interp = ("this." + (interp.substring(1))); interp = ("this." + (interp.substring(1)));
} }
@ -499,9 +500,9 @@
nested = lexer.tokenize(("(" + inner + ")"), { nested = lexer.tokenize(("(" + inner + ")"), {
line: this.line line: this.line
}); });
_c = nested; _d = nested;
for (idx = 0, _d = _c.length; idx < _d; idx++) { for (idx = 0, _e = _d.length; idx < _e; idx++) {
tok = _c[idx]; tok = _d[idx];
tok[0] === 'CALL_END' ? (tok[0] = ')') : null; tok[0] === 'CALL_END' ? (tok[0] = ')') : null;
} }
nested.pop(); nested.pop();
@ -524,12 +525,12 @@
if (interpolated) { if (interpolated) {
this.token('(', '('); this.token('(', '(');
} }
_e = tokens; _f = tokens;
for (i = 0, _f = _e.length; i < _f; i++) { for (i = 0, _g = _f.length; i < _g; i++) {
token = _e[i]; token = _f[i];
_g = token; _h = token;
tag = _g[0]; tag = _h[0];
value = _g[1]; value = _h[1];
if (tag === 'TOKENS') { if (tag === 'TOKENS') {
this.tokens = this.tokens.concat(value); this.tokens = this.tokens.concat(value);
} else if (tag === 'STRING' && escape_quotes) { } else if (tag === 'STRING' && escape_quotes) {

View File

@ -1,5 +1,5 @@
(function(){ (function(){
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, compact, del, flatten, helpers, literal, merge, statement, utility; var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IS_STRING, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, UTILITIES, ValueNode, WhileNode, _a, compact, del, flatten, helpers, literal, merge, statement, utility;
var __extends = function(child, parent) { var __extends = function(child, parent) {
var ctor = function(){ }; var ctor = function(){ };
ctor.prototype = parent.prototype; ctor.prototype = parent.prototype;
@ -26,10 +26,11 @@
Scope = this.Scope; Scope = this.Scope;
} }
// Import the helpers we plan to use. // Import the helpers we plan to use.
compact = helpers.compact; _a = helpers;
flatten = helpers.flatten; compact = _a.compact;
merge = helpers.merge; flatten = _a.flatten;
del = helpers.del; merge = _a.merge;
del = _a.del;
// Helper function that marks a node as a JavaScript *statement*, or as a // Helper function that marks a node as a JavaScript *statement*, or as a
// *pure_statement*. Statements must be wrapped in a closure when used as an // *pure_statement*. Statements must be wrapped in a closure when used as an
// expression, and nodes tagged as *pure_statement* cannot be closure-wrapped // expression, and nodes tagged as *pure_statement* cannot be closure-wrapped
@ -118,10 +119,10 @@
// and returning true when the block finds a match. `contains` does not cross // and returning true when the block finds a match. `contains` does not cross
// scope boundaries. // scope boundaries.
BaseNode.prototype.contains = function contains(block) { BaseNode.prototype.contains = function contains(block) {
var _a, _b, _c, node; var _b, _c, _d, node;
_b = this.children; _c = this.children;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
node = _b[_a]; node = _c[_b];
if (block(node)) { if (block(node)) {
return true; return true;
} }
@ -146,31 +147,31 @@
}; };
// Perform an in-order traversal of the AST. Crosses scope boundaries. // Perform an in-order traversal of the AST. Crosses scope boundaries.
BaseNode.prototype.traverse = function traverse(block) { BaseNode.prototype.traverse = function traverse(block) {
var _a, _b, _c, _d, node; var _b, _c, _d, _e, node;
_a = []; _c = this.children; _b = []; _d = this.children;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
node = _c[_b]; node = _d[_c];
_a.push((function() { _b.push((function() {
block(node); block(node);
if (node.traverse) { if (node.traverse) {
return node.traverse(block); return node.traverse(block);
} }
})()); })());
} }
return _a; return _b;
}; };
// `toString` representation of the node, for inspecting the parse tree. // `toString` representation of the node, for inspecting the parse tree.
// This is what `coffee --nodes` prints out. // This is what `coffee --nodes` prints out.
BaseNode.prototype.toString = function toString(idt) { BaseNode.prototype.toString = function toString(idt) {
var _a, _b, _c, _d, child; var _b, _c, _d, _e, child;
idt = idt || ''; idt = idt || '';
return '\n' + idt + this.constructor.name + (function() { return '\n' + idt + this.constructor.name + (function() {
_a = []; _c = this.children; _b = []; _d = this.children;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
child = _c[_b]; child = _d[_c];
_a.push(child.toString(idt + TAB)); _b.push(child.toString(idt + TAB));
} }
return _a; return _b;
}).call(this).join(''); }).call(this).join('');
}; };
// Default implementations of the common node identification methods. Nodes // Default implementations of the common node identification methods. Nodes
@ -254,14 +255,14 @@
} }
}; };
Expressions.prototype.compile_node = function compile_node(o) { Expressions.prototype.compile_node = function compile_node(o) {
var _a, _b, _c, _d, node; var _b, _c, _d, _e, node;
return (function() { return (function() {
_a = []; _c = this.expressions; _b = []; _d = this.expressions;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
node = _c[_b]; node = _d[_c];
_a.push(this.compile_expression(node, merge(o))); _b.push(this.compile_expression(node, merge(o)));
} }
return _a; return _b;
}).call(this).join("\n"); }).call(this).join("\n");
}; };
// If we happen to be the top-level **Expressions**, wrap everything in // If we happen to be the top-level **Expressions**, wrap everything in
@ -426,7 +427,7 @@
// operators `?.` interspersed. Then we have to take care not to accidentally // operators `?.` interspersed. Then we have to take care not to accidentally
// evaluate a anything twice when building the soak chain. // evaluate a anything twice when building the soak chain.
ValueNode.prototype.compile_node = function compile_node(o) { ValueNode.prototype.compile_node = function compile_node(o) {
var _a, _b, _c, baseline, complete, only, op, part, prop, props, soaked, temp; var _b, _c, _d, baseline, complete, only, op, part, prop, props, soaked, temp;
soaked = false; soaked = false;
only = del(o, 'only_first'); only = del(o, 'only_first');
op = del(o, 'operation'); op = del(o, 'operation');
@ -436,9 +437,9 @@
baseline = ("(" + baseline + ")"); baseline = ("(" + baseline + ")");
} }
complete = (this.last = baseline); complete = (this.last = baseline);
_b = props; _c = props;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
prop = _b[_a]; prop = _c[_b];
this.source = baseline; this.source = baseline;
if (prop.soak_node) { if (prop.soak_node) {
soaked = true; soaked = true;
@ -516,21 +517,21 @@
}; };
// Compile a vanilla function call. // Compile a vanilla function call.
CallNode.prototype.compile_node = function compile_node(o) { CallNode.prototype.compile_node = function compile_node(o) {
var _a, _b, _c, _d, _e, _f, _g, arg, args; var _b, _c, _d, _e, _f, _g, _h, arg, args;
_b = this.args; _c = this.args;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
arg = _b[_a]; arg = _c[_b];
if (arg instanceof SplatNode) { if (arg instanceof SplatNode) {
return this.compile_splat(o); return this.compile_splat(o);
} }
} }
args = (function() { args = (function() {
_d = []; _f = this.args; _e = []; _g = this.args;
for (_e = 0, _g = _f.length; _e < _g; _e++) { for (_f = 0, _h = _g.length; _f < _h; _f++) {
arg = _f[_e]; arg = _g[_f];
_d.push(arg.compile(o)); _e.push(arg.compile(o));
} }
return _d; return _e;
}).call(this).join(', '); }).call(this).join(', ');
if (this.is_super) { if (this.is_super) {
return this.compile_super(args, o); return this.compile_super(args, o);
@ -569,10 +570,10 @@
}; };
__extends(CurryNode, CallNode); __extends(CurryNode, CallNode);
CurryNode.prototype.arguments = function arguments(o) { CurryNode.prototype.arguments = function arguments(o) {
var _a, _b, _c, arg; var _b, _c, _d, arg;
_b = this.args; _c = this.args;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
arg = _b[_a]; arg = _c[_b];
if (arg instanceof SplatNode) { if (arg instanceof SplatNode) {
return this.compile_splat_arguments(o); return this.compile_splat_arguments(o);
} }
@ -653,14 +654,14 @@
__extends(RangeNode, BaseNode); __extends(RangeNode, BaseNode);
// Compiles the range's source variables -- where it starts and where it ends. // Compiles the range's source variables -- where it starts and where it ends.
RangeNode.prototype.compile_variables = function compile_variables(o) { RangeNode.prototype.compile_variables = function compile_variables(o) {
var _a, _b, from, to; var _b, _c, from, to;
this.tab = o.indent; this.tab = o.indent;
_a = [o.scope.free_variable(), o.scope.free_variable()]; _b = [o.scope.free_variable(), o.scope.free_variable()];
this.from_var = _a[0]; this.from_var = _b[0];
this.to_var = _a[1]; this.to_var = _b[1];
_b = [this.from.compile(o), this.to.compile(o)]; _c = [this.from.compile(o), this.to.compile(o)];
from = _b[0]; from = _c[0];
to = _b[1]; to = _c[1];
return "" + this.from_var + " = " + from + "; " + this.to_var + " = " + to + ";\n" + this.tab; return "" + this.from_var + " = " + from + "; " + this.to_var + " = " + to + ";\n" + this.tab;
}; };
// When compiled normally, the range returns the contents of the *for loop* // When compiled normally, the range returns the contents of the *for loop*
@ -727,22 +728,22 @@
// AssignNodes get interleaved correctly, with no trailing commas or // AssignNodes get interleaved correctly, with no trailing commas or
// commas affixed to comments. // commas affixed to comments.
ObjectNode.prototype.compile_node = function compile_node(o) { ObjectNode.prototype.compile_node = function compile_node(o) {
var _a, _b, _c, _d, _e, _f, _g, i, indent, inner, join, last_noncom, non_comments, prop, props; var _b, _c, _d, _e, _f, _g, _h, i, indent, inner, join, last_noncom, non_comments, prop, props;
o.indent = this.idt(1); o.indent = this.idt(1);
non_comments = (function() { non_comments = (function() {
_a = []; _c = this.properties; _b = []; _d = this.properties;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
prop = _c[_b]; prop = _d[_c];
!(prop instanceof CommentNode) ? _a.push(prop) : null; !(prop instanceof CommentNode) ? _b.push(prop) : null;
} }
return _a; return _b;
}).call(this); }).call(this);
last_noncom = non_comments[non_comments.length - 1]; last_noncom = non_comments[non_comments.length - 1];
props = (function() { props = (function() {
_e = []; _f = this.properties; _f = []; _g = this.properties;
for (i = 0, _g = _f.length; i < _g; i++) { for (i = 0, _h = _g.length; i < _h; i++) {
prop = _f[i]; prop = _g[i];
_e.push((function() { _f.push((function() {
join = ",\n"; join = ",\n";
if ((prop === last_noncom) || (prop instanceof CommentNode)) { if ((prop === last_noncom) || (prop instanceof CommentNode)) {
join = "\n"; join = "\n";
@ -754,7 +755,7 @@
return indent + prop.compile(o) + join; return indent + prop.compile(o) + join;
}).call(this)); }).call(this));
} }
return _e; return _f;
}).call(this); }).call(this);
props = props.join(''); props = props.join('');
inner = props ? '\n' + props + '\n' + this.idt() : ''; inner = props ? '\n' + props + '\n' + this.idt() : '';
@ -772,12 +773,12 @@
}; };
__extends(ArrayNode, BaseNode); __extends(ArrayNode, BaseNode);
ArrayNode.prototype.compile_node = function compile_node(o) { ArrayNode.prototype.compile_node = function compile_node(o) {
var _a, _b, code, ending, i, obj, objects; var _b, _c, code, ending, i, obj, objects;
o.indent = this.idt(1); o.indent = this.idt(1);
objects = []; objects = [];
_a = this.objects; _b = this.objects;
for (i = 0, _b = _a.length; i < _b; i++) { for (i = 0, _c = _b.length; i < _c; i++) {
obj = _a[i]; obj = _b[i];
code = obj.compile(o); code = obj.compile(o);
if (obj instanceof SplatNode) { if (obj instanceof SplatNode) {
return this.compile_splat_literal(this.objects, o); return this.compile_splat_literal(this.objects, o);
@ -814,17 +815,17 @@
// equivalent syntax tree and compile that, in pieces. You can see the // equivalent syntax tree and compile that, in pieces. You can see the
// constructor, property assignments, and inheritance getting built out below. // constructor, property assignments, and inheritance getting built out below.
ClassNode.prototype.compile_node = function compile_node(o) { ClassNode.prototype.compile_node = function compile_node(o) {
var _a, _b, _c, _d, access, applied, construct, extension, func, prop, props, pvar, returns, val; var _b, _c, _d, _e, access, applied, construct, extension, func, prop, props, pvar, returns, val;
extension = this.parent && new ExtendsNode(this.variable, this.parent); extension = this.parent && new ExtendsNode(this.variable, this.parent);
constructor = null; constructor = null;
props = new Expressions(); props = new Expressions();
o.top = true; o.top = true;
_b = this.properties; _c = this.properties;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
prop = _b[_a]; prop = _c[_b];
_d = [prop.variable, prop.value]; _e = [prop.variable, prop.value];
pvar = _d[0]; pvar = _e[0];
func = _d[1]; func = _e[1];
if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) { if (pvar && pvar.base.value === 'constructor' && func instanceof CodeNode) {
func.body.push(new ReturnNode(literal('this'))); func.body.push(new ReturnNode(literal('this')));
constructor = new AssignNode(this.variable, func); constructor = new AssignNode(this.variable, func);
@ -927,24 +928,24 @@
// See the [ECMAScript Harmony Wiki](http://wiki.ecmascript.org/doku.php?id=harmony:destructuring) // See the [ECMAScript Harmony Wiki](http://wiki.ecmascript.org/doku.php?id=harmony:destructuring)
// for details. // for details.
AssignNode.prototype.compile_pattern_match = function compile_pattern_match(o) { AssignNode.prototype.compile_pattern_match = function compile_pattern_match(o) {
var _a, _b, _c, access_class, assigns, code, i, idx, is_string, obj, oindex, olength, splat, val, val_var, value; var _b, _c, _d, access_class, assigns, code, i, idx, is_string, obj, oindex, olength, splat, val, val_var, value;
val_var = o.scope.free_variable(); val_var = o.scope.free_variable();
value = this.value.is_statement() ? ClosureNode.wrap(this.value) : this.value; value = this.value.is_statement() ? ClosureNode.wrap(this.value) : this.value;
assigns = [("" + this.tab + val_var + " = " + (value.compile(o)) + ";")]; assigns = [("" + this.tab + val_var + " = " + (value.compile(o)) + ";")];
o.top = true; o.top = true;
o.as_statement = true; o.as_statement = true;
splat = false; splat = false;
_a = this.variable.base.objects; _b = this.variable.base.objects;
for (i = 0, _b = _a.length; i < _b; i++) { for (i = 0, _c = _b.length; i < _c; i++) {
obj = _a[i]; obj = _b[i];
// A regular array pattern-match. // A regular array pattern-match.
idx = i; idx = i;
if (this.variable.is_object()) { if (this.variable.is_object()) {
if (obj instanceof AssignNode) { if (obj instanceof AssignNode) {
// A regular object pattern-match. // A regular object pattern-match.
_c = [obj.value, obj.variable.base]; _d = [obj.value, obj.variable.base];
obj = _c[0]; obj = _d[0];
idx = _c[1]; idx = _d[1];
} else { } else {
// A shorthand `{a, b, c}: val` pattern-match. // A shorthand `{a, b, c}: val` pattern-match.
idx = obj; idx = obj;
@ -1004,7 +1005,7 @@
// arrow, generates a wrapper that saves the current value of `this` through // arrow, generates a wrapper that saves the current value of `this` through
// a closure. // a closure.
CodeNode.prototype.compile_node = function compile_node(o) { CodeNode.prototype.compile_node = function compile_node(o) {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, code, func, i, name_part, param, params, ref, shared_scope, splat, top; var _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, code, func, i, name_part, param, params, ref, shared_scope, splat, top;
shared_scope = del(o, 'shared_scope'); shared_scope = del(o, 'shared_scope');
top = del(o, 'top'); top = del(o, 'top');
o.scope = shared_scope || new Scope(o.scope, this.body, this); o.scope = shared_scope || new Scope(o.scope, this.body, this);
@ -1015,9 +1016,9 @@
i = 0; i = 0;
splat = undefined; splat = undefined;
params = []; params = [];
_b = this.params; _c = this.params;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
param = _b[_a]; param = _c[_b];
if (param instanceof SplatNode && !(typeof splat !== "undefined" && splat !== null)) { if (param instanceof SplatNode && !(typeof splat !== "undefined" && splat !== null)) {
splat = param; splat = param;
splat.index = i; splat.index = i;
@ -1031,17 +1032,17 @@
i += 1; i += 1;
} }
params = (function() { params = (function() {
_d = []; _f = params; _e = []; _g = params;
for (_e = 0, _g = _f.length; _e < _g; _e++) { for (_f = 0, _h = _g.length; _f < _h; _f++) {
param = _f[_e]; param = _g[_f];
_d.push(param.compile(o)); _e.push(param.compile(o));
} }
return _d; return _e;
})(); })();
this.body.make_return(); this.body.make_return();
_i = params; _j = params;
for (_h = 0, _j = _i.length; _h < _j; _h++) { for (_i = 0, _k = _j.length; _i < _k; _i++) {
param = _i[_h]; param = _j[_i];
(o.scope.parameter(param)); (o.scope.parameter(param));
} }
code = this.body.expressions.length ? ("\n" + (this.body.compile_with_declarations(o)) + "\n") : ''; code = this.body.expressions.length ? ("\n" + (this.body.compile_with_declarations(o)) + "\n") : '';
@ -1067,25 +1068,25 @@
}; };
// Custom `traverse` implementation that uses the `real_children`. // Custom `traverse` implementation that uses the `real_children`.
CodeNode.prototype.traverse = function traverse(block) { CodeNode.prototype.traverse = function traverse(block) {
var _a, _b, _c, _d, child; var _b, _c, _d, _e, child;
block(this); block(this);
_a = []; _c = this.real_children(); _b = []; _d = this.real_children();
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
child = _c[_b]; child = _d[_c];
_a.push(child.traverse(block)); _b.push(child.traverse(block));
} }
return _a; return _b;
}; };
CodeNode.prototype.toString = function toString(idt) { CodeNode.prototype.toString = function toString(idt) {
var _a, _b, _c, _d, child, children; var _b, _c, _d, _e, child, children;
idt = idt || ''; idt = idt || '';
children = (function() { children = (function() {
_a = []; _c = this.real_children(); _b = []; _d = this.real_children();
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
child = _c[_b]; child = _d[_c];
_a.push(child.toString(idt + TAB)); _b.push(child.toString(idt + TAB));
} }
return _a; return _b;
}).call(this).join(''); }).call(this).join('');
return "\n" + idt + children; return "\n" + idt + children;
}; };
@ -1104,8 +1105,8 @@
}; };
__extends(SplatNode, BaseNode); __extends(SplatNode, BaseNode);
SplatNode.prototype.compile_node = function compile_node(o) { SplatNode.prototype.compile_node = function compile_node(o) {
var _a; var _b;
if ((typeof (_a = this.index) !== "undefined" && _a !== null)) { if ((typeof (_b = this.index) !== "undefined" && _b !== null)) {
return this.compile_param(o); return this.compile_param(o);
} else { } else {
return this.name.compile(o); return this.name.compile(o);
@ -1114,13 +1115,13 @@
// Compiling a parameter splat means recovering the parameters that succeed // Compiling a parameter splat means recovering the parameters that succeed
// the splat in the parameter list, by slicing the arguments object. // the splat in the parameter list, by slicing the arguments object.
SplatNode.prototype.compile_param = function compile_param(o) { SplatNode.prototype.compile_param = function compile_param(o) {
var _a, _b, _c, i, name, trailing; var _b, _c, _d, i, name, trailing;
name = this.name.compile(o); name = this.name.compile(o);
o.scope.find(name); o.scope.find(name);
i = 0; i = 0;
_b = this.trailings; _c = this.trailings;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
trailing = _b[_a]; trailing = _c[_b];
o.scope.assign(trailing.compile(o), ("arguments[arguments.length - " + this.trailings.length + " + " + i + "]")); o.scope.assign(trailing.compile(o), ("arguments[arguments.length - " + this.trailings.length + " + " + i + "]"));
i += 1; i += 1;
} }
@ -1136,12 +1137,12 @@
// Utility function that converts arbitrary number of elements, mixed with // Utility function that converts arbitrary number of elements, mixed with
// splats, to a proper array // splats, to a proper array
SplatNode.compile_mixed_array = function compile_mixed_array(list, o) { SplatNode.compile_mixed_array = function compile_mixed_array(list, o) {
var _a, _b, _c, arg, args, code, i, prev; var _b, _c, _d, arg, args, code, i, prev;
args = []; args = [];
i = 0; i = 0;
_b = list; _c = list;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
arg = _b[_a]; arg = _c[_b];
code = arg.compile(o); code = arg.compile(o);
if (!(arg instanceof SplatNode)) { if (!(arg instanceof SplatNode)) {
prev = args[i - 1]; prev = args[i - 1];
@ -1267,27 +1268,27 @@
// bin/coffee -e "puts 50 < 65 > 10" // bin/coffee -e "puts 50 < 65 > 10"
// true // true
OpNode.prototype.compile_chain = function compile_chain(o) { OpNode.prototype.compile_chain = function compile_chain(o) {
var _a, _b, first, second, shared; var _b, _c, first, second, shared;
shared = this.first.unwrap().second; shared = this.first.unwrap().second;
if (shared.contains_type(CallNode)) { if (shared.contains_type(CallNode)) {
_a = shared.compile_reference(o); _b = shared.compile_reference(o);
this.first.second = _a[0]; this.first.second = _b[0];
shared = _a[1]; shared = _b[1];
} }
_b = [this.first.compile(o), this.second.compile(o), shared.compile(o)]; _c = [this.first.compile(o), this.second.compile(o), shared.compile(o)];
first = _b[0]; first = _c[0];
second = _b[1]; second = _c[1];
shared = _b[2]; shared = _c[2];
return "(" + first + ") && (" + shared + " " + this.operator + " " + second + ")"; return "(" + first + ") && (" + shared + " " + this.operator + " " + second + ")";
}; };
// When compiling a conditional assignment, take care to ensure that the // When compiling a conditional assignment, take care to ensure that the
// operands are only evaluated once, even though we have to reference them // operands are only evaluated once, even though we have to reference them
// more than once. // more than once.
OpNode.prototype.compile_assignment = function compile_assignment(o) { OpNode.prototype.compile_assignment = function compile_assignment(o) {
var _a, first, second; var _b, first, second;
_a = [this.first.compile(o), this.second.compile(o)]; _b = [this.first.compile(o), this.second.compile(o)];
first = _a[0]; first = _b[0];
second = _a[1]; second = _b[1];
if (first.match(IDENTIFIER)) { if (first.match(IDENTIFIER)) {
o.scope.find(first); o.scope.find(first);
} }
@ -1299,10 +1300,10 @@
// If this is an existence operator, we delegate to `ExistenceNode.compile_test` // If this is an existence operator, we delegate to `ExistenceNode.compile_test`
// to give us the safe references for the variables. // to give us the safe references for the variables.
OpNode.prototype.compile_existence = function compile_existence(o) { OpNode.prototype.compile_existence = function compile_existence(o) {
var _a, first, second, test; var _b, first, second, test;
_a = [this.first.compile(o), this.second.compile(o)]; _b = [this.first.compile(o), this.second.compile(o)];
first = _a[0]; first = _b[0];
second = _a[1]; second = _b[1];
test = ExistenceNode.compile_test(o, this.first); test = ExistenceNode.compile_test(o, this.first);
return "" + test + " ? " + first + " : " + second; return "" + test + " ? " + first + " : " + second;
}; };
@ -1387,18 +1388,18 @@
// because other nodes like to check the existence of their variables as well. // because other nodes like to check the existence of their variables as well.
// Be careful not to double-evaluate anything. // Be careful not to double-evaluate anything.
ExistenceNode.compile_test = function compile_test(o, variable) { ExistenceNode.compile_test = function compile_test(o, variable) {
var _a, _b, _c, first, second; var _b, _c, _d, first, second;
_a = [variable, variable]; _b = [variable, variable];
first = _a[0]; first = _b[0];
second = _a[1]; second = _b[1];
if (variable instanceof CallNode || (variable instanceof ValueNode && variable.has_properties())) { if (variable instanceof CallNode || (variable instanceof ValueNode && variable.has_properties())) {
_b = variable.compile_reference(o); _c = variable.compile_reference(o);
first = _b[0]; first = _c[0];
second = _b[1]; second = _c[1];
} }
_c = [first.compile(o), second.compile(o)]; _d = [first.compile(o), second.compile(o)];
first = _c[0]; first = _d[0];
second = _c[1]; second = _d[1];
return "(typeof " + first + " !== \"undefined\" && " + second + " !== null)"; return "(typeof " + first + " !== \"undefined\" && " + second + " !== null)";
}; };
return ExistenceNode; return ExistenceNode;
@ -1447,7 +1448,7 @@
// you can map and filter in a single pass. // you can map and filter in a single pass.
exports.ForNode = (function() { exports.ForNode = (function() {
ForNode = function ForNode(body, source, name, index) { ForNode = function ForNode(body, source, name, index) {
var _a; var _b;
this.body = body; this.body = body;
this.name = name; this.name = name;
this.index = index || null; this.index = index || null;
@ -1456,9 +1457,9 @@
this.step = source.step; this.step = source.step;
this.object = !!source.object; this.object = !!source.object;
if (this.object) { if (this.object) {
_a = [this.index, this.name]; _b = [this.index, this.name];
this.name = _a[0]; this.name = _b[0];
this.index = _a[1]; this.index = _b[1];
} }
this.children = compact([this.body, this.source, this.filter]); this.children = compact([this.body, this.source, this.filter]);
this.returns = false; this.returns = false;
@ -1589,7 +1590,7 @@
// Rewrite a chain of **IfNodes** with their switch condition for equality. // Rewrite a chain of **IfNodes** with their switch condition for equality.
// Ensure that the switch expression isn't evaluated more than once. // Ensure that the switch expression isn't evaluated more than once.
IfNode.prototype.rewrite_switch = function rewrite_switch(o) { IfNode.prototype.rewrite_switch = function rewrite_switch(o) {
var _a, _b, _c, assigner, cond, i, variable; var _b, _c, _d, assigner, cond, i, variable;
assigner = this.switcher; assigner = this.switcher;
if (!(this.switcher.unwrap() instanceof LiteralNode)) { if (!(this.switcher.unwrap() instanceof LiteralNode)) {
variable = literal(o.scope.free_variable()); variable = literal(o.scope.free_variable());
@ -1598,12 +1599,12 @@
} }
this.condition = (function() { this.condition = (function() {
if (this.multiple) { if (this.multiple) {
_a = []; _b = this.condition; _b = []; _c = this.condition;
for (i = 0, _c = _b.length; i < _c; i++) { for (i = 0, _d = _c.length; i < _d; i++) {
cond = _b[i]; cond = _c[i];
_a.push(new OpNode('==', (i === 0 ? assigner : this.switcher), cond)); _b.push(new OpNode('==', (i === 0 ? assigner : this.switcher), cond));
} }
return _a; return _b;
} else { } else {
return new OpNode('==', assigner, this.condition); return new OpNode('==', assigner, this.condition);
} }
@ -1635,14 +1636,14 @@
return this.statement = this.statement || !!(this.comment || this.tags.statement || this.body.is_statement() || (this.else_body && this.else_body.is_statement())); return this.statement = this.statement || !!(this.comment || this.tags.statement || this.body.is_statement() || (this.else_body && this.else_body.is_statement()));
}; };
IfNode.prototype.compile_condition = function compile_condition(o) { IfNode.prototype.compile_condition = function compile_condition(o) {
var _a, _b, _c, _d, cond; var _b, _c, _d, _e, cond;
return (function() { return (function() {
_a = []; _c = flatten([this.condition]); _b = []; _d = flatten([this.condition]);
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
cond = _c[_b]; cond = _d[_c];
_a.push(cond.compile(o)); _b.push(cond.compile(o));
} }
return _a; return _b;
}).call(this).join(' || '); }).call(this).join(' || ');
}; };
IfNode.prototype.compile_node = function compile_node(o) { IfNode.prototype.compile_node = function compile_node(o) {

View File

@ -1,5 +1,5 @@
(function(){ (function(){
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, helpers, include, pair; var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, helpers, include, pair;
var __slice = Array.prototype.slice, __bind = function(func, obj, args) { var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
return function() { return function() {
return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments); return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
@ -19,7 +19,8 @@
helpers = this.helpers; helpers = this.helpers;
} }
// Import the helpers we need. // Import the helpers we need.
include = helpers.include; _a = helpers;
include = _a.include;
// The **Rewriter** class is used by the [Lexer](lexer.html), directly against // The **Rewriter** class is used by the [Lexer](lexer.html), directly against
// its internal array of tokens. // its internal array of tokens.
exports.Rewriter = (function() { exports.Rewriter = (function() {
@ -62,13 +63,13 @@
// correctly indented, or appear on a line of their own. // correctly indented, or appear on a line of their own.
Rewriter.prototype.adjust_comments = function adjust_comments() { Rewriter.prototype.adjust_comments = function adjust_comments() {
return this.scan_tokens(__bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var _a, after, before; var _b, after, before;
if (!(token[0] === 'COMMENT')) { if (!(token[0] === 'COMMENT')) {
return 1; return 1;
} }
_a = [this.tokens[i - 2], this.tokens[i + 2]]; _b = [this.tokens[i - 2], this.tokens[i + 2]];
before = _a[0]; before = _b[0];
after = _a[1]; after = _b[1];
if (after && after[0] === 'INDENT') { if (after && after[0] === 'INDENT') {
this.tokens.splice(i + 2, 1); this.tokens.splice(i + 2, 1);
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after); before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after);
@ -84,12 +85,12 @@
// Leading newlines would introduce an ambiguity in the grammar, so we // Leading newlines would introduce an ambiguity in the grammar, so we
// dispatch them here. // dispatch them here.
Rewriter.prototype.remove_leading_newlines = function remove_leading_newlines() { Rewriter.prototype.remove_leading_newlines = function remove_leading_newlines() {
var _a; var _b;
_a = []; _b = [];
while (this.tokens[0] && this.tokens[0][0] === 'TERMINATOR') { while (this.tokens[0] && this.tokens[0][0] === 'TERMINATOR') {
_a.push(this.tokens.shift()); _b.push(this.tokens.shift());
} }
return _a; return _b;
}; };
// Some blocks occur in the middle of expressions -- when we're expecting // Some blocks occur in the middle of expressions -- when we're expecting
// this, remove their trailing newlines. // this, remove their trailing newlines.
@ -110,23 +111,23 @@
parens = [0]; parens = [0];
brackets = [0]; brackets = [0];
return this.scan_tokens(__bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
var _a; var _b;
if ((_a = token[0]) === 'CALL_START') { if ((_b = token[0]) === 'CALL_START') {
parens.push(0); parens.push(0);
} else if (_a === 'INDEX_START') { } else if (_b === 'INDEX_START') {
brackets.push(0); brackets.push(0);
} else if (_a === '(') { } else if (_b === '(') {
parens[parens.length - 1] += 1; parens[parens.length - 1] += 1;
} else if (_a === '[') { } else if (_b === '[') {
brackets[brackets.length - 1] += 1; brackets[brackets.length - 1] += 1;
} else if (_a === ')') { } else if (_b === ')') {
if (parens[parens.length - 1] === 0) { if (parens[parens.length - 1] === 0) {
parens.pop(); parens.pop();
token[0] = 'CALL_END'; token[0] = 'CALL_END';
} else { } else {
parens[parens.length - 1] -= 1; parens[parens.length - 1] -= 1;
} }
} else if (_a === ']') { } else if (_b === ']') {
if (brackets[brackets.length - 1] === 0) { if (brackets[brackets.length - 1] === 0) {
brackets.pop(); brackets.pop();
token[0] = 'INDEX_END'; token[0] = 'INDEX_END';
@ -144,9 +145,9 @@
var close_calls, stack; var close_calls, stack;
stack = [0]; stack = [0];
close_calls = __bind(function(i) { close_calls = __bind(function(i) {
var _a, _b, _c, size, tmp; var _b, _c, _d, size, tmp;
_b = 0; _c = stack[stack.length - 1]; _c = 0; _d = stack[stack.length - 1];
for (_a = 0, tmp = _b; (_b <= _c ? tmp < _c : tmp > _c); (_b <= _c ? tmp += 1 : tmp -= 1), _a++) { for (_b = 0, tmp = _c; (_c <= _d ? tmp < _d : tmp > _d); (_c <= _d ? tmp += 1 : tmp -= 1), _b++) {
this.tokens.splice(i, 0, ['CALL_END', ')', this.tokens[i][2]]); this.tokens.splice(i, 0, ['CALL_END', ')', this.tokens[i][2]]);
} }
size = stack[stack.length - 1] + 1; size = stack[stack.length - 1] + 1;
@ -235,17 +236,17 @@
// Ensure that all listed pairs of tokens are correctly balanced throughout // Ensure that all listed pairs of tokens are correctly balanced throughout
// the course of the token stream. // the course of the token stream.
Rewriter.prototype.ensure_balance = function ensure_balance(pairs) { Rewriter.prototype.ensure_balance = function ensure_balance(pairs) {
var _a, _b, key, levels, line, open, open_line, unclosed, value; var _b, _c, key, levels, line, open, open_line, unclosed, value;
levels = {}; levels = {};
open_line = {}; open_line = {};
this.scan_tokens(__bind(function(prev, token, post, i) { this.scan_tokens(__bind(function(prev, token, post, i) {
var _a, _b, _c, _d, close, open, pair; var _b, _c, _d, _e, close, open, pair;
_b = pairs; _c = pairs;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
pair = _b[_a]; pair = _c[_b];
_d = pair; _e = pair;
open = _d[0]; open = _e[0];
close = _d[1]; close = _e[1];
levels[open] = levels[open] || 0; levels[open] = levels[open] || 0;
if (token[0] === open) { if (token[0] === open) {
if (levels[open] === 0) { if (levels[open] === 0) {
@ -263,12 +264,12 @@
return 1; return 1;
}, this)); }, this));
unclosed = (function() { unclosed = (function() {
_a = []; _b = levels; _b = []; _c = levels;
for (key in _b) { if (__hasProp.call(_b, key)) { for (key in _c) { if (__hasProp.call(_c, key)) {
value = _b[key]; value = _c[key];
value > 0 ? _a.push(key) : null; value > 0 ? _b.push(key) : null;
}} }}
return _a; return _b;
})(); })();
if (unclosed.length) { if (unclosed.length) {
open = unclosed[0]; open = unclosed[0];
@ -290,12 +291,12 @@
// 4. Be careful not to alter array or parentheses delimiters with overzealous // 4. Be careful not to alter array or parentheses delimiters with overzealous
// rewriting. // rewriting.
Rewriter.prototype.rewrite_closing_parens = function rewrite_closing_parens() { Rewriter.prototype.rewrite_closing_parens = function rewrite_closing_parens() {
var _a, debt, key, stack, val; var _b, debt, key, stack, val;
stack = []; stack = [];
debt = {}; debt = {};
_a = INVERSES; _b = INVERSES;
for (key in _a) { if (__hasProp.call(_a, key)) { for (key in _b) { if (__hasProp.call(_b, key)) {
val = _a[key]; val = _b[key];
(debt[key] = 0); (debt[key] = 0);
}} }}
return this.scan_tokens(__bind(function(prev, token, post, i) { return this.scan_tokens(__bind(function(prev, token, post, i) {
@ -341,29 +342,29 @@
// The inverse mappings of `BALANCED_PAIRS` we're trying to fix up, so we can // The inverse mappings of `BALANCED_PAIRS` we're trying to fix up, so we can
// look things up from either end. // look things up from either end.
INVERSES = {}; INVERSES = {};
_b = BALANCED_PAIRS; _c = BALANCED_PAIRS;
for (_a = 0, _c = _b.length; _a < _c; _a++) { for (_b = 0, _d = _c.length; _b < _d; _b++) {
pair = _b[_a]; pair = _c[_b];
INVERSES[pair[0]] = pair[1]; INVERSES[pair[0]] = pair[1];
INVERSES[pair[1]] = pair[0]; INVERSES[pair[1]] = pair[0];
} }
// The tokens that signal the start of a balanced pair. // The tokens that signal the start of a balanced pair.
EXPRESSION_START = (function() { EXPRESSION_START = (function() {
_d = []; _f = BALANCED_PAIRS; _e = []; _g = BALANCED_PAIRS;
for (_e = 0, _g = _f.length; _e < _g; _e++) { for (_f = 0, _h = _g.length; _f < _h; _f++) {
pair = _f[_e]; pair = _g[_f];
_d.push(pair[0]); _e.push(pair[0]);
} }
return _d; return _e;
})(); })();
// The tokens that signal the end of a balanced pair. // The tokens that signal the end of a balanced pair.
EXPRESSION_END = (function() { EXPRESSION_END = (function() {
_h = []; _j = BALANCED_PAIRS; _i = []; _k = BALANCED_PAIRS;
for (_i = 0, _k = _j.length; _i < _k; _i++) { for (_j = 0, _l = _k.length; _j < _l; _j++) {
pair = _j[_i]; pair = _k[_j];
_h.push(pair[1]); _i.push(pair[1]);
} }
return _h; return _i;
})(); })();
// Tokens that indicate the close of a clause of an expression. // Tokens that indicate the close of a clause of an expression.
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END); EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);

View File

@ -5,11 +5,11 @@
# interactive REPL. # interactive REPL.
# External dependencies. # External dependencies.
fs: require 'fs' fs: require 'fs'
path: require 'path' path: require 'path'
optparse: require './optparse' optparse: require './optparse'
CoffeeScript: require './coffee-script' CoffeeScript: require './coffee-script'
{spawn: spawn, exec: exec}: require('child_process') {spawn, exec}: require('child_process')
# The help banner that is printed when `coffee` is called without arguments. # The help banner that is printed when `coffee` is called without arguments.
BANNER: ''' BANNER: '''
@ -123,7 +123,7 @@ write_js: (source, js) ->
# Pipe compiled JS through JSLint (requires a working `jsl` command), printing # Pipe compiled JS through JSLint (requires a working `jsl` command), printing
# any errors or warnings that arise. # any errors or warnings that arise.
lint: (js) -> lint: (js) ->
print_it: (buffer) -> puts buffer.toString() print_it: (buffer) -> print buffer.toString()
jsl: spawn 'jsl', ['-nologo', '-stdin'] jsl: spawn 'jsl', ['-nologo', '-stdin']
jsl.stdout.addListener 'data', print_it jsl.stdout.addListener 'data', print_it
jsl.stderr.addListener 'data', print_it jsl.stderr.addListener 'data', print_it

View File

@ -17,11 +17,7 @@ else
helpers: this.helpers helpers: this.helpers
# Import the helpers we need. # Import the helpers we need.
include: helpers.include {include, count, starts, compact, balanced_string}: helpers
count: helpers.count
starts: helpers.starts
compact: helpers.compact
balanced_string: helpers.balanced_string
# The Lexer Class # The Lexer Class
# --------------- # ---------------

View File

@ -14,10 +14,7 @@ else
Scope: this.Scope Scope: this.Scope
# Import the helpers we plan to use. # Import the helpers we plan to use.
compact: helpers.compact {compact, flatten, merge, del}: helpers
flatten: helpers.flatten
merge: helpers.merge
del: helpers.del
# Helper function that marks a node as a JavaScript *statement*, or as a # Helper function that marks a node as a JavaScript *statement*, or as a
# *pure_statement*. Statements must be wrapped in a closure when used as an # *pure_statement*. Statements must be wrapped in a closure when used as an

View File

@ -13,7 +13,7 @@ else
helpers: this.helpers helpers: this.helpers
# Import the helpers we need. # Import the helpers we need.
include: helpers.include {include}: helpers
# The **Rewriter** class is used by the [Lexer](lexer.html), directly against # The **Rewriter** class is used by the [Lexer](lexer.html), directly against
# its internal array of tokens. # its internal array of tokens.