go-toml/lexer/items.go

36 lines
991 B
Go

package lexer
import (
"fmt"
"github.com/mmakaay/toml/parser"
)
// Definition of all the lexer item types for the TOML lexer.
const (
ItemComment parser.ItemType = iota // An error occurred
ItemKey // Key of a key/value pair
ItemKeyDot // Dot for a dotted key
ItemAssignment // Value assignment coming up (=)
ItemString // A value of type string
)
// ParserItemToString returns a string representation of the
// parser.Item. This is used for unit testing purposes.
func ParserItemToString(i parser.Item) string {
switch i.Type {
case ItemComment:
return fmt.Sprintf("#(%s)", i.Value)
case ItemKey:
return fmt.Sprintf("[%s]", i.Value)
case ItemString:
return fmt.Sprintf("STR(%s)", i.Value)
case ItemKeyDot:
return "."
case ItemAssignment:
return "="
default:
panic(fmt.Sprintf("No string representation available for parser.Item id %d", i.Type))
}
}