...
1 package toml
2
3
4
5
6
7 type tomlType interface {
8 typeString() string
9 }
10
11
12 func typeEqual(t1, t2 tomlType) bool {
13 if t1 == nil || t2 == nil {
14 return false
15 }
16 return t1.typeString() == t2.typeString()
17 }
18
19 func typeIsTable(t tomlType) bool {
20 return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash)
21 }
22
23 type tomlBaseType string
24
25 func (btype tomlBaseType) typeString() string {
26 return string(btype)
27 }
28
29 func (btype tomlBaseType) String() string {
30 return btype.typeString()
31 }
32
33 var (
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"
42 )
43
44
45
46
47
48
49 func (p *parser) typeOfPrimitive(lexItem item) tomlType {
50 switch lexItem.typ {
51 case itemInteger:
52 return tomlInteger
53 case itemFloat:
54 return tomlFloat
55 case itemDatetime:
56 return tomlDatetime
57 case itemString:
58 return tomlString
59 case itemMultilineString:
60 return tomlString
61 case itemRawString:
62 return tomlString
63 case itemRawMultilineString:
64 return tomlString
65 case itemBool:
66 return tomlBool
67 }
68 p.bug("Cannot infer primitive type of lex item '%s'.", lexItem)
69 panic("unreachable")
70 }
71
View as plain text