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"
|
2020-07-04 17:59:26 +00:00
|
|
|
"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{
|
2020-07-04 17:59:26 +00:00
|
|
|
Node: ast.Node{
|
|
|
|
Tokens: token.Collection{
|
|
|
|
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{
|
|
|
|
Variadic: true,
|
2020-05-12 21:16:36 +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
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
|
|
|
// 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: "",
|
|
|
|
// },
|
|
|
|
// &ast.Parameter{
|
|
|
|
// Variadic: true,
|
|
|
|
// Var: &ast.ExprVariable{
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// &ast.StmtInlineHtml{
|
|
|
|
// Value: "foo",
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
//}
|
|
|
|
}
|