ini-0.1.0: Quick and easy configuration files in the INI format.

Safe HaskellNone

Data.Ini

Contents

Description

Clean configuration files in the INI format.

Format rules and recommendations:

  • The : syntax is space-sensitive.
  • Keys are case-sensitive.
  • Lower-case is recommended.
  • Values can be empty.
  • Keys cannot contain :, =, [, or ].
  • Comments are not supported at this time.

An example configuration file:

 [SERVER]
 port=6667
 hostname=localhost
 [AUTH]
 user: hello
 pass: world
 salt:

Parsing example:

>>> parseIni "[SERVER]\nport: 6667\nhostname: localhost"
Right (Ini {unIni = fromList [("SERVER",fromList [("hostname","localhost"),("port","6667")])]})

Synopsis

Reading

readIniFile :: FilePath -> IO (Either String Ini)Source

Parse an INI file.

parseIni :: Text -> Either String IniSource

Parse an INI config.

lookupValue :: Ini -> Text -> Text -> Either String TextSource

Lookup values in the config.

readValue :: Ini -> Text -> Text -> (Text -> Either String (a, Text)) -> Either String aSource

Read a value using a reader from Data.Text.Read.

Writing

writeIniFile :: FilePath -> Ini -> IO ()Source

Print the INI config to a file.

printIni :: Ini -> TextSource

Print an INI config.

Types

newtype Ini Source

An INI configuration.

Constructors

Ini 

Instances

Parsers

iniParser :: Parser IniSource

Parser for an INI.

sectionParser :: Parser (Text, HashMap Text Text)Source

A section. Format: [foo]. Conventionally, [FOO].

keyValueParser :: Parser (Text, Text)Source

A key-value pair. Either foo: bar or foo=bar.