packages feed

salak-yaml 0.2.8 → 0.2.9

raw patch · 5 files changed

+70/−54 lines, 5 filesdep +conduitdep +libyamldep −aesondep −unordered-containersdep −vectordep ~salakPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: conduit, libyaml

Dependencies removed: aeson, unordered-containers, vector, yaml

Dependency ranges changed: salak

API changes (from Hackage documentation)

- Salak.Load.Yaml: YAML :: YAML
- Salak.Load.Yaml: data YAML
- Salak.Load.Yaml: instance Salak.HasLoad Salak.Load.Yaml.YAML
- Salak.Load.Yaml: loadJSON :: Reload -> Value -> SourcePack -> SourcePack
- Salak.Load.Yaml: loadYaml :: MonadIO m => FilePath -> SourcePackT m ()
+ Salak.Yaml: YAML :: YAML
+ Salak.Yaml: data YAML
+ Salak.Yaml: instance Salak.HasLoad Salak.Yaml.YAML
+ Salak.Yaml: loadYaml :: MonadIO m => FilePath -> LoadSalakT m ()

Files

salak-yaml.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: salak-yaml-version: 0.2.8+version: 0.2.9 license: BSD3 license-file: LICENSE copyright: (c) 2018 Daniel YU@@ -16,36 +16,35 @@  library     exposed-modules:-        Salak.Load.Yaml+        Salak.Yaml     hs-source-dirs: src     other-modules:         Paths_salak_yaml     default-language: Haskell2010+    ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures     build-depends:-        aeson >=1.4.2.0 && <1.5,         base >=4.10 && <5,+        conduit >=1.3.1.1 && <1.4,+        libyaml >=0.1.1.0 && <0.2,         mtl >=2.2.2 && <2.3,-        salak ==0.2.8,-        unordered-containers >=0.2.9.0 && <0.3,-        vector >=0.12.0.2 && <0.13,-        yaml >=0.11.0.0 && <0.12+        salak ==0.2.9,+        text >=1.2.3.1 && <1.3  test-suite spec     type: exitcode-stdio-1.0     main-is: Spec.hs     hs-source-dirs: test src     other-modules:-        Salak.Load.Yaml+        Salak.Yaml         Paths_salak_yaml     default-language: Haskell2010+    ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures     build-depends:         QuickCheck >=2.12.6.1 && <2.14,-        aeson >=1.4.2.0 && <1.5,         base >=4.10 && <5,+        conduit >=1.3.1.1 && <1.4,         hspec ==2.*,+        libyaml >=0.1.1.0 && <0.2,         mtl >=2.2.2 && <2.3,-        salak ==0.2.8,-        text >=1.2.3.1 && <1.3,-        unordered-containers >=0.2.9.0 && <0.3,-        vector >=0.12.0.2 && <0.13,-        yaml >=0.11.0.0 && <0.12+        salak ==0.2.9,+        text >=1.2.3.1 && <1.3
− src/Salak/Load/Yaml.hs
@@ -1,36 +0,0 @@-{-# LANGUAGE TupleSections #-}-module Salak.Load.Yaml where--import           Control.Monad.IO.Class (MonadIO, liftIO)-import           Control.Monad.State-import qualified Data.Aeson             as A-import qualified Data.HashMap.Strict    as HM-import qualified Data.Vector            as V-import qualified Data.Yaml              as Y-import           Salak-import           Salak.Load--loadJSON :: Reload -> A.Value -> SourcePack -> SourcePack-loadJSON name v sp = loadFile name sp $ go v-  where-    go (A.Object m) i s = foldl (g2 i) (return s) $ g3 <$> HM.toList m-    go (A.Array  m) i s = foldl (g2 i) (return s) $ zip (g4 <$> [0..]) $ V.toList m-    go (A.String m) i s = return $ insertSource (VStr  i m) s-    go (A.Number m) i s = return $ insertSource (VNum  i m) s-    go (A.Bool   m) i s = return $ insertSource (VBool i m) s-    go A.Null       _ s = return s-    g2 i ms (k, v') = ms >>= updateSources k (go v' i)-    g3 (k,x) = (simpleSelectors k, x)-    g4 i     = [SNum i]--loadYaml :: MonadIO m => FilePath -> SourcePackT m ()-loadYaml file = do-  v <- liftIO $ Y.decodeFileEither file-  modify $ \sp -> case v of-    Left  e -> addErr' (show e) sp-    Right a -> loadJSON (defReload file $ loadYaml file) a sp--data YAML = YAML--instance HasLoad YAML where-  loaders _ = (, loadYaml) <$> ["yaml", "yml"]
+ src/Salak/Yaml.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE RecordWildCards  #-}+{-# LANGUAGE TupleSections    #-}+module Salak.Yaml(+    YAML(..)+  , loadYaml+  ) where++import           Control.Exception      (throwIO)+import           Control.Monad.IO.Class (MonadIO, liftIO)+import           Data.Conduit           hiding (Source)+import           Data.Text.Encoding     (decodeUtf8)+import           Salak+import           Salak.Load+import           Text.Libyaml++loadYaml :: MonadIO m => FilePath -> LoadSalakT m ()+loadYaml file = loadFile file $ \i s -> liftIO $ runConduitRes (decodeFileMarked file .| loadYAML i s)++data YAML = YAML++instance HasLoad YAML where+  loaders _ = (, loadYaml) <$> ["yaml", "yml"]++loadYAML :: MonadIO m => Priority -> Source -> ConduitM MarkedEvent o m Source+loadYAML i s = await >>= maybe (return s) go+  where+    go (MarkedEvent (EventScalar a _ _ _) _ _) = return (insertSource (newVStr (decodeUtf8 a) i) s)+    go (MarkedEvent EventSequenceStart{}  _ _) = goSeq 0 s+    go (MarkedEvent EventSequenceEnd      _ _) = return emptySource+    go (MarkedEvent EventMappingStart{}  _ ee) = goMap ee s+    go _ = loadYAML i s+    goSeq j s1 = do+      s' <- loadYAML i emptySource+      if nullSource s'+        then return s1+        else updateSource (SNum j) (\_ -> return s') s1 >>= goSeq (j+1)+    goMap ee s1 = do+      v <- await+      case v of+        Nothing -> ge ee "suppose to have data"+        Just (MarkedEvent (EventScalar a _ _ _) _ ee') ->+          updateSources (simpleSelectors $ decodeUtf8 a) (loadYAML i) s1 >>= goMap ee'+        Just (MarkedEvent EventMappingEnd _ _) -> return s1+        Just e -> ge (yamlStartMark e) "suppose scalar and mapping end"+    ge YamlMark{..} e = liftIO $ throwIO $ YamlException $ "(" ++ show yamlLine ++ "," ++ show yamlColumn ++ ")" ++ e++++++
test/Spec.hs view
@@ -7,13 +7,11 @@ module Main where  import           Control.Monad.Reader-import           Control.Monad.Writer-import           Data.Either import           Data.List            (intercalate)-import           Data.Text            (Text, pack, unpack)+import           Data.Text            (Text, pack) import           GHC.Generics import           Salak-import           Salak.Load.Yaml+import           Salak.Yaml import           Test.Hspec import           Test.QuickCheck 
test/salak.yml view
@@ -5,6 +5,9 @@   - c hello:   world+a:+  b:+    c  me.icymint.conf:   name: daniel