2020-03-12 22:20:48 +00:00
|
|
|
package visitor_test
|
|
|
|
|
|
|
|
import (
|
2020-12-11 08:05:02 +00:00
|
|
|
"os"
|
|
|
|
|
2020-03-12 22:20:48 +00:00
|
|
|
"github.com/z7zmey/php-parser/pkg/ast"
|
|
|
|
"github.com/z7zmey/php-parser/pkg/ast/traverser"
|
|
|
|
"github.com/z7zmey/php-parser/pkg/ast/visitor"
|
2020-07-04 17:59:26 +00:00
|
|
|
"github.com/z7zmey/php-parser/pkg/token"
|
2020-03-12 22:20:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleDump() {
|
|
|
|
stxTree := &ast.Root{
|
|
|
|
Stmts: []ast.Vertex{
|
|
|
|
&ast.Identifier{},
|
|
|
|
&ast.Parameter{
|
2020-07-05 19:47:46 +00:00
|
|
|
Var: &ast.ExprVariable{},
|
2020-03-12 22:20:48 +00:00
|
|
|
},
|
|
|
|
&ast.StmtInlineHtml{
|
2020-05-13 18:05:15 +00:00
|
|
|
Value: []byte("foo"),
|
2020-03-12 22:20:48 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-11 08:05:02 +00:00
|
|
|
EndTkn: &token.Token{
|
|
|
|
ID: token.T_WHITESPACE,
|
|
|
|
Value: []byte(" "),
|
|
|
|
},
|
2020-03-12 22:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
traverser.NewDFS(visitor.NewDump(os.Stdout)).Traverse(stxTree)
|
|
|
|
|
|
|
|
//output:
|
|
|
|
//&ast.Root{
|
2020-07-04 17:59:26 +00:00
|
|
|
// Node: ast.Node{
|
|
|
|
// Tokens: token.Collection{
|
2020-08-17 17:31:04 +00:00
|
|
|
// token.Start: []*token.Token{
|
2020-07-04 17:59:26 +00:00
|
|
|
// {
|
|
|
|
// ID: token.T_WHITESPACE,
|
|
|
|
// Value: []byte(" "),
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// Position: &position.Position{
|
|
|
|
// StartLine: 1,
|
|
|
|
// EndLine: 1,
|
|
|
|
// StartPos: 0,
|
|
|
|
// EndPos: 1,
|
|
|
|
// },
|
|
|
|
// },
|
2020-03-12 22:20:48 +00:00
|
|
|
// Stmts: []ast.Vertex{
|
|
|
|
// &ast.Identifier{
|
2020-07-04 18:10:41 +00:00
|
|
|
// Value: []byte(""),
|
2020-03-12 22:20:48 +00:00
|
|
|
// },
|
|
|
|
// &ast.Parameter{
|
|
|
|
// Var: &ast.ExprVariable{
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// &ast.StmtInlineHtml{
|
2020-07-04 18:10:41 +00:00
|
|
|
// Value: []byte("foo"),
|
2020-03-12 22:20:48 +00:00
|
|
|
// },
|
|
|
|
// },
|
|
|
|
//}
|
|
|
|
}
|