haskell-scfg

[MIRROR] Haskell library for scfg

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

 1# haskell-scfg
 2
 3[![builds.sr.ht status](https://builds.sr.ht/~mariusl/haskell-scfg.svg)](https://builds.sr.ht/~mariusl/haskell-scfg?)
 4
 5Haskell library for [scfg](https://codeberg.org/emersion/scfg).
 6
 7## Usage
 8
 9```haskell
10{-# LANGUAGE OverloadedStrings #-}
11
12import Data.Scfg (
13    Directive (directiveChildren, directiveName, directiveParams),
14    ParseError (errorMessage),
15    parse,
16 )
17import Data.Text (Text)
18import qualified Data.Text as T
19import qualified Data.Text.IO as TIO
20
21config :: Text
22config =
23    "train \"Shinkansen\" {\n\
24    \  model \"E5\" {\n\
25    \    max-speed 320km/h\n\
26    \    weight 453.5t\n\
27    \    lines-served \"Tōhoku\" \"Hokkaido\"\n\
28    \  }\n\
29    \  model \"E7\" {\n\
30    \    max-speed 275km/h\n\
31    \    weight 540t\n\
32    \    lines-served \"Hokuriku\" \"Jōetsu\"\n\
33    \  }\n\
34    \}\n"
35
36main :: IO ()
37main = case parse config of
38    Left err -> TIO.putStrLn $ "parse error: " <> errorMessage err
39    Right cfg -> do
40        let models = concatMap directiveChildren cfg
41        mapM_ (\m -> TIO.putStrLn $ T.unwords (directiveName m : directiveParams m)) models
42
43```
44
45## Contributing
46
47Feel free to send patches to my
48[public-inbox](https://lists.sr.ht/~mariusl/public-inbox). Please note
49what change the patch will have on the version in accordance with the
50[Haskell Package Versioning Policy (PVP)](https://pvp.haskell.org/).
51
52## License
53
54MIT