3 // tomlType represents any Go type that corresponds to a TOML type.
4 // While the first draft of the TOML spec has a simplistic type system that
5 // probably doesn't need this level of sophistication, we seem to be militating
6 // toward adding real composite types.
7 type tomlType interface {
11 // typeEqual accepts any two types and returns true if they are equal.
12 func typeEqual(t1, t2 tomlType) bool {
13 if t1 == nil || t2 == nil {
16 return t1.typeString() == t2.typeString()
19 func typeIsHash(t tomlType) bool {
20 return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash)
23 type tomlBaseType string
25 func (btype tomlBaseType) typeString() string {
29 func (btype tomlBaseType) String() string {
30 return btype.typeString()
34 tomlInteger tomlBaseType = "Integer"
35 tomlFloat tomlBaseType = "Float"
36 tomlDatetime tomlBaseType = "Datetime"
37 tomlString tomlBaseType = "String"
38 tomlBool tomlBaseType = "Bool"
39 tomlArray tomlBaseType = "Array"
40 tomlHash tomlBaseType = "Hash"
41 tomlArrayHash tomlBaseType = "ArrayHash"
44 // typeOfPrimitive returns a tomlType of any primitive value in TOML.
45 // Primitive values are: Integer, Float, Datetime, String and Bool.
47 // Passing a lexer item other than the following will cause a BUG message
48 // to occur: itemString, itemBool, itemInteger, itemFloat, itemDatetime.
49 func (p *parser) typeOfPrimitive(lexItem item) tomlType {
59 case itemMultilineString:
63 case itemRawMultilineString:
68 p.bug("Cannot infer primitive type of lex item '%s'.", lexItem)
72 // typeOfArray returns a tomlType for an array given a list of types of its
75 // In the current spec, if an array is homogeneous, then its type is always
76 // "Array". If the array is not homogeneous, an error is generated.
77 func (p *parser) typeOfArray(types []tomlType) tomlType {
78 // Empty arrays are cool.
84 for _, t := range types[1:] {
85 if !typeEqual(theType, t) {
86 p.panicf("Array contains values of type '%s' and '%s', but "+
87 "arrays must be homogeneous.", theType, t)