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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff