php-parser/dumper.go

43 lines
747 B
Go
Raw Normal View History

2017-12-27 23:23:32 +00:00
package main
import (
"fmt"
2018-01-04 18:29:07 +00:00
"reflect"
2017-12-27 23:23:32 +00:00
"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
2018-01-04 18:29:07 +00:00
fmt.Printf("%v%v", d.indent, reflect.TypeOf(n))
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
2018-01-05 15:03:59 +00:00
if c := n.Comments(); c != nil && len(*c) > 0 {
fmt.Printf("%vcomments:\n", d.indent+" ")
for _, cc := range *c {
fmt.Printf("%v%q\n", d.indent+" ", cc)
}
}
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
}