package lexer import "fmt" // itemType represents the type of lexer items. type itemType int // Definition of all the lexer item types for the TOML lexer. const ( ItemError itemType = iota // An error occurred ItemEOF // End of input reached ItemComment // Comment string, starts with # till en of line ItemKey // Key of a key/value pair ItemKeyDot // Dot for a dotted key ItemString // A value of type string ) // Item represents a lexer item returned from the scanner. type Item struct { Type itemType //Type, e.g. itemNumber, itemSquareBracket Value string // Value, e.g. "10.42", "[" } // String returns a string representation of the lexer item. func (i Item) String() string { switch i.Type { case ItemEOF: return "EOF" case ItemError: return "Error: " + i.Value } return fmt.Sprintf("%s(%q)", i.Type, i.Value) } // String returns a string representation of the lexer item type. func (i itemType) String() string { switch i { case ItemError: return "Error" case ItemComment: return "Comment" case ItemKey: return "Key" case ItemKeyDot: return "KeyDot" case ItemString: return "String" default: return fmt.Sprintf("", i) } }