remove SimpleNode

This commit is contained in:
vadim
2017-12-27 19:55:58 +02:00
parent e83ab79344
commit 32a285b437
159 changed files with 1195 additions and 622 deletions

View File

@@ -5,14 +5,18 @@ import (
)
type FullyQualified struct {
Name
NameNode
}
func NewFullyQualified(parts []node.Node) node.Node {
return FullyQualified{
Name{
node.SimpleNode{Name: "FullyQualifiedName", Attributes: make(map[string]string)},
NameNode{
"FullyQualifiedName",
parts,
},
}
}
func (n FullyQualified) Name() string {
return "FullyQualified"
}

View File

@@ -2,26 +2,34 @@ package name
import (
"fmt"
"github.com/z7zmey/php-parser/node"
"io"
"github.com/z7zmey/php-parser/node"
)
type Name struct {
node.SimpleNode
func (n NameNode) Name() string {
return "Name"
}
type NameNode struct {
name string
parts []node.Node
}
func NewName(parts []node.Node) node.Node {
return Name{
node.SimpleNode{Name: "Name", Attributes: make(map[string]string)},
return NameNode{
"Name",
parts,
}
}
func (n Name) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v", indent, n.Name)
fmt.Fprintf(out, "\n%vparts:", indent+" ",)
for _, nn := range n.parts {
nn.Print(out, indent+" ")
func (n NameNode) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v", indent, n.name)
if n.parts != nil {
fmt.Fprintf(out, "\n%vparts:", indent+" ")
for _, nn := range n.parts {
nn.Print(out, indent+" ")
}
}
}
}

View File

@@ -2,26 +2,28 @@ package name
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
func(n NamePart) Name() string {
return "NamePart"
}
type NamePart struct {
node.SimpleNode
name string
token token.Token
}
func NewNamePart(token token.Token) node.Node {
return NamePart{
node.SimpleNode{Name: "NamePart", Attributes: make(map[string]string)},
"NamePart",
token,
}
}
func (n NamePart) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
for _, nn := range n.Children {
nn.Print(out, indent+" ")
}
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.name, n.token.StartLine, n.token.EndLine, n.token.Value)
}

View File

@@ -5,15 +5,18 @@ import (
)
type Relative struct {
Name
NameNode
}
func NewRelative(parts []node.Node) node.Node {
return Relative{
Name{
node.SimpleNode{Name: "RelativeName", Attributes: make(map[string]string)},
NameNode{
"RelativeName",
parts,
},
}
}
func (n Relative) Name() string {
return "Relative"
}