-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.go
More file actions
71 lines (51 loc) · 1.41 KB
/
Copy pathnode.go
File metadata and controls
71 lines (51 loc) · 1.41 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package libparser
import (
"fmt"
"strings"
)
type Node interface {
Context() NodeContext
String() string
}
// ————————————————————————————————
type NodeRoot struct {
Tomes map[string]*NodeDirective
NodeContext
NodeChildren
}
func (node *NodeRoot) Context() NodeContext {
return node.NodeContext
}
func (node *NodeRoot) String() string {
return node.NodeChildren.String()
}
// ————————————————————————————————
type NodeContext struct {
OffsetStart, OffsetEnd uint
}
func (context NodeContext) String() string {
return fmt.Sprintf("[%d-%d]", context.OffsetStart, context.OffsetEnd)
}
// ————————————————————————————————
type NodeChildren []Node
func (children NodeChildren) String() string {
if len(children) == 0 {
return " {}"
}
var builder strings.Builder
builder.WriteString(" {\n")
for _, arg := range children {
builder.WriteString(" " + arg.String() + "; ")
}
builder.WriteString("}")
return builder.String()
}
// ————————————————————————————————
type NodeArgs []Node
func (args NodeArgs) String() string {
var builder strings.Builder
for _, arg := range args {
builder.WriteString(" " + arg.String())
}
return builder.String()
}