0 | module Text.TOML.Types
2 | import public Data.Time.Time
3 | import public Data.SortedMap
4 | import Derive.Prelude
6 | import Text.ParseError
9 | %language ElabReflection
16 | data TomlFloat : Type where
18 | Infty : Sign -> TomlFloat
19 | Float : Double -> TomlFloat
21 | %runElab derive "TomlFloat" [Eq,Show]
24 | Interpolation TomlFloat where
25 | interpolate NaN = "nan"
26 | interpolate (Infty Plus) = "inf"
27 | interpolate (Infty _) = "-inf"
28 | interpolate (Float dbl) = show dbl
36 | data TomlValue : Type where
38 | TStr : String -> TomlValue
41 | TBool : Bool -> TomlValue
44 | TTime : AnyTime -> TomlValue
47 | TInt : Integer -> TomlValue
50 | TDbl : TomlFloat -> TomlValue
53 | TArr : List TomlValue -> TomlValue
56 | TTbl : SortedMap String TomlValue -> TomlValue
58 | %name TomlValue
v,v1,v2
59 | %runElab derive "TomlValue" [Eq,Show]
65 | TomlTable = SortedMap String TomlValue
67 | %name TomlTable
t,t1,t2
74 | data KeyType = Plain | Quoted | Literal
76 | %runElab derive "KeyType" [Eq,Show]
86 | %runElab derive "Key" [Eq,Show]
89 | Interpolation Key where
90 | interpolate (KT k t _) = case t of
95 | Interpolation (List Key) where
96 | interpolate = fastConcat . intersperse "." . map interpolate
103 | data TomlParseError : Type where
104 | ValueExists : List Key -> TomlParseError
105 | InlineTableExists : List Key -> TomlParseError
106 | TableExists : List Key -> TomlParseError
107 | StaticArray : List Key -> TomlParseError
108 | TableArray : List Key -> TomlParseError
109 | InvalidLeapDay : LocalDate -> TomlParseError
111 | %runElab derive "TomlParseError" [Eq,Show]
114 | Interpolation TomlParseError where
115 | interpolate (ValueExists k) =
116 | "Trying to overwrite an existing value: \{k}"
117 | interpolate (InlineTableExists k) =
118 | "Trying to overwrite an existing inline table: \{k}"
119 | interpolate (TableExists k) =
120 | "Trying to overwrite an existing table: \{k}"
121 | interpolate (StaticArray k) =
122 | "Trying to overwrite an existing array: \{k}"
123 | interpolate (TableArray k) =
124 | "Trying to overwrite an existing array of tables: \{k}"
125 | interpolate (InvalidLeapDay d) = "Invalid leap day: \{d}"
130 | TErr = BoundedErr TomlParseError