packages feed

yamlparse-applicative 0.2.0.0 → 0.2.0.1

raw patch · 4 files changed

+43/−11 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Path Path.Posix.Abs Path.Posix.Dir)
- YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Path Path.Posix.Abs Path.Posix.File)
- YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Path Path.Posix.Rel Path.Posix.Dir)
- YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Path Path.Posix.Rel Path.Posix.File)
- YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema v => YamlParse.Applicative.Class.YamlSchema (Data.HashMap.Internal.HashMap Data.Text.Internal.Text v)
+ YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Posix.Path Path.Posix.Abs Path.Posix.Dir)
+ YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Posix.Path Path.Posix.Abs Path.Posix.File)
+ YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Posix.Path Path.Posix.Rel Path.Posix.Dir)
+ YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema (Path.Internal.Posix.Path Path.Posix.Rel Path.Posix.File)
+ YamlParse.Applicative.Class: instance YamlParse.Applicative.Class.YamlSchema v => YamlParse.Applicative.Class.YamlSchema (Data.Aeson.KeyMap.KeyMap v)
+ YamlParse.Applicative.Implement: fromText :: Text -> Key
+ YamlParse.Applicative.Implement: toText :: Key -> Text
- YamlParse.Applicative: [ParseMapKeys] :: Ord k => Parser Text k -> Parser Object (HashMap Text v) -> Parser Object (Map k v)
+ YamlParse.Applicative: [ParseMapKeys] :: Ord k => Parser Text k -> Parser Object (KeyMap v) -> Parser Object (Map k v)
- YamlParse.Applicative: [ParseMap] :: Parser Value v -> Parser Object (HashMap Text v)
+ YamlParse.Applicative: [ParseMap] :: Parser Value v -> Parser Object (KeyMap v)
- YamlParse.Applicative.Parser: [ParseMapKeys] :: Ord k => Parser Text k -> Parser Object (HashMap Text v) -> Parser Object (Map k v)
+ YamlParse.Applicative.Parser: [ParseMapKeys] :: Ord k => Parser Text k -> Parser Object (KeyMap v) -> Parser Object (Map k v)
- YamlParse.Applicative.Parser: [ParseMap] :: Parser Value v -> Parser Object (HashMap Text v)
+ YamlParse.Applicative.Parser: [ParseMap] :: Parser Value v -> Parser Object (KeyMap v)

Files

src/YamlParse/Applicative/Class.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-}@@ -7,7 +8,9 @@ module YamlParse.Applicative.Class where  import qualified Data.Aeson as JSON-import Data.HashMap.Strict (HashMap)+#if MIN_VERSION_aeson(2,0,0)+import Data.Aeson.KeyMap (KeyMap)+#endif import Data.Int import Data.List.NonEmpty as NE import Data.Map (Map)@@ -151,7 +154,7 @@ -- | There is no instance using YamlKeySchema k yet. -- Ideally there wouldn't be one for HashMap Text either because it's insecure, -- but the yaml arrives in a HashMap anyway so we might as well expose this.-instance YamlSchema v => YamlSchema (HashMap Text v) where+instance YamlSchema v => YamlSchema (KeyMap v) where   yamlSchema = ParseObject Nothing $ ParseMap yamlSchema  -- | A parser for a required field in an object at a given key
src/YamlParse/Applicative/Implement.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-}@@ -9,12 +10,31 @@  import Control.Applicative import qualified Data.Aeson.Types as Aeson+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as HM+import qualified Data.Aeson.Key as K+#else import qualified Data.HashMap.Strict as HM+#endif import qualified Data.Map as M import qualified Data.Text as T import qualified Data.Yaml as Yaml import YamlParse.Applicative.Parser +#if MIN_VERSION_aeson(2,0,0)+fromText :: T.Text -> K.Key+fromText = K.fromText++toText :: K.Key -> T.Text+toText = K.toText+#else+fromText :: T.Text -> T.Text+fromText = id++toText :: T.Text -> T.Text+toText = id+#endif+ -- | Use a 'Parser' to parse a value from Yaml. -- -- A 'Parser i o' corresponds exactly to a 'i -> Yaml.Parser o' and this function servers as evidence for that.@@ -65,21 +85,21 @@       ParseField key fp -> \o -> case fp of         FieldParserFmap f fp' -> f <$> go (ParseField key fp') o         FieldParserRequired p -> do-          v <- o Yaml..: key+          v <- o Yaml..: fromText key           go p v         FieldParserOptional p -> do-          case HM.lookup key o of+          case HM.lookup (fromText key) o of             Nothing -> pure Nothing             Just v -> Just <$> go p v         FieldParserOptionalWithDefault p d -> do-          case HM.lookup key o of+          case HM.lookup (fromText key) o of             Nothing -> pure d             Just v -> go p v       ParseList p -> mapM (go p)       ParseMap p -> HM.traverseWithKey $ \_ v -> go p v       ParseMapKeys p pm -> \val -> do         hm <- go pm val-        M.fromList <$> mapM (\(k, v) -> (,) <$> go p k <*> pure v) (HM.toList hm)+        M.fromList <$> mapM (\(k, v) -> (,) <$> go p (toText k) <*> pure v) (HM.toList hm)       ParsePure v -> const $ pure v       ParseAp pf p -> \v -> go pf v <*> go p v       ParseAlt ps -> \v -> case ps of
src/YamlParse/Applicative/Parser.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-}@@ -9,7 +10,11 @@ import Control.Monad import qualified Data.Aeson as JSON import qualified Data.ByteString.Lazy as LB-import Data.HashMap.Strict (HashMap)+#if MIN_VERSION_aeson(2,0,0)+import Data.Aeson.KeyMap (KeyMap)+#else+import qualified Data.HashMap.Strict as HM+#endif import Data.Map (Map) import Data.Scientific import Data.Text (Text)@@ -20,6 +25,10 @@ import qualified Data.Yaml as Yaml import Text.Read +#if !MIN_VERSION_aeson(2,0,0)+type KeyMap a = HM.HashMap T.Text a+#endif+ -- | A parser that takes values of type 'i' as input and parses them into values of type 'o' -- -- Note that there is no 'Monad' instance.@@ -77,13 +86,13 @@   -- | Parse a map where the keys are the yaml keys   ParseMap ::     Parser Yaml.Value v ->-    Parser Yaml.Object (HashMap Text v)+    Parser Yaml.Object (KeyMap v)   -- | Parse a map's keys via a given parser   ParseMapKeys ::     Ord k =>     Parser Text k ->-    Parser Yaml.Object (HashMap Text v) ->-    Parser Yaml.Object (Map k v) -- Once we get out of a HashMap, we'll want to stay out.+    Parser Yaml.Object (KeyMap v) ->+    Parser Yaml.Object (Map k v) -- Once we get out of a KeyMap, we'll want to stay out.    -- | Parse a field of an object   ParseField ::
yamlparse-applicative.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           yamlparse-applicative-version:        0.2.0.0+version:        0.2.0.1 synopsis:       Declaritive configuration parsing with free docs description:    See https://github.com/NorfairKing/yamlparse-applicative homepage:       https://github.com/NorfairKing/yamlparse-applicative#readme