php-parser/pkg/ast/visitor/dump_test.go

75 lines
1.4 KiB
Go
Raw Normal View History

2020-03-12 22:20:48 +00:00
package visitor_test
import (
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/ast/traverser"
"github.com/z7zmey/php-parser/pkg/ast/visitor"
"github.com/z7zmey/php-parser/pkg/position"
"github.com/z7zmey/php-parser/pkg/token"
2020-03-12 22:20:48 +00:00
"os"
)
func ExampleDump() {
stxTree := &ast.Root{
Node: ast.Node{
Tokens: token.Collection{
2020-08-17 17:31:04 +00:00
token.Start: []*token.Token{
{
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{},
&ast.Parameter{
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
},
},
}
traverser.NewDFS(visitor.NewDump(os.Stdout)).Traverse(stxTree)
//output:
//&ast.Root{
// Node: ast.Node{
// Tokens: token.Collection{
2020-08-17 17:31:04 +00:00
// token.Start: []*token.Token{
// {
// 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{
// Value: []byte(""),
2020-03-12 22:20:48 +00:00
// },
// &ast.Parameter{
// Var: &ast.ExprVariable{
// },
// },
// &ast.StmtInlineHtml{
// Value: []byte("foo"),
2020-03-12 22:20:48 +00:00
// },
// },
//}
}