yamlparse-applicative 0.1.0.4 → 0.2.0.0
raw patch · 6 files changed
+21/−23 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- YamlParse.Applicative.Parser: [FieldParserOptionalOrNullWithDefault] :: Show o => YamlParser o -> o -> FieldParser o
- YamlParse.Applicative.Parser: [FieldParserOptionalOrNull] :: YamlParser o -> FieldParser (Maybe o)
+ YamlParse.Applicative: [FieldParserFmap] :: (a -> b) -> FieldParser a -> FieldParser b
+ YamlParse.Applicative: [FieldParserOptionalWithDefault] :: Show o => YamlParser o -> o -> FieldParser o
+ YamlParse.Applicative: [FieldParserOptional] :: YamlParser o -> FieldParser (Maybe o)
+ YamlParse.Applicative: [FieldParserRequired] :: YamlParser o -> FieldParser o
+ YamlParse.Applicative: data FieldParser o
+ YamlParse.Applicative.Parser: [FieldParserFmap] :: (a -> b) -> FieldParser a -> FieldParser b
+ YamlParse.Applicative.Parser: instance GHC.Base.Functor YamlParse.Applicative.Parser.FieldParser
Files
- src/YamlParse/Applicative.hs +1/−0
- src/YamlParse/Applicative/Explain.hs +6/−3
- src/YamlParse/Applicative/Implement.hs +3/−12
- src/YamlParse/Applicative/Parser.hs +9/−6
- src/YamlParse/Applicative/Pretty.hs +1/−1
- yamlparse-applicative.cabal +1/−1
src/YamlParse/Applicative.hs view
@@ -102,6 +102,7 @@ YamlParser, ObjectParser, Parser (..),+ FieldParser (..), -- * Using a yaml schema
src/YamlParse/Applicative/Explain.hs view
@@ -28,7 +28,11 @@ | StringSchema (Maybe Text) | ArraySchema (Maybe Text) Schema | ObjectSchema (Maybe Text) Schema- | FieldSchema Text Bool (Maybe Text) Schema+ | FieldSchema+ Text -- Field name+ Bool -- Required+ (Maybe Text) -- Default value+ Schema -- Schema of the value | ListSchema Schema | MapSchema Schema | MapKeysSchema Schema@@ -60,11 +64,10 @@ ParseArray t p -> ArraySchema t $ go p ParseObject t p -> ObjectSchema t $ go p ParseField k fp -> case fp of+ FieldParserFmap _ fp' -> go $ ParseField k fp' FieldParserRequired p -> FieldSchema k True Nothing $ go p FieldParserOptional p -> FieldSchema k False Nothing $ go p FieldParserOptionalWithDefault p d -> FieldSchema k False (Just $ T.pack $ show d) $ go p- FieldParserOptionalOrNull p -> FieldSchema k False Nothing $ go p- FieldParserOptionalOrNullWithDefault p d -> FieldSchema k False (Just $ T.pack $ show d) $ go p ParseList p -> ListSchema $ go p ParseMap p -> MapSchema $ go p ParseMapKeys _ p -> MapKeysSchema $ go p
src/YamlParse/Applicative/Implement.hs view
@@ -63,25 +63,16 @@ Yaml.Object o -> go p o _ -> Aeson.typeMismatch "Object" v ParseField key fp -> \o -> case fp of+ FieldParserFmap f fp' -> f <$> go (ParseField key fp') o FieldParserRequired p -> do v <- o Yaml..: key go p v- FieldParserOptional p ->+ FieldParserOptional p -> do case HM.lookup key o of Nothing -> pure Nothing Just v -> Just <$> go p v- FieldParserOptionalWithDefault p d ->+ FieldParserOptionalWithDefault p d -> do case HM.lookup key o of- Nothing -> pure d- Just v -> go p v- FieldParserOptionalOrNull p -> do- mv <- o Yaml..:? key- case mv of- Nothing -> pure Nothing- Just v -> Just <$> go p v- FieldParserOptionalOrNullWithDefault p d -> do- mv <- o Yaml..:? key- case mv of Nothing -> pure d Just v -> go p v ParseList p -> mapM (go p)
src/YamlParse/Applicative/Parser.hs view
@@ -6,6 +6,7 @@ module YamlParse.Applicative.Parser where import Control.Applicative+import Control.Monad import qualified Data.Aeson as JSON import qualified Data.ByteString.Lazy as LB import Data.HashMap.Strict (HashMap)@@ -117,12 +118,14 @@ many = undefined data FieldParser o where+ FieldParserFmap :: (a -> b) -> FieldParser a -> FieldParser b FieldParserRequired :: YamlParser o -> FieldParser o FieldParserOptional :: YamlParser o -> FieldParser (Maybe o) FieldParserOptionalWithDefault :: Show o => YamlParser o -> o -> FieldParser o- FieldParserOptionalOrNull :: YamlParser o -> FieldParser (Maybe o)- FieldParserOptionalOrNullWithDefault :: Show o => YamlParser o -> o -> FieldParser o +instance Functor FieldParser where+ fmap = FieldParserFmap+ type YamlParser a = Parser Yaml.Value a type ObjectParser a = Parser Yaml.Object a@@ -255,23 +258,23 @@ -- | A parser for an optional field at a given key with a parser for what is found at that key optionalFieldWith :: Text -> Text -> YamlParser a -> ObjectParser (Maybe a)-optionalFieldWith k h func = ParseComment h $ ParseField k $ FieldParserOptionalOrNull func+optionalFieldWith k h func = ParseComment h $ ParseField k $ fmap join $ FieldParserOptional $ ParseMaybe func -- | A parser for an optional field at a given key with a parser for what is found at that key without a help text optionalFieldWith' :: Text -> YamlParser a -> ObjectParser (Maybe a)-optionalFieldWith' k func = ParseField k $ FieldParserOptionalOrNull func+optionalFieldWith' k func = ParseField k $ fmap join $ FieldParserOptional $ ParseMaybe func -- | A parser for an optional field at a given key with a default value and a parser for what is found at that key -- -- For the sake of documentation, the default value needs to be showable. optionalFieldWithDefaultWith :: Show a => Text -> a -> Text -> YamlParser a -> ObjectParser a-optionalFieldWithDefaultWith k d h func = ParseComment h $ ParseField k $ FieldParserOptionalOrNullWithDefault func d+optionalFieldWithDefaultWith k d h func = ParseComment h $ ParseField k $ FieldParserOptionalWithDefault func d -- | A parser for an optional field at a given key with a default value and a parser for what is found at that key without a help text -- -- For the sake of documentation, the default value needs to be showable. optionalFieldWithDefaultWith' :: Show a => Text -> a -> YamlParser a -> ObjectParser a-optionalFieldWithDefaultWith' k d func = ParseField k $ FieldParserOptionalOrNullWithDefault func d+optionalFieldWithDefaultWith' k d func = ParseField k $ FieldParserOptionalWithDefault func d -- | Make a parser that parses a value using the given extra parsing function --
src/YamlParse/Applicative/Pretty.hs view
@@ -120,7 +120,7 @@ AnySchema -> e "<any>" cs ExactSchema t -> e (pretty t) cs <+> fromJust (mkCommentsMDoc $ comment "(exact)") NullSchema -> e "null" cs- MaybeSchema s -> go (cs <> comment "or <null>") s+ MaybeSchema s -> go (comment "or <null>" <> cs) s BoolSchema t -> e "<boolean>" $ addMComment cs t NumberSchema t -> e "<number>" $ addMComment cs t StringSchema t -> e "<string>" $ addMComment cs t
yamlparse-applicative.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: yamlparse-applicative-version: 0.1.0.4+version: 0.2.0.0 synopsis: Declaritive configuration parsing with free docs description: See https://github.com/NorfairKing/yamlparse-applicative homepage: https://github.com/NorfairKing/yamlparse-applicative#readme