Copyright | (c) Eric Mertens, 2016 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
This module provides tools for producing structured configuration information out of configuration values.
- data ConfigParser a
- decodeConfig :: FromConfig a => Value -> Either Text a
- runConfigParser :: ConfigParser a -> Either Text a
- failure :: Text -> ConfigParser a
- extendLoc :: Text -> ConfigParser a -> ConfigParser a
- class FromConfig a where
- parseList :: (Value -> ConfigParser a) -> Value -> ConfigParser [a]
- data SectionParser a
- parseSections :: SectionParser a -> Value -> ConfigParser a
- sectionReq :: FromConfig a => Text -> SectionParser a
- sectionReqWith :: (Value -> ConfigParser a) -> Text -> SectionParser a
- sectionOpt :: FromConfig a => Text -> SectionParser (Maybe a)
- sectionOptWith :: (Value -> ConfigParser a) -> Text -> SectionParser (Maybe a)
- liftConfigParser :: ConfigParser a -> SectionParser a
- parseSectionsWith :: (a -> Text -> Value -> ConfigParser a) -> a -> Value -> ConfigParser a
Configuration parsing
data ConfigParser a Source #
Configuration parser tracking current location and for propagating error information.
decodeConfig :: FromConfig a => Value -> Either Text a Source #
Parse a Value
according to the method in the FromConfig
runConfigParser :: ConfigParser a -> Either Text a Source #
Run a top-level parser to either get the parsed value or an error message.
:: Text | error message |
-> ConfigParser a |
A parser that always fails with the given error message.
extendLoc :: Text -> ConfigParser a -> ConfigParser a Source #
Embed a parser into an extended location. This is used when parsing inside a section.
class FromConfig a where Source #
Class for types that have a well-known way to parse them.
parseConfig :: Value -> ConfigParser a Source #
Parse a value
FromConfig Integer Source # | Matches |
FromConfig Text Source # | Matches |
FromConfig Atom Source # | Matches |
FromConfig a => FromConfig [a] Source # | Matches |
Integral a => FromConfig (Ratio a) Source # | Matches |
Parser wrappers
parseList :: (Value -> ConfigParser a) -> Value -> ConfigParser [a] Source #
Section parsing
data SectionParser a Source #
Parser for consuming key-value pairs of sections.
parseSections :: SectionParser a -> Value -> ConfigParser a Source #
Run a SectionParser
given particular Value
. This will only
succeed when the value is a Sections
and the section parser consumes all
of the sections from that value.
sectionReq :: FromConfig a => Text -> SectionParser a Source #
Parse the value at the given section or fail.
sectionReqWith :: (Value -> ConfigParser a) -> Text -> SectionParser a Source #
Parse the value at the given section or fail.
sectionOpt :: FromConfig a => Text -> SectionParser (Maybe a) Source #
sectionOpt = sectionOptWith parseConfig
sectionOptWith :: (Value -> ConfigParser a) -> Text -> SectionParser (Maybe a) Source #
Parses the value stored at the given section with the given parser. Nothing is returned if the section is missing. Just is returned if the parse succeeds Error is raised if the section is present but the parse fails
liftConfigParser :: ConfigParser a -> SectionParser a Source #
Lift a ConfigParser
into a SectionParser
leaving the current
section information unmodified.
parseSectionsWith :: (a -> Text -> Value -> ConfigParser a) -> a -> Value -> ConfigParser a Source #