name nodes

This commit is contained in:
z7zmey
2017-12-05 23:36:28 +02:00
parent 347cb09386
commit 829326f8f7
8 changed files with 753 additions and 661 deletions

View File

@@ -0,0 +1,18 @@
package name
import (
"github.com/z7zmey/php-parser/node"
)
type FullyQualified struct {
Name
}
func NewFullyQualified(parts []node.Node) node.Node {
return FullyQualified{
Name{
node.SimpleNode{Name: "FullyQualifiedName", Attributes: make(map[string]string)},
parts,
},
}
}

27
node/name/name.go Normal file
View File

@@ -0,0 +1,27 @@
package name
import (
"fmt"
"github.com/z7zmey/php-parser/node"
"io"
)
type Name struct {
node.SimpleNode
parts []node.Node
}
func NewName(parts []node.Node) node.Node {
return Name{
node.SimpleNode{Name: "Name", Attributes: make(map[string]string)},
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+" ")
}
}

27
node/name/name_part.go Normal file
View File

@@ -0,0 +1,27 @@
package name
import (
"fmt"
"github.com/z7zmey/php-parser/token"
"github.com/z7zmey/php-parser/node"
"io"
)
type NamePart struct {
node.SimpleNode
token token.Token
}
func NewNamePart(token token.Token) node.Node {
return NamePart{
node.SimpleNode{Name: "NamePart", Attributes: make(map[string]string)},
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+" ")
}
}

19
node/name/relative.go Normal file
View File

@@ -0,0 +1,19 @@
package name
import (
"github.com/z7zmey/php-parser/node"
)
type Relative struct {
Name
}
func NewRelative(parts []node.Node) node.Node {
return Relative{
Name{
node.SimpleNode{Name: "RelativeName", Attributes: make(map[string]string)},
parts,
},
}
}