salak-toml 0.2.9 → 0.2.9.1
raw patch · 3 files changed
+27/−12 lines, 3 filesdep ~salakPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: salak
API changes (from Hackage documentation)
Files
- salak-toml.cabal +3/−3
- src/Salak/Toml.hs +22/−9
- test/Spec.hs +2/−0
salak-toml.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: salak-toml-version: 0.2.9+version: 0.2.9.1 license: BSD3 license-file: LICENSE copyright: (c) 2018 Daniel YU@@ -25,7 +25,7 @@ build-depends: base >=4.10 && <5, mtl >=2.2.2 && <2.3,- salak ==0.2.9,+ salak ==0.2.9.*, text >=1.2.3.1 && <1.3, time >=1.8.0.2 && <1.9, tomland ==1.0.*,@@ -45,7 +45,7 @@ base >=4.10 && <5, hspec ==2.*, mtl >=2.2.2 && <2.3,- salak ==0.2.9,+ salak ==0.2.9.*, text >=1.2.3.1 && <1.3, time >=1.8.0.2 && <1.9, tomland ==1.0.*,
src/Salak/Toml.hs view
@@ -1,6 +1,16 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TupleSections #-}+-- |+-- Module: Salak.Toml+-- Copyright: (c) 2019 Daniel YU+-- License: BSD3+-- Maintainer: leptonyu@gmail.com+-- Stability: experimental+-- Portability: portable+--+-- Toml support for "Salak".+-- module Salak.Toml( TOML(..) , loadToml@@ -18,6 +28,7 @@ import Toml hiding (TOML) import qualified Toml as T +-- | TOML notation for `loadToml` data TOML = TOML instance HasLoad TOML where@@ -30,16 +41,17 @@ toS = SStr . unPiece loadTOML :: Monad m => T.TOML -> Priority -> Source -> WriterT [String] m Source-loadTOML T.TOML{..} i = foldPairs i tomlPairs- >=> foldTables i tomlTables- >=> foldTableArrays i tomlTableArrays-foldToml go m s = HM.foldlWithKey' (\ms k v -> ms >>= go k v) (return s) m-foldPairs i = foldToml (\k -> updateSources (toSs k) . insertAnyValue i)-foldTables i = foldToml (const go)+loadTOML T.TOML{..} i = foldPairs tomlPairs+ >=> foldTables tomlTables+ >=> foldTableArrays tomlTableArrays where- go (Leaf k toml) = updateSources (toSs k) (loadTOML toml i)- go (Branch k v' tomap) = updateSources (toSs k) (maybe return (`loadTOML` i) v' >=> foldTables i tomap)-foldTableArrays i = foldToml (\k v -> updateSources (toSs k) (foldArray (N.toList v) (`loadTOML` i)))+ foldToml go m s = HM.foldlWithKey' (\ms k v -> ms >>= go k v) (return s) m+ foldPairs = foldToml (\k -> updateSources (toSs k) . insertAnyValue i)+ foldTables = foldToml (const go)+ where+ go (Leaf k toml) = updateSources (toSs k) (loadTOML toml i)+ go (Branch k v' tomap) = updateSources (toSs k) (maybe return (`loadTOML` i) v' >=> foldTables tomap)+ foldTableArrays = foldToml (\k v -> updateSources (toSs k) (foldArray (N.toList v) (`loadTOML` i))) insertAnyValue :: Monad m => Priority -> AnyValue -> Source -> m Source insertAnyValue i (AnyValue (Array b)) = foldArray b (insertAnyValue i . AnyValue)@@ -55,6 +67,7 @@ foldArray :: Monad m => [a] -> (a -> Source -> m Source) -> Source -> m Source foldArray a g s = foldM (\s' (ix,x) -> updateSource (SNum ix) (g x) s') s $ zip [0..] a +-- | Load Toml loadToml :: MonadIO m => FilePath -> LoadSalakT m () loadToml file = loadFile file $ \i s -> do re <- liftIO (parse <$> IO.readFile file)
test/Spec.hs view
@@ -15,6 +15,7 @@ import Test.Hspec import Test.QuickCheck +main :: IO () main = hspec spec spec :: Spec@@ -50,6 +51,7 @@ instance FromProp Conf +tomlProperty :: SpecWith () tomlProperty = do context "load toml" $ do it "salak.toml" $ do