refactor token structure
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
type Vertex interface {
|
||||
Accept(v NodeVisitor)
|
||||
|
||||
SetPosition(p *position.Position)
|
||||
GetPosition() *position.Position
|
||||
GetFreeFloating() *freefloating.Collection
|
||||
GetNode() *Node
|
||||
}
|
||||
|
||||
type Traverser interface {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package ast_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/z7zmey/php-parser/pkg/ast"
|
||||
"github.com/z7zmey/php-parser/pkg/ast/traverser"
|
||||
@@ -11,92 +9,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ExampleJSON() {
|
||||
stxTree := &ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.Nullable{
|
||||
Expr: &ast.Parameter{
|
||||
Type: nil,
|
||||
Var: nil,
|
||||
DefaultValue: nil,
|
||||
},
|
||||
},
|
||||
&ast.Identifier{},
|
||||
&ast.ArgumentList{
|
||||
Arguments: []ast.Vertex{
|
||||
&ast.Argument{},
|
||||
&ast.Argument{
|
||||
Expr: &ast.ScalarDnumber{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
jsonStxTree, err := json.Marshal(stxTree)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
err = json.Indent(buf, jsonStxTree, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Fprint(os.Stdout, buf.String())
|
||||
|
||||
// output:
|
||||
// {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Stmts": [
|
||||
// {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Expr": {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "ByRef": false,
|
||||
// "Variadic": false,
|
||||
// "Type": null,
|
||||
// "Var": null,
|
||||
// "DefaultValue": null
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Value": ""
|
||||
// },
|
||||
// {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Arguments": [
|
||||
// {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Variadic": false,
|
||||
// "IsReference": false,
|
||||
// "Expr": null
|
||||
// },
|
||||
// {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Variadic": false,
|
||||
// "IsReference": false,
|
||||
// "Expr": {
|
||||
// "FreeFloating": null,
|
||||
// "Position": null,
|
||||
// "Value": ""
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
}
|
||||
|
||||
func ExampleStxTree() {
|
||||
stxTree := &ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/pkg/token"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
FreeFloating freefloating.Collection
|
||||
StartTokens []token.Token
|
||||
EndTokens []token.Token
|
||||
Position *position.Position
|
||||
}
|
||||
|
||||
// SetPosition sets node position
|
||||
func (n *Node) SetPosition(p *position.Position) {
|
||||
n.Position = p
|
||||
}
|
||||
|
||||
// GetPosition returns node positions
|
||||
func (n *Node) GetPosition() *position.Position {
|
||||
return n.Position
|
||||
}
|
||||
|
||||
func (n *Node) GetFreeFloating() *freefloating.Collection {
|
||||
return &n.FreeFloating
|
||||
func (n *Node) GetNode() *Node {
|
||||
return n
|
||||
}
|
||||
|
||||
// Root node
|
||||
|
||||
Reference in New Issue
Block a user