configurator-pg-0.1.0.0: Reduced parser for configurator-ng config files

Data.Configurator

Description

A simplified library for reading configuration files in the format of configurator-ng.

Synopsis

# Types

type Key = Text Source #

The left-hand side of a configuration binding.

data Value Source #

A general right-hand side value of a configuration binding.

Constructors

 Bool Bool A Boolean. Represented in a configuration file as on or off, true or false (case sensitive). String Text A Unicode string. Represented in a configuration file as text surrounded by double quotes.Escape sequences:\n - newline\r - carriage return\t - horizontal tab\\ - backslash\" - quotes\uxxxx - Unicode character, encoded as four hexadecimal digits\uxxxx\uxxxx - Unicode character (as two UTF-16 surrogates) Number Scientific A number. List [Value] A heterogeneous list. Represented in a configuration file as an opening square bracket "[", followed by a comma-separated series of values, ending with a closing square bracket "]".
Instances
 Source # Instance detailsDefined in Data.Configurator.Types Methods(==) :: Value -> Value -> Bool #(/=) :: Value -> Value -> Bool # Source # Instance detailsDefined in Data.Configurator.Types MethodsshowsPrec :: Int -> Value -> ShowS #show :: Value -> String #showList :: [Value] -> ShowS #

An evaluated configuation.

# Low-level parsing

Read and parse a configuration file.

This may cause IO exceptions for reading this file or imported files, and ParseError if there is a problem with parsing or evaluating the file.

newtype ParseError Source #

An error that occurred during the low-level parsing of a configuration file.

Constructors

 ParseError Text
Instances
 Source # Instance detailsDefined in Data.Configurator.Types MethodsshowList :: [ParseError] -> ShowS # Source # Instance detailsDefined in Data.Configurator.Types Methods

# High-level parsing

data Parser a b Source #

A generic parser.

A Parser a b knows how to extract a b from an a. Typical instances are Parser Value a, which handles the parsing of individual configuration values, and Parser Config a, which handles extracting data from a full keyed configuration file.

Instances
 Monad (Parser a) Source # Instance detailsDefined in Data.Configurator.Parser Methods(>>=) :: Parser a a0 -> (a0 -> Parser a b) -> Parser a b #(>>) :: Parser a a0 -> Parser a b -> Parser a b #return :: a0 -> Parser a a0 #fail :: String -> Parser a a0 # Source # Instance detailsDefined in Data.Configurator.Parser Methodsfmap :: (a0 -> b) -> Parser a a0 -> Parser a b #(<\$) :: a0 -> Parser a b -> Parser a a0 # Source # Instance detailsDefined in Data.Configurator.Parser Methodspure :: a0 -> Parser a a0 #(<*>) :: Parser a (a0 -> b) -> Parser a a0 -> Parser a b #liftA2 :: (a0 -> b -> c) -> Parser a a0 -> Parser a b -> Parser a c #(*>) :: Parser a a0 -> Parser a b -> Parser a b #(<*) :: Parser a a0 -> Parser a b -> Parser a a0 #

runParser :: Parser a b -> a -> Either Text b Source #

Run a parser.

runParser p x runs the parser p on the input x, returning a value Right v on success, or Left err on error.

## Value parsers

Extract a boolean value.

bool expects the given value to be boolean.

Extract an integer value.

int expects the given value to be an Int.

Extract a string value.

string expects the given value to be a string.

Extract a raw value.

value returns a configuration value in its raw form.

list :: Parser Value a -> Parser Value [a] Source #

Parse a list of values.

list p expects a list value, and parses each entry with p.

## Configuration parsers

Parse an optional configuration field.

optional key p returns Nothing if the field key is not present. Otherwise it returns Just v, where v is the result of parsing the field value with p.

Parse a required configuration field.

required key p expects the field key to be present, and parses its value with p.

subassocs :: Key -> Parser Value a -> Parser Config [(Key, a)] Source #

Parse a set of fields with a shared prefix.

subassocs prefix p extracts all configuration keys one level below prefix, and collects pairs of the full keys and the corresponding field values parsed with p.