Maintainer | cabal-devel@haskell.org |
---|---|
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Parsing utilities.
Synopsis
- data FieldDescr a = FieldDescr {}
- liftField :: (b -> a) -> (a -> b -> b) -> FieldDescr a -> FieldDescr b
- liftFields :: (b -> a) -> (a -> b -> b) -> [FieldDescr a] -> [FieldDescr b]
- filterFields :: [String] -> [FieldDescr a] -> [FieldDescr a]
- mapFieldNames :: (String -> String) -> [FieldDescr a] -> [FieldDescr a]
- commandOptionToField :: OptionField a -> FieldDescr a
- commandOptionsToFields :: [OptionField a] -> [FieldDescr a]
- data SectionDescr a = forall b.SectionDescr {
- sectionName :: String
- sectionFields :: [FieldDescr b]
- sectionSubsections :: [SectionDescr b]
- sectionGet :: a -> [(String, b)]
- sectionSet :: LineNo -> String -> b -> a -> ParseResult a
- sectionEmpty :: b
- liftSection :: (b -> a) -> (a -> b -> b) -> SectionDescr a -> SectionDescr b
- data FGSectionDescr g a = forall s.FGSectionDescr {
- fgSectionName :: String
- fgSectionGrammar :: g s s
- fgSectionGet :: a -> [(String, s)]
- fgSectionSet :: LineNo -> String -> s -> a -> ParseResult a
- parseFields :: [FieldDescr a] -> a -> [Field] -> ParseResult a
- ppFields :: [FieldDescr a] -> Maybe a -> a -> Doc
- ppSection :: String -> String -> [FieldDescr a] -> Maybe a -> a -> Doc
- parseFieldsAndSections :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr ParsecFieldGrammar a] -> a -> [Field] -> ParseResult a
- ppFieldsAndSections :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr PrettyFieldGrammar a] -> a -> Doc
- parseConfig :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr ParsecFieldGrammar a] -> a -> ByteString -> ParseResult a
- showConfig :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr PrettyFieldGrammar a] -> a -> Doc
Fields and field utilities
data FieldDescr a Source #
Field descriptor. The parameter a
parameterizes over where the field's
value is stored in.
liftField :: (b -> a) -> (a -> b -> b) -> FieldDescr a -> FieldDescr b Source #
liftFields :: (b -> a) -> (a -> b -> b) -> [FieldDescr a] -> [FieldDescr b] Source #
filterFields :: [String] -> [FieldDescr a] -> [FieldDescr a] Source #
Given a collection of field descriptions, keep only a given list of them, identified by name.
mapFieldNames :: (String -> String) -> [FieldDescr a] -> [FieldDescr a] Source #
Apply a name mangling function to the field names of all the field descriptions. The typical use case is to apply some prefix.
commandOptionToField :: OptionField a -> FieldDescr a Source #
Reuse a command line OptionField
as a config file FieldDescr
.
commandOptionsToFields :: [OptionField a] -> [FieldDescr a] Source #
Reuse a bunch of command line OptionField
s as config file FieldDescr
s.
Sections and utilities
data SectionDescr a Source #
The description of a section in a config file. It can contain both
fields and optionally further subsections. See also FieldDescr
.
forall b. SectionDescr | |
|
liftSection :: (b -> a) -> (a -> b -> b) -> SectionDescr a -> SectionDescr b Source #
To help construction of config file descriptions in a modular way it is useful to define fields and sections on local types and then hoist them into the parent types when combining them in bigger descriptions.
This is essentially a lens operation for SectionDescr
to help embedding
one inside another.
FieldGrammar sections
data FGSectionDescr g a Source #
FieldGrammar
section description
forall s. FGSectionDescr | |
|
Parsing and printing flat config
parseFields :: [FieldDescr a] -> a -> [Field] -> ParseResult a Source #
Parse a bunch of semi-parsed Field
s according to a set of field
descriptions. It accumulates the result on top of a given initial value.
This only covers the case of flat configuration without subsections. See
also parseFieldsAndSections
.
ppFields :: [FieldDescr a] -> Maybe a -> a -> Doc Source #
This is a customised version of the functions from Distribution.Deprecated.ParseUtils that also optionally print default values for empty fields as comments.
ppSection :: String -> String -> [FieldDescr a] -> Maybe a -> a -> Doc Source #
Pretty print a section.
Since ppFields
does not cover subsections you can use this to add them.
Or alternatively use a SectionDescr
and use ppFieldsAndSections
.
Parsing and printing config with sections and subsections
parseFieldsAndSections Source #
:: [FieldDescr a] | field |
-> [SectionDescr a] | legacy sections |
-> [FGSectionDescr ParsecFieldGrammar a] | FieldGrammar sections |
-> a | |
-> [Field] | |
-> ParseResult a |
Much like parseFields
but it also allows subsections. The permitted
subsections are given by a list of SectionDescr
s.
ppFieldsAndSections :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr PrettyFieldGrammar a] -> a -> Doc Source #
Top level of config files
parseConfig :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr ParsecFieldGrammar a] -> a -> ByteString -> ParseResult a Source #
Parse a string in the config file syntax into a value, based on a description of the configuration file in terms of its fields and sections.
It accumulates the result on top of a given initial (typically empty) value.
showConfig :: [FieldDescr a] -> [SectionDescr a] -> [FGSectionDescr PrettyFieldGrammar a] -> a -> Doc Source #
Render a value in the config file syntax, based on a description of the configuration file in terms of its fields and sections.