...
1 package tracker
2
3 import "github.com/pelletier/go-toml/v2/unstable"
4
5
6
7 type KeyTracker struct {
8 k []string
9 }
10
11
12 func (t *KeyTracker) UpdateTable(node *unstable.Node) {
13 t.reset()
14 t.Push(node)
15 }
16
17
18 func (t *KeyTracker) UpdateArrayTable(node *unstable.Node) {
19 t.reset()
20 t.Push(node)
21 }
22
23
24 func (t *KeyTracker) Push(node *unstable.Node) {
25 it := node.Key()
26 for it.Next() {
27 t.k = append(t.k, string(it.Node().Data))
28 }
29 }
30
31
32 func (t *KeyTracker) Pop(node *unstable.Node) {
33 it := node.Key()
34 for it.Next() {
35 t.k = t.k[:len(t.k)-1]
36 }
37 }
38
39
40 func (t *KeyTracker) Key() []string {
41 k := make([]string, len(t.k))
42 copy(k, t.k)
43 return k
44 }
45
46 func (t *KeyTracker) reset() {
47 t.k = t.k[:0]
48 }
49
View as plain text