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

Safe HaskellNone
LanguageHaskell98

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 key separators, section delimiters, or comment markers.
  • Comments must start at the beginning of the line and start with ; or #.

An example configuration file:

# Some comment.
[SERVER]
port=6667
hostname=localhost
; another comment here
[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 Ini Source #

Parse an INI config.

lookupValue :: Text -> Text -> Ini -> Either String Text Source #

Lookup values in the config.

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

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

parseValue :: Text -> Text -> Parser a -> Ini -> Either String a Source #

Parse a value using a reader from Data.Attoparsec.Text.

sections :: Ini -> [Text] Source #

Get the sections in the config.

keys :: Text -> Ini -> Either String [Text] Source #

Get the keys in a section.

Writing

printIni :: Ini -> Text Source #

Print an INI config.

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

Print the INI config to a file.

Advanced writing

data WriteIniSettings Source #

Settings determining how an INI file is written.

defaultWriteIniSettings :: WriteIniSettings Source #

The default settings for writing INI files.

printIniWith :: WriteIniSettings -> Ini -> Text Source #

Print an INI config.

writeIniFileWith :: WriteIniSettings -> FilePath -> Ini -> IO () Source #

Print the INI config to a file.

Types

newtype Ini Source #

An INI configuration.

Constructors

Ini 

Instances

Show Ini Source # 

Methods

showsPrec :: Int -> Ini -> ShowS #

show :: Ini -> String #

showList :: [Ini] -> ShowS #

Semigroup Ini Source # 

Methods

(<>) :: Ini -> Ini -> Ini #

sconcat :: NonEmpty Ini -> Ini #

stimes :: Integral b => b -> Ini -> Ini #

Monoid Ini Source # 

Methods

mempty :: Ini #

mappend :: Ini -> Ini -> Ini #

mconcat :: [Ini] -> Ini #

Parsers

iniParser :: Parser Ini Source #

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.