nicer --tree printing, with values inlines to the right

This commit is contained in:
Jeremy Ashkenas
2010-02-13 09:51:52 -05:00
parent 8147ef554a
commit 4bad3e0f4f
2 changed files with 12 additions and 12 deletions

View File

@@ -108,9 +108,9 @@
}; };
// toString representation of the node, for inspecting the parse tree. // toString representation of the node, for inspecting the parse tree.
Node.prototype.toString = function toString(idt) { Node.prototype.toString = function toString(idt) {
idt = (idt || '') + TAB; idt = idt || '';
return this.type + '\n' + _.map(this.children, function(child) { return '\n' + idt + this.type + _.map(this.children, function(child) {
return idt + child.toString(idt); return child.toString(idt + TAB);
}).join(''); }).join('');
}; };
// Default implementations of the common node methods. // Default implementations of the common node methods.
@@ -255,7 +255,7 @@
return idt + this.value + end; return idt + this.value + end;
}, },
toString: function toString(idt) { toString: function toString(idt) {
return '"' + this.value + '"' + '\n'; return ' "' + this.value + '"';
} }
})); }));
LiteralNode.prototype.is_statement_only = LiteralNode.prototype.is_statement; LiteralNode.prototype.is_statement_only = LiteralNode.prototype.is_statement;
@@ -806,10 +806,10 @@
}, },
toString: function toString(idt) { toString: function toString(idt) {
var children; var children;
idt = (idt || '') + TAB; idt = idt || '';
children = _.flatten([this.params, this.body.expressions]); children = _.flatten([this.params, this.body.expressions]);
return this.type + '\n' + _.map(children, function(child) { return '\n' + idt + this.type + _.map(children, function(child) {
return idt + child.toString(idt); return child.toString(idt + TAB);
}).join(''); }).join('');
} }
})); }));

View File

@@ -78,8 +78,8 @@ Node::contains: (block) ->
# toString representation of the node, for inspecting the parse tree. # toString representation of the node, for inspecting the parse tree.
Node::toString: (idt) -> Node::toString: (idt) ->
idt: (idt || '') + TAB idt ||= ''
@type + '\n' + _.map(@children, (child) -> idt + child.toString(idt)).join('') '\n' + idt + @type + _.map(@children, (child) -> child.toString(idt + TAB)).join('')
# Default implementations of the common node methods. # Default implementations of the common node methods.
Node::unwrap: -> this Node::unwrap: -> this
@@ -189,7 +189,7 @@ LiteralNode: exports.LiteralNode: inherit Node, {
idt + @value + end idt + @value + end
toString: (idt) -> toString: (idt) ->
'"' + @value + '"' + '\n' ' "' + @value + '"'
} }
@@ -653,9 +653,9 @@ CodeNode: exports.CodeNode: inherit Node, {
true true
toString: (idt) -> toString: (idt) ->
idt: (idt || '') + TAB idt ||= ''
children: _.flatten [@params, @body.expressions] children: _.flatten [@params, @body.expressions]
@type + '\n' + _.map(children, (child) -> idt + child.toString(idt)).join('') '\n' + idt + @type + _.map(children, (child) -> child.toString(idt + TAB)).join('')
} }