module Toml.Type.TOML
( TOML (..)
, insertKeyVal
, insertTable
) where
import Data.HashMap.Strict (HashMap)
import Data.Semigroup (Semigroup (..))
import Toml.PrefixTree (Key (..), PrefixMap)
import Toml.Type.AnyValue (AnyValue (..))
import Toml.Type.Value (Value)
import qualified Data.HashMap.Strict as HashMap
import qualified Toml.PrefixTree as Prefix
data TOML = TOML
{ tomlPairs :: HashMap Key AnyValue
, tomlTables :: PrefixMap TOML
} deriving (Show, Eq)
instance Semigroup TOML where
(TOML pairsA tablesA) <> (TOML pairsB tablesB) = TOML
(pairsA <> pairsB)
(HashMap.unionWith (<>) tablesA tablesB)
instance Monoid TOML where
mappend = (<>)
mempty = TOML mempty mempty
insertKeyVal :: Key -> Value a -> TOML -> TOML
insertKeyVal k v toml = toml {tomlPairs = HashMap.insert k (AnyValue v) (tomlPairs toml)}
insertTable :: Key -> TOML -> TOML -> TOML
insertTable k inToml toml = toml
{ tomlTables = Prefix.insert k inToml (tomlTables toml)
}