-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.go
56 lines (46 loc) · 1.09 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package amotoen
import (
"bytes"
)
type node struct {
content Stringer
source State
children []Tree
}
func (n *node) Process() interface{} {
return nil // n.source.processor(n)
}
func (n *node) Source() State {
return n.source
}
func (n *node) Append(t Tree) Tree {
// It's expected that when a Tree is provided to append
// ... it is finished - it's ready to be post-processed...
// We can access the post-processor through the state which is in the
// ... source attribute
n.children = append(n.children, t)
return t
}
func (n *node) String() string {
var result bytes.Buffer
if n.content != nil {
result.WriteString(n.content.String())
}
if len(n.children) > 0 {
result.WriteString("[")
}
for i, c := range n.children {
result.WriteString(c.String())
if i < len(n.children)-1 {
result.WriteString(",")
}
}
if len(n.children) > 0 {
result.WriteString("]")
}
return result.String()
}
type stringContent string
func (s stringContent) String() string { return string(s) }
type runeContent rune
func (r runeContent) String() string { return "'" + string(r) + "'" }