Copyright | (c) Matthew Peddie 2014 |
---|---|
License | BSD3 |
Maintainer | mpeddie@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Converting libconfig native data into friendly Haskell structures from Language.Libconfig.Types.
- decode :: Configuration -> IO (Either DecodeError Group)
- decodeFrom :: String -> IO (Either DecodeError Group)
- data DecodeError
Decoding libconfig native data
decode :: Configuration -> IO (Either DecodeError Group) Source
Convert a native Configuration
into a top-level Group
of
Setting
s.
>>>
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 Setting
s.
>>>
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
.
DecoderRoot | No root setting was found (possibly this configuration is invalid?) |
Name | |
| |
GetNone | |
| |
GetIndex | |
| |
Parse | |
| |
FileInput | |
|