Path: blob/main/vendor/github.com/pelletier/go-toml/v2/strict.go
3497 views
package toml12import (3"github.com/pelletier/go-toml/v2/internal/danger"4"github.com/pelletier/go-toml/v2/internal/tracker"5"github.com/pelletier/go-toml/v2/unstable"6)78type strict struct {9Enabled bool1011// Tracks the current key being processed.12key tracker.KeyTracker1314missing []unstable.ParserError15}1617func (s *strict) EnterTable(node *unstable.Node) {18if !s.Enabled {19return20}2122s.key.UpdateTable(node)23}2425func (s *strict) EnterArrayTable(node *unstable.Node) {26if !s.Enabled {27return28}2930s.key.UpdateArrayTable(node)31}3233func (s *strict) EnterKeyValue(node *unstable.Node) {34if !s.Enabled {35return36}3738s.key.Push(node)39}4041func (s *strict) ExitKeyValue(node *unstable.Node) {42if !s.Enabled {43return44}4546s.key.Pop(node)47}4849func (s *strict) MissingTable(node *unstable.Node) {50if !s.Enabled {51return52}5354s.missing = append(s.missing, unstable.ParserError{55Highlight: keyLocation(node),56Message: "missing table",57Key: s.key.Key(),58})59}6061func (s *strict) MissingField(node *unstable.Node) {62if !s.Enabled {63return64}6566s.missing = append(s.missing, unstable.ParserError{67Highlight: keyLocation(node),68Message: "missing field",69Key: s.key.Key(),70})71}7273func (s *strict) Error(doc []byte) error {74if !s.Enabled || len(s.missing) == 0 {75return nil76}7778err := &StrictMissingError{79Errors: make([]DecodeError, 0, len(s.missing)),80}8182for _, derr := range s.missing {83derr := derr84err.Errors = append(err.Errors, *wrapDecodeError(doc, &derr))85}8687return err88}8990func keyLocation(node *unstable.Node) []byte {91k := node.Key()9293hasOne := k.Next()94if !hasOne {95panic("should not be called with empty key")96}9798start := k.Node().Data99end := k.Node().Data100101for k.Next() {102end = k.Node().Data103}104105return danger.BytesRange(start, end)106}107108109