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

Safe HaskellNone
LanguageHaskell2010

Data.Configurator

Contents

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
Eq Value Source # 
Instance details

Defined in Data.Configurator.Types

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

Show Value Source # 
Instance details

Defined in Data.Configurator.Types

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

type Config = Map Key Value Source #

An evaluated configuation.

Low-level parsing

load :: FilePath -> IO Config Source #

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 

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 details

Defined 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 #

Functor (Parser a) Source # 
Instance details

Defined in Data.Configurator.Parser

Methods

fmap :: (a0 -> b) -> Parser a a0 -> Parser a b #

(<$) :: a0 -> Parser a b -> Parser a a0 #

Applicative (Parser a) Source # 
Instance details

Defined in Data.Configurator.Parser

Methods

pure :: 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

bool :: Parser Value Bool Source #

Extract a boolean value.

bool expects the given value to be boolean.

int :: Parser Value Int Source #

Extract an integer value.

int expects the given value to be an Int.

string :: Parser Value Text Source #

Extract a string value.

string expects the given value to be a string.

value :: Parser Value Value Source #

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

optional :: Key -> Parser Value a -> Parser Config (Maybe a) Source #

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.

required :: Key -> Parser Value a -> Parser Config a Source #

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.