Path: blob/main/vendor/github.com/pelletier/go-toml/v2/internal/tracker/key.go
2898 views
package tracker12import "github.com/pelletier/go-toml/v2/unstable"34// KeyTracker is a tracker that keeps track of the current Key as the AST is5// walked.6type KeyTracker struct {7k []string8}910// UpdateTable sets the state of the tracker with the AST table node.11func (t *KeyTracker) UpdateTable(node *unstable.Node) {12t.reset()13t.Push(node)14}1516// UpdateArrayTable sets the state of the tracker with the AST array table node.17func (t *KeyTracker) UpdateArrayTable(node *unstable.Node) {18t.reset()19t.Push(node)20}2122// Push the given key on the stack.23func (t *KeyTracker) Push(node *unstable.Node) {24it := node.Key()25for it.Next() {26t.k = append(t.k, string(it.Node().Data))27}28}2930// Pop key from stack.31func (t *KeyTracker) Pop(node *unstable.Node) {32it := node.Key()33for it.Next() {34t.k = t.k[:len(t.k)-1]35}36}3738// Key returns the current key39func (t *KeyTracker) Key() []string {40k := make([]string, len(t.k))41copy(k, t.k)42return k43}4445func (t *KeyTracker) reset() {46t.k = t.k[:0]47}484950