From 321a8d51e5db6164c53aa3808eae10c68ff94a81 Mon Sep 17 00:00:00 2001 From: z7zmey Date: Tue, 20 Feb 2018 20:05:04 +0200 Subject: [PATCH] update dumper --- visitor/dumper.go | 15 +-------------- walker/walker.go | 10 ++++++---- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/visitor/dumper.go b/visitor/dumper.go index 6a0c593..2ad5a2d 100644 --- a/visitor/dumper.go +++ b/visitor/dumper.go @@ -1,4 +1,4 @@ -package visitor +package visitor // Visitor implementations import ( "fmt" @@ -11,15 +11,6 @@ import ( "github.com/z7zmey/php-parser/walker" ) -func isWalkerImplementsNodeInterface(w walker.Walkable) bool { - switch w.(type) { - case node.Node: - return true - default: - return false - } -} - // Dumper prints ast hierarchy to stdout // Also prints comments and positions attached to nodes type Dumper struct { @@ -30,10 +21,6 @@ type Dumper struct { // EnterNode is invoked at every node in heirerchy func (d Dumper) EnterNode(w walker.Walkable) bool { - if !isWalkerImplementsNodeInterface(w) { - return false - } - n := w.(node.Node) fmt.Printf("%v%v", d.Indent, reflect.TypeOf(n)) diff --git a/walker/walker.go b/walker/walker.go index 9cd41a7..8f3ad41 100644 --- a/walker/walker.go +++ b/walker/walker.go @@ -1,13 +1,15 @@ -package walker +package walker // Node walking behavior // Walkable interface +// +// Every node must implement this interface type Walkable interface { Walk(v Visitor) } // Visitor interface type Visitor interface { - EnterNode(w Walkable) bool // EnterNode invoked for each node encountered by Walk. - GetChildrenVisitor(Key string) Visitor // GetChildrenVisitor returns visitor for children nodes - LeaveNode(w Walkable) // LeaveNode invoked after process node + EnterNode(w Walkable) bool // EnterNode is invoked for each node encountered by Walk. + GetChildrenVisitor(Key string) Visitor // GetChildrenVisitor is invoked at every node parameter that contains children nodes + LeaveNode(w Walkable) // LeaveNode is invoked after process node }