haskell-scfg

[MIRROR] Haskell library for scfg

git clone git://git.marius.pm/haskell-scfg.git

 1{- | Parser for the [scfg](https://codeberg.org/emersion/scfg)
 2configuration file format.
 3-}
 4module Data.Scfg (
 5  parse,
 6  parseFile,
 7  format,
 8  formatFile,
 9  Directive (..),
10  Config,
11  ParseError (..),
12) where
13
14import qualified Data.Scfg.Formatter as F
15import qualified Data.Scfg.Parser as P
16import Data.Scfg.Types
17import Data.Text (Text)
18import qualified Data.Text.IO as TIO
19
20{- | Parse scfg from 'Text'. Returns a 'Data.Scfg.Types.ParseError' if
21the input is not valid scfg.
22-}
23parse :: Text -> Either ParseError Config
24parse = P.parseConfig
25
26{- | Parse scfg from a file. Returns a 'Data.Scfg.Types.ParseError' if
27the input is not valid scfg or if the file cannot be read.
28-}
29parseFile :: FilePath -> IO (Either ParseError Config)
30parseFile path = parse <$> TIO.readFile path
31
32{- | Format a 'Config' as a canonical 'Text' representation. All words
33are double-quoted and blocks indented with tabs.
34-}
35format :: Config -> Text
36format = F.format
37
38{- | Format a 'Config' and write it to a file. Returns an 'IOError' if
39the file cannot be written.
40-}
41formatFile :: FilePath -> Config -> IO ()
42formatFile path = TIO.writeFile path . F.format