Copyright | © Jonathan Lorimer 2023 |
---|---|
License | MIT |
Maintainer | jonathanlorimer@pm.me |
Stability | stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- defaultParseConfig :: forall a. (Generic a, GConfigParser (Rep a)) => ConfigOptions -> KeyTree Text Text -> Either ConfigParseError a
- class GConfigParser (f :: Type -> Type) where
- gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError (f p)
Default Parser Function
defaultParseConfig :: forall a. (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
gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError (f p) Source #
Instances
(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 |
Defined in Cfg.Parser.Config gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError ((a :*: b) p) Source # | |
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, Since: 0.0.2.0 |
Defined in Cfg.Parser.Config gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError (K1 R a p) Source # | |
(Constructor c, GConfigParser f) => GConfigParser (M1 C c f) Source # | This is the data constructor case, if we are dealing with a
Since: 0.0.2.0 |
Defined in Cfg.Parser.Config gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError (M1 C c f p) Source # | |
(GConfigParser f, Datatype d) => GConfigParser (M1 D d f) Source # | This is the type constructor case, if we are dealing with a
Since: 0.0.2.0 |
Defined in Cfg.Parser.Config gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError (M1 D d f p) Source # | |
(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 |
Defined in Cfg.Parser.Config gParseConfig :: ConfigOptions -> KeyTree Text Text -> Either ConfigParseError (M1 S s f p) Source # |