update dumper

This commit is contained in:
z7zmey 2018-02-20 20:05:04 +02:00
parent e3ed427fac
commit 321a8d51e5
2 changed files with 7 additions and 18 deletions

View File

@ -1,4 +1,4 @@
package visitor package visitor // Visitor implementations
import ( import (
"fmt" "fmt"
@ -11,15 +11,6 @@ import (
"github.com/z7zmey/php-parser/walker" "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 // Dumper prints ast hierarchy to stdout
// Also prints comments and positions attached to nodes // Also prints comments and positions attached to nodes
type Dumper struct { type Dumper struct {
@ -30,10 +21,6 @@ type Dumper struct {
// EnterNode is invoked at every node in heirerchy // EnterNode is invoked at every node in heirerchy
func (d Dumper) EnterNode(w walker.Walkable) bool { func (d Dumper) EnterNode(w walker.Walkable) bool {
if !isWalkerImplementsNodeInterface(w) {
return false
}
n := w.(node.Node) n := w.(node.Node)
fmt.Printf("%v%v", d.Indent, reflect.TypeOf(n)) fmt.Printf("%v%v", d.Indent, reflect.TypeOf(n))

View File

@ -1,13 +1,15 @@
package walker package walker // Node walking behavior
// Walkable interface // Walkable interface
//
// Every node must implement this interface
type Walkable interface { type Walkable interface {
Walk(v Visitor) Walk(v Visitor)
} }
// Visitor interface // Visitor interface
type Visitor interface { type Visitor interface {
EnterNode(w Walkable) bool // EnterNode invoked for each node encountered by Walk. EnterNode(w Walkable) bool // EnterNode is invoked for each node encountered by Walk.
GetChildrenVisitor(Key string) Visitor // GetChildrenVisitor returns visitor for children nodes GetChildrenVisitor(Key string) Visitor // GetChildrenVisitor is invoked at every node parameter that contains children nodes
LeaveNode(w Walkable) // LeaveNode invoked after process node LeaveNode(w Walkable) // LeaveNode is invoked after process node
} }