module Toml.Type.Edsl
( TDSL
, mkToml
, empty
, (=:)
, table
, tableArray
) where
import Control.Monad.State (State, execState, modify, put)
import Data.List.NonEmpty (NonEmpty)
import Toml.Type.Key (Key)
import Toml.Type.TOML (TOML (..), insertKeyVal, insertTable, insertTableArrays)
import Toml.Type.Value (Value)
type TDSL = State TOML ()
mkToml :: TDSL -> TOML
mkToml :: TDSL -> TOML
mkToml TDSL
env = forall s a. State s a -> s -> s
execState TDSL
env forall a. Monoid a => a
mempty
{-# INLINE mkToml #-}
empty :: TDSL
empty :: TDSL
empty = forall s (m :: * -> *). MonadState s m => s -> m ()
put forall a. Monoid a => a
mempty
{-# INLINE empty #-}
(=:) :: Key -> Value a -> TDSL
=: :: forall (a :: TValue). Key -> Value a -> TDSL
(=:) Key
k Value a
v = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ forall (a :: TValue). Key -> Value a -> TOML -> TOML
insertKeyVal Key
k Value a
v
{-# INLINE (=:) #-}
table :: Key -> TDSL -> TDSL
table :: Key -> TDSL -> TDSL
table Key
k = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TOML -> TOML -> TOML
insertTable Key
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. TDSL -> TOML
mkToml
{-# INLINE table #-}
tableArray :: Key -> NonEmpty TDSL -> TDSL
tableArray :: Key -> NonEmpty TDSL -> TDSL
tableArray Key
k = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> NonEmpty TOML -> TOML -> TOML
insertTableArrays Key
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TDSL -> TOML
mkToml
{-# INLINE tableArray #-}