yamlparse-applicative 0.1.0.3 → 0.1.0.4
raw patch · 5 files changed
+26/−14 lines, 5 files
Files
- src/YamlParse/Applicative/Explain.hs +2/−0
- src/YamlParse/Applicative/IO.hs +7/−7
- src/YamlParse/Applicative/Implement.hs +10/−2
- src/YamlParse/Applicative/Parser.hs +6/−4
- yamlparse-applicative.cabal +1/−1
src/YamlParse/Applicative/Explain.hs view
@@ -63,6 +63,8 @@ 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/IO.hs view
@@ -51,11 +51,11 @@ [ "Reference: ", T.unpack $ prettyColourisedSchema $ explainParser (yamlSchema :: YamlParser a) ]- die- $ unlines- $ concat- [ failedMsgs,- triedFilesMsgs,- referenceMsgs- ]+ die $+ unlines $+ concat+ [ failedMsgs,+ triedFilesMsgs,+ referenceMsgs+ ] Right (ViaYamlSchema conf) -> pure $ Just conf
src/YamlParse/Applicative/Implement.hs view
@@ -66,12 +66,20 @@ FieldParserRequired p -> do v <- o Yaml..: key go p v- FieldParserOptional p -> do+ FieldParserOptional p ->+ case HM.lookup key o of+ Nothing -> pure Nothing+ Just v -> Just <$> go p v+ FieldParserOptionalWithDefault p d ->+ 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- FieldParserOptionalWithDefault p d -> do+ FieldParserOptionalOrNullWithDefault p d -> do mv <- o Yaml..:? key case mv of Nothing -> pure d
src/YamlParse/Applicative/Parser.hs view
@@ -120,6 +120,8 @@ 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 type YamlParser a = Parser Yaml.Value a @@ -253,23 +255,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 $ FieldParserOptional func+optionalFieldWith k h func = ParseComment h $ ParseField k $ FieldParserOptionalOrNull 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 $ FieldParserOptional func+optionalFieldWith' k func = ParseField k $ FieldParserOptionalOrNull 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 $ FieldParserOptionalWithDefault func d+optionalFieldWithDefaultWith k d h func = ParseComment h $ ParseField k $ FieldParserOptionalOrNullWithDefault 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 $ FieldParserOptionalWithDefault func d+optionalFieldWithDefaultWith' k d func = ParseField k $ FieldParserOptionalOrNullWithDefault func d -- | Make a parser that parses a value using the given extra parsing function --
yamlparse-applicative.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: yamlparse-applicative-version: 0.1.0.3+version: 0.1.0.4 synopsis: Declaritive configuration parsing with free docs description: See https://github.com/NorfairKing/yamlparse-applicative homepage: https://github.com/NorfairKing/yamlparse-applicative#readme