vendor/github.com/pelletier/go-toml/v2/internal/tracker/key.go
changeset 265 05c40b36d3b2
parent 260 445e01aede7e
equal deleted inserted replaced
264:8f478162d991 265:05c40b36d3b2
     1 package tracker
     1 package tracker
     2 
     2 
     3 import (
     3 import "github.com/pelletier/go-toml/v2/unstable"
     4 	"github.com/pelletier/go-toml/v2/internal/ast"
       
     5 )
       
     6 
     4 
     7 // KeyTracker is a tracker that keeps track of the current Key as the AST is
     5 // KeyTracker is a tracker that keeps track of the current Key as the AST is
     8 // walked.
     6 // walked.
     9 type KeyTracker struct {
     7 type KeyTracker struct {
    10 	k []string
     8 	k []string
    11 }
     9 }
    12 
    10 
    13 // UpdateTable sets the state of the tracker with the AST table node.
    11 // UpdateTable sets the state of the tracker with the AST table node.
    14 func (t *KeyTracker) UpdateTable(node *ast.Node) {
    12 func (t *KeyTracker) UpdateTable(node *unstable.Node) {
    15 	t.reset()
    13 	t.reset()
    16 	t.Push(node)
    14 	t.Push(node)
    17 }
    15 }
    18 
    16 
    19 // UpdateArrayTable sets the state of the tracker with the AST array table node.
    17 // UpdateArrayTable sets the state of the tracker with the AST array table node.
    20 func (t *KeyTracker) UpdateArrayTable(node *ast.Node) {
    18 func (t *KeyTracker) UpdateArrayTable(node *unstable.Node) {
    21 	t.reset()
    19 	t.reset()
    22 	t.Push(node)
    20 	t.Push(node)
    23 }
    21 }
    24 
    22 
    25 // Push the given key on the stack.
    23 // Push the given key on the stack.
    26 func (t *KeyTracker) Push(node *ast.Node) {
    24 func (t *KeyTracker) Push(node *unstable.Node) {
    27 	it := node.Key()
    25 	it := node.Key()
    28 	for it.Next() {
    26 	for it.Next() {
    29 		t.k = append(t.k, string(it.Node().Data))
    27 		t.k = append(t.k, string(it.Node().Data))
    30 	}
    28 	}
    31 }
    29 }
    32 
    30 
    33 // Pop key from stack.
    31 // Pop key from stack.
    34 func (t *KeyTracker) Pop(node *ast.Node) {
    32 func (t *KeyTracker) Pop(node *unstable.Node) {
    35 	it := node.Key()
    33 	it := node.Key()
    36 	for it.Next() {
    34 	for it.Next() {
    37 		t.k = t.k[:len(t.k)-1]
    35 		t.k = t.k[:len(t.k)-1]
    38 	}
    36 	}
    39 }
    37 }