ast: print unknown node type

This commit is contained in:
Fatih Arslan 2015-10-24 23:12:28 +03:00
parent a995361468
commit de7241ebe5

View File

@ -1,5 +1,7 @@
package ast package ast
import "fmt"
// Walk traverses an AST in depth-first order: It starts by calling fn(node); // Walk traverses an AST in depth-first order: It starts by calling fn(node);
// node must not be nil. If f returns true, Walk invokes f recursively for // node must not be nil. If f returns true, Walk invokes f recursively for
// each of the non-nil children of node, followed by a call of f(nil). // each of the non-nil children of node, followed by a call of f(nil).
@ -30,6 +32,8 @@ func Walk(node Node, fn func(Node) bool) {
for _, l := range n.List.Items { for _, l := range n.List.Items {
Walk(l, fn) Walk(l, fn)
} }
default:
fmt.Printf(" unknown type: %T\n", n)
} }
fn(nil) fn(nil)