php-parser/dumper.go

35 lines
554 B
Go
Raw Normal View History

2017-12-27 23:23:32 +00:00
package main
import (
"fmt"
"github.com/z7zmey/php-parser/node"
)
type dumper struct {
indent string
}
2017-12-28 11:36:27 +00:00
func (d dumper) EnterNode(n node.Node) bool {
2017-12-29 15:20:24 +00:00
fmt.Printf("%v%v", d.indent, n.Name())
2017-12-31 18:53:55 +00:00
if p := n.Position(); p != nil {
fmt.Printf(" %v", *p)
}
2017-12-29 15:53:13 +00:00
if a := n.Attributes(); len(a) > 0 {
2017-12-29 15:20:24 +00:00
fmt.Printf(" %v", a)
}
fmt.Println()
2017-12-27 23:23:32 +00:00
return true
}
2017-12-28 11:36:27 +00:00
func (d dumper) GetChildrenVisitor(key string) node.Visitor {
2017-12-29 15:20:24 +00:00
fmt.Printf("%v%q:\n", d.indent+" ", key)
return dumper{d.indent + " "}
2017-12-27 23:23:32 +00:00
}
2017-12-28 11:36:27 +00:00
func (d dumper) LeaveNode(n node.Node) {
// do nothing
}