From a4f1e5c786bb9fedf9ed5b76b58a1c5142b693fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Wed, 27 Jul 2016 09:44:24 +0300 Subject: [PATCH] Limit Node.String() to print itself, no children --- node.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/node.go b/node.go index d40cf8a..58f399f 100644 --- a/node.go +++ b/node.go @@ -128,6 +128,16 @@ func NewNode(typ NodeType) *Node { } } +func (n *Node) String() string { + ellipsis := "" + snippet := n.Literal + if len(snippet) > 16 { + snippet = snippet[:16] + ellipsis = "..." + } + return fmt.Sprintf("%s: '%s%s'", n.Type, snippet, ellipsis) +} + func (n *Node) unlink() { if n.Prev != nil { n.Prev.Next = n.Next @@ -310,10 +320,6 @@ func (nw *NodeWalker) resumeAt(node *Node, entering bool) (*Node, bool) { return nw.next() } -func (ast *Node) String() string { - return dumpString(ast) -} - func dump(ast *Node) { fmt.Println(dumpString(ast)) }