config-schema-1.2.0.0: Schema definitions for the config-value package
Copyright(c) Eric Mertens 2017
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Config.Schema.Types

Description

This module defines the syntax of value specifications.

Specifications can be defined using Config.Schema.Spec and can be consumed with Config.Schema.Load and Config.Schema.Doc.

This module defines high-level ValueSpec and SectionsSpec types that are intended to be used by normal library users. This types are implemented in terms of primitive PrimValueSpec and PrimSectionSpec types. These primitives are what consumers of specifications will need to use.

Synopsis

Value specification

data ValueSpec a Source #

Non-empty disjunction of value specifications. This type is the primary way to specify expected values.

Multiple specifications can be combined using this type's Alt instance.

To create ValueSpec values see Config.Schema.Spec

Instances

Instances details
Functor ValueSpec Source # 
Instance details

Defined in Config.Schema.Types

Methods

fmap :: (a -> b) -> ValueSpec a -> ValueSpec b #

(<$) :: a -> ValueSpec b -> ValueSpec a #

Alt ValueSpec Source #

Left-biased choice between two specifications

Instance details

Defined in Config.Schema.Types

data PrimValueSpec :: * -> * where Source #

The primitive specification descriptions for values. Specifications built from these primitive cases are found in ValueSpec.

Constructors

TextSpec :: PrimValueSpec Text

Matches any string literal

NumberSpec :: PrimValueSpec Number

Matches numbers

AnyAtomSpec :: PrimValueSpec Text

Matches any atom

AtomSpec :: Text -> PrimValueSpec ()

Specific atom to be matched

ListSpec :: ValueSpec a -> PrimValueSpec [a]

Matches a list of the underlying specification

SectionsSpec :: Text -> SectionsSpec a -> PrimValueSpec a

Documentation identifier and sections specification

AssocSpec :: ValueSpec a -> PrimValueSpec [(Text, a)]

Matches an arbitrary list of sections. Similar to SectionsSpec except that that the section names are user-defined.

CustomSpec :: Text -> ValueSpec (Either Text a) -> PrimValueSpec a

Documentation text and underlying specification. This specification will match values where the underlying specification returns a Right value. Otherwise a Left should contain a short failure explanation.

NamedSpec :: Text -> ValueSpec a -> PrimValueSpec a

Label used to hide complex specifications in documentation.

primValueSpec :: PrimValueSpec a -> ValueSpec a Source #

Lift a primitive value specification to ValueSpec.

Since: 0.2.0.0

runValueSpec :: Alt f => (forall x. PrimValueSpec x -> f x) -> ValueSpec a -> f a Source #

Given an interpretation of a primitive value specification, extract a list of the possible interpretations of a disjunction of value specifications. Each of these primitive interpretations will be combined using the provided Alt instance.

runValueSpec_ :: Semigroup m => (forall x. PrimValueSpec x -> m) -> ValueSpec a -> m Source #

Given an interpretation of a primitive value specification, extract a list of the possible interpretations of a disjunction of value specifications. Each of these primitive interpretations will be combined using the provided Semigroup instance.

Unordered section-value pairs specification

data SectionsSpec a Source #

A list of section specifications used to process a whole group of key-value pairs. Multiple section specifications can be combined using this type's Applicative instance.

To create SectionsSpec values see Config.Schema.Spec

Instances

Instances details
Functor SectionsSpec Source # 
Instance details

Defined in Config.Schema.Types

Methods

fmap :: (a -> b) -> SectionsSpec a -> SectionsSpec b #

(<$) :: a -> SectionsSpec b -> SectionsSpec a #

Applicative SectionsSpec Source # 
Instance details

Defined in Config.Schema.Types

data PrimSectionSpec :: * -> * where Source #

Specifications for single configuration sections.

The fields are section name, documentation text, value specification. Use ReqSection for required key-value pairs and OptSection for optional ones.

Constructors

ReqSection :: Text -> Text -> ValueSpec a -> PrimSectionSpec a

Required section: Name, Documentation, Specification

OptSection :: Text -> Text -> ValueSpec a -> PrimSectionSpec (Maybe a)

Optional section: Name, Documentation, Specification

primSectionsSpec :: PrimSectionSpec a -> SectionsSpec a Source #

Lift a single specification into a list of specifications.

Since: 0.2.0.0

runSections :: Applicative f => (forall x. PrimSectionSpec x -> f x) -> SectionsSpec a -> f a Source #

Given an function that handles a single, primitive section specification; runSections will generate one that processes a whole SectionsSpec.

The results from each section will be sequence together using the Applicative instance in of the result type, and the results can be indexed by the type parameter of the specification.

For an example use of runSections, see Config.Schema.Load.

runSections_ :: Monoid m => (forall x. PrimSectionSpec x -> m) -> SectionsSpec a -> m Source #

Given an function that handles a single, primitive section specification; runSections_ will generate one that processes a whole SectionsSpec.

The results from each section will be sequence together using the Monoid instance in of the result type, and the results will not be indexed by the type parameter of the specifications.

For an example use of runSections_, see Config.Schema.Docs.