Limit Node.String() to print itself, no children
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 27 Jul 2016 09:44:24 +0300
1 files changed,
10 insertions(+),
4 deletions(-)
jump to
M
node.go
→
node.go
@@ -128,6 +128,16 @@ open: true,
} } +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@@ -308,10 +318,6 @@ func (nw *NodeWalker) resumeAt(node *Node, entering bool) (*Node, bool) {
nw.current = node nw.entering = entering return nw.next() -} - -func (ast *Node) String() string { - return dumpString(ast) } func dump(ast *Node) {