From 4bad3e0f4f382295b6bbb400a1145a59a48164ba Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 13 Feb 2010 09:51:52 -0500 Subject: [PATCH] nicer --tree printing, with values inlines to the right --- lib/coffee_script/nodes.js | 14 +++++++------- src/nodes.coffee | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/coffee_script/nodes.js b/lib/coffee_script/nodes.js index 509b82e8..d7e2eab5 100644 --- a/lib/coffee_script/nodes.js +++ b/lib/coffee_script/nodes.js @@ -108,9 +108,9 @@ }; // toString representation of the node, for inspecting the parse tree. Node.prototype.toString = function toString(idt) { - idt = (idt || '') + TAB; - return this.type + '\n' + _.map(this.children, function(child) { - return idt + child.toString(idt); + idt = idt || ''; + return '\n' + idt + this.type + _.map(this.children, function(child) { + return child.toString(idt + TAB); }).join(''); }; // Default implementations of the common node methods. @@ -255,7 +255,7 @@ return idt + this.value + end; }, toString: function toString(idt) { - return '"' + this.value + '"' + '\n'; + return ' "' + this.value + '"'; } })); LiteralNode.prototype.is_statement_only = LiteralNode.prototype.is_statement; @@ -806,10 +806,10 @@ }, toString: function toString(idt) { var children; - idt = (idt || '') + TAB; + idt = idt || ''; children = _.flatten([this.params, this.body.expressions]); - return this.type + '\n' + _.map(children, function(child) { - return idt + child.toString(idt); + return '\n' + idt + this.type + _.map(children, function(child) { + return child.toString(idt + TAB); }).join(''); } })); diff --git a/src/nodes.coffee b/src/nodes.coffee index f5ac353a..66474ec9 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -78,8 +78,8 @@ Node::contains: (block) -> # toString representation of the node, for inspecting the parse tree. Node::toString: (idt) -> - idt: (idt || '') + TAB - @type + '\n' + _.map(@children, (child) -> idt + child.toString(idt)).join('') + idt ||= '' + '\n' + idt + @type + _.map(@children, (child) -> child.toString(idt + TAB)).join('') # Default implementations of the common node methods. Node::unwrap: -> this @@ -189,7 +189,7 @@ LiteralNode: exports.LiteralNode: inherit Node, { idt + @value + end toString: (idt) -> - '"' + @value + '"' + '\n' + ' "' + @value + '"' } @@ -653,9 +653,9 @@ CodeNode: exports.CodeNode: inherit Node, { true toString: (idt) -> - idt: (idt || '') + TAB + idt ||= '' 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('') }