Quick and easy configuration files in the INI format for Haskell.
Format rules and recommendations:
foo: bar
or foo=bar
are allowed.:
syntax is space-sensitive.:
, =
, [
, or ]
.;
or #
.An example configuration file:
# Some comment.
[SERVER]
port=6667
hostname=localhost
[AUTH]
user=hello
pass=world
# Salt can be an empty string.
salt=
Parsing example:
> parseIni "[SERVER]\nport: 6667\nhostname: localhost"
Right (Ini {unIni = fromList [("SERVER",fromList [("hostname","localhost")
,("port","6667")])]})
Extracting values:
> parseIni "[SERVER]\nport: 6667\nhostname: localhost" >>=
lookupValue "SERVER" "hostname"
Right "localhost"
Parsing:
> parseIni "[SERVER]\nport: 6667\nhostname: localhost" >>=
readValue "SERVER" "port" decimal
Right 6667
Import Data.Text.Read
to use decimal
.
ini-qq
provides a quasiquoter for INI.