rename Walker to Walkable interface

This commit is contained in:
z7zmey 2018-02-20 19:52:07 +02:00
parent a762ab3754
commit e3ed427fac
11 changed files with 24 additions and 24 deletions

View File

@ -137,12 +137,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {

View File

@ -240,12 +240,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {

View File

@ -73,12 +73,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {

View File

@ -360,12 +360,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {

View File

@ -43,12 +43,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestNameVisitorDisableChildren(t *testing.T) {
for _, tt := range nameNodesTests {

View File

@ -4,6 +4,6 @@ import "github.com/z7zmey/php-parser/walker"
// Node interface
type Node interface {
walker.Walker
walker.Walkable
Attributes() map[string]interface{} // Attributes returns node attributes as map
}

View File

@ -52,12 +52,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestNameVisitorDisableChildren(t *testing.T) {
for _, tt := range nameNodesTests {

View File

@ -486,12 +486,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {

View File

@ -51,12 +51,12 @@ type visitorMock struct {
visitedKeys []string
}
func (v *visitorMock) EnterNode(n walker.Walker) bool { return v.visitChildren }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor {
v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
}
func (v *visitorMock) LeaveNode(n walker.Walker) {}
func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func TestNameVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest {

View File

@ -11,7 +11,7 @@ import (
"github.com/z7zmey/php-parser/walker"
)
func isWalkerImplementsNodeInterface(w walker.Walker) bool {
func isWalkerImplementsNodeInterface(w walker.Walkable) bool {
switch w.(type) {
case node.Node:
return true
@ -29,7 +29,7 @@ type Dumper struct {
}
// EnterNode is invoked at every node in heirerchy
func (d Dumper) EnterNode(w walker.Walker) bool {
func (d Dumper) EnterNode(w walker.Walkable) bool {
if !isWalkerImplementsNodeInterface(w) {
return false
}
@ -62,6 +62,6 @@ func (d Dumper) GetChildrenVisitor(key string) walker.Visitor {
}
// LeaveNode is invoked after node process
func (d Dumper) LeaveNode(n walker.Walker) {
func (d Dumper) LeaveNode(n walker.Walkable) {
// do nothing
}

View File

@ -1,13 +1,13 @@
package walker
// Walker interface
type Walker interface {
// Walkable interface
type Walkable interface {
Walk(v Visitor)
}
// Visitor interface
type Visitor interface {
EnterNode(w Walker) bool // EnterNode invoked for each node encountered by Walk.
EnterNode(w Walkable) bool // EnterNode invoked for each node encountered by Walk.
GetChildrenVisitor(Key string) Visitor // GetChildrenVisitor returns visitor for children nodes
LeaveNode(w Walker) // LeaveNode invoked after process node
LeaveNode(w Walkable) // LeaveNode invoked after process node
}