cfg-0.0.2.2: Type directed application configuration parsing and accessors
Copyright© Jonathan Lorimer 2023
LicenseMIT
Maintainerjonathanlorimer@pm.me
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

Cfg.Parser.Config

Description

This module contains the generic machinery for building parsers from the structure of a type. The majority of the work here is threading a ValueParser through the KeyTree structure until a Pure value is hit, and then dispatching the correct parser.

Since: 0.0.2.0

Synopsis

Default Parser Function

defaultParseConfig :: (Generic a, GConfigParser (Rep a)) => ConfigOptions -> KeyTree Text Text -> Either ConfigParseError a Source #

This function is the workhorse of the generic machinery, however the user should never have to invoke it directly. Instead, one of the newtypes from Config should call into this function in the definition of a ConfigParser instance. The deriving via type should pull out the ConfigOptions from type level information.

Since: 0.0.1.0

Generic Machinery

class GConfigParser (f :: Type -> Type) where Source #

This class is the generic version of ConfigParser. It recurses on the generic structure of a type, building up a return type for the parser.

Since: 0.0.2.0

Instances

Instances details
(GConfigParser a, GConfigParser b) => GConfigParser (a :*: b) Source #

This is the product case, we just distribute the parsers over the different product fields.

Notably, there is no sum type case. We could potentially add that in the future, allowing users to specify different cases of configuration. But right now that seems like it would be more confusing than helpful, so we just give a type error by eliding the instance.

Since: 0.0.2.0

Instance details

Defined in Cfg.Parser.Config

ConfigParser a => GConfigParser (K1 R a :: Type -> Type) Source #

This is the "base case", since GHC.Generics don't recurse the generic represetation multiple levels, a is just a plain type. Therefore we call parseConfig on it. a may be another nested record, in which case gParseConfig will probably get called again, but for the generic representation of a sub-tree. Or it will find the default instance for ConfigParser (indicating that we have reached a leaf) and dispatch to a value parser through parseConfig.

Since: 0.0.2.0

Instance details

Defined in Cfg.Parser.Config

(Constructor c, GConfigParser f) => GConfigParser (M1 C c f) Source #

This is the data constructor case, if we are dealing with a ConfigRoot instance, then we have lookup the "root key", but in all other cases we just keep recursing.

Since: 0.0.2.0

Instance details

Defined in Cfg.Parser.Config

(GConfigParser f, Datatype d) => GConfigParser (M1 D d f) Source #

This is the type constructor case, if we are dealing with a ConfigRoot instance, then we have lookup the "root key", but in all other cases we just keep recursing.

Since: 0.0.2.0

Instance details

Defined in Cfg.Parser.Config

(Selector s, GConfigParser f) => GConfigParser (M1 S s f) Source #

This is the most important case, we need to look up the subconfig by key (just the record field with all key modifiers applied), and then recursively parse the sub tree.

Since: 0.0.2.0

Instance details

Defined in Cfg.Parser.Config