libconfig-0.3.0.0: Haskell bindings to libconfig

Copyright(c) Matthew Peddie 2014
LicenseBSD3
Maintainermpeddie@gmail.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Language.Libconfig.Decode

Contents

Description

Converting libconfig native data into friendly Haskell structures from Language.Libconfig.Types.

Synopsis

Decoding libconfig native data

decode :: Configuration -> IO (Either DecodeError Group) Source

Convert a native Configuration into a top-level Group of Settings.

>>> Just conf <- C.configNew "test/test.conf"
>>> decode conf
Right ["version" := Scalar (String "1.0"),"application" := Group ["window" := Group ["title" := Scalar (String "My Application"),"size" := Group ["w" := Scalar (Integer 640),"h" := Scalar (Integer 480)],"pos" := Group ["x" := Scalar (Integer 350),"y" := Scalar (Integer 250)]],"list" := List [List [Scalar (String "abc"),Scalar (Integer 123),Scalar (Boolean True)],Scalar (Float 1.234),List []],"books" := List [Group ["title" := Scalar (String "Treasure Island"),"author" := Scalar (String "Robert Louis Stevenson"),"price" := Scalar (Float 29.95),"qty" := Scalar (Integer 5)],Group ["title" := Scalar (String "Snow Crash"),"author" := Scalar (String "Neal Stephenson"),"price" := Scalar (Float 9.99),"qty" := Scalar (Integer 8)]],"misc" := Group ["pi" := Scalar (Float 3.141592654),"bigint" := Scalar (Integer64 9223372036854775807),"columns" := Array [String "Last Name",String "First Name",String "MI"],"bitmask" := Scalar (Hex 8131)]]]

decodeFrom :: String -> IO (Either DecodeError Group) Source

Load the libconfig configuration file at the given path and try to convert it to a top-level Group of Settings.

>>> decodeFrom "test/test.conf"
Right ["version" := Scalar (String "1.0"),"application" := Group ["window" := Group ["title" := Scalar (String "My Application"),"size" := Group ["w" := Scalar (Integer 640),"h" := Scalar (Integer 480)],"pos" := Group ["x" := Scalar (Integer 350),"y" := Scalar (Integer 250)]],"list" := List [List [Scalar (String "abc"),Scalar (Integer 123),Scalar (Boolean True)],Scalar (Float 1.234),List []],"books" := List [Group ["title" := Scalar (String "Treasure Island"),"author" := Scalar (String "Robert Louis Stevenson"),"price" := Scalar (Float 29.95),"qty" := Scalar (Integer 5)],Group ["title" := Scalar (String "Snow Crash"),"author" := Scalar (String "Neal Stephenson"),"price" := Scalar (Float 9.99),"qty" := Scalar (Integer 8)]],"misc" := Group ["pi" := Scalar (Float 3.141592654),"bigint" := Scalar (Integer64 9223372036854775807),"columns" := Array [String "Last Name",String "First Name",String "MI"],"bitmask" := Scalar (Hex 8131)]]]

Decoding errors

data DecodeError Source

Any of these problems can occur while decoding a libconfig Configuration.

Constructors

DecoderRoot

No root setting was found (possibly this configuration is invalid?)

Name 

Fields

decodeErrSetting :: Text

This setting had no name but was in a Group.

GetNone 

Fields

decodeErrSetting :: Text

This setting had no name but was in a Group.

GetIndex 

Fields

decodeErrParent :: Text

Failed to get a child of this Setting

decodeErrIndex :: Int

This was the index we tried to look up

Parse 

Fields

decodeErrFilename :: Text

The file in which parsing failed

decodeErrLine :: Word32

The line of the file on which parsing failed

decodeErrDescription :: Text

libconfig's description of the parsing failure

FileInput 

Fields

decodeErrFilename :: Text

The file in which parsing failed