update dumper
This commit is contained in:
parent
e3ed427fac
commit
321a8d51e5
@ -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))
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user