change SimpleNode

This commit is contained in:
z7zmey 2017-12-04 23:24:12 +02:00
parent e31ec50c78
commit e7ba0ca435
7 changed files with 570 additions and 570 deletions

View File

@ -13,58 +13,58 @@ type Node interface {
Attribute(key string, value string) Node
}
type simpleNode struct {
name string
children []Node
attributes map[string]string
type SimpleNode struct {
Name string
Children []Node
Attributes map[string]string
}
type tokenNode struct {
*simpleNode
*SimpleNode
token token.Token
}
func (n simpleNode) String() string {
func (n SimpleNode) String() string {
buf := new(bytes.Buffer)
n.Print(buf, " ")
return buf.String()
}
func (n simpleNode) Print(out io.Writer, indent string) {
if len(n.attributes) > 0 {
fmt.Fprintf(out, "\n%v%v %s", indent, n.name, n.attributes)
func (n SimpleNode) Print(out io.Writer, indent string) {
if len(n.Attributes) > 0 {
fmt.Fprintf(out, "\n%v%v %s", indent, n.Name, n.Attributes)
} else {
fmt.Fprintf(out, "\n%v%v", indent, n.name)
fmt.Fprintf(out, "\n%v%v", indent, n.Name)
}
for _, nn := range n.children {
for _, nn := range n.Children {
nn.Print(out, indent+" ")
}
}
func SimpleNode(name string) Node {
return simpleNode{name: name, attributes: make(map[string]string)}
func NewSimpleNode(name string) Node {
return SimpleNode{Name: name, Attributes: make(map[string]string)}
}
func TokenNode(name string, t token.Token) Node {
return tokenNode{
&simpleNode{name: name, attributes: make(map[string]string)},
&SimpleNode{Name: name, Attributes: make(map[string]string)},
t,
}
}
func (n tokenNode) 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 {
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+" ")
}
}
func (n simpleNode) Append(nn ...Node) Node {
n.children = append(n.children, nn...)
func (n SimpleNode) Append(nn ...Node) Node {
n.Children = append(n.Children, nn...)
return n
}
func (n simpleNode) Attribute(key string, value string) Node {
n.attributes[key] = value
func (n SimpleNode) Attribute(key string, value string) Node {
n.Attributes[key] = value
return n
}

View File

@ -8,7 +8,7 @@ import (
type NodeExprShellExec struct {
*simpleNode
*SimpleNode
startToken token.Token
endToken token.Token
parts []Node
@ -17,7 +17,7 @@ type NodeExprShellExec struct {
func NewNodeExprShellExec(startToken token.Token, parts []Node, endToken token.Token) Node {
return NodeExprShellExec{
&simpleNode{name: "NodeExprShellExec", attributes: make(map[string]string)},
&SimpleNode{Name: "NodeExprShellExec", Attributes: make(map[string]string)},
startToken,
endToken,
parts,
@ -25,7 +25,7 @@ func NewNodeExprShellExec(startToken token.Token, parts []Node, endToken token.T
}
func (n NodeExprShellExec) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.name, n.startToken.StartLine, n.endToken.EndLine)
fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.startToken.StartLine, n.endToken.EndLine)
fmt.Fprintf(out, "\n%vparts:", indent+" ",)
for _, nn := range n.parts {
nn.Print(out, indent+" ")

View File

@ -8,7 +8,7 @@ import (
type NodeScalarEncapsed struct {
*simpleNode
*SimpleNode
startToken token.Token
endToken token.Token
parts []Node
@ -17,7 +17,7 @@ type NodeScalarEncapsed struct {
func NewNodeScalarEncapsed(startToken token.Token, parts []Node, endToken token.Token) Node {
return NodeScalarEncapsed{
&simpleNode{name: "NodeScalarEncapsed", attributes: make(map[string]string)},
&SimpleNode{Name: "NodeScalarEncapsed", Attributes: make(map[string]string)},
startToken,
endToken,
parts,
@ -25,7 +25,7 @@ func NewNodeScalarEncapsed(startToken token.Token, parts []Node, endToken token.
}
func (n NodeScalarEncapsed) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.name, n.startToken.StartLine, n.endToken.EndLine)
fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.startToken.StartLine, n.endToken.EndLine)
fmt.Fprintf(out, "\n%vparts:", indent+" ",)
for _, nn := range n.parts {
nn.Print(out, indent+" ")

View File

@ -7,21 +7,21 @@ import (
)
type NodeScalarEncapsedStringPart struct {
*simpleNode
*SimpleNode
token token.Token
}
func NewNodeScalarEncapsedStringPart(t token.Token) Node {
return NodeScalarEncapsedStringPart{
&simpleNode{name: "NodeScalarEncapsedStringPart", attributes: make(map[string]string)},
&SimpleNode{Name: "NodeScalarEncapsedStringPart", Attributes: make(map[string]string)},
t,
}
}
func (n NodeScalarEncapsedStringPart) 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 {
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+" ")
}
}

View File

@ -8,21 +8,21 @@ import (
type NodeScalarString struct {
*simpleNode
*SimpleNode
token token.Token
}
func NewNodeScalarString(t token.Token) Node {
return NodeScalarString{
&simpleNode{name: "NodeScalarString", attributes: make(map[string]string)},
&SimpleNode{Name: "NodeScalarString", Attributes: make(map[string]string)},
t,
}
}
func (n NodeScalarString) 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 {
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+" ")
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff