packages feed

scfg-1.0.0: README.md

# haskell-scfg

[![builds.sr.ht status](https://builds.sr.ht/~mariusl/haskell-scfg.svg)](https://builds.sr.ht/~mariusl/haskell-scfg?)

Haskell library for [scfg](https://codeberg.org/emersion/scfg).

## Usage

```haskell
{-# LANGUAGE OverloadedStrings #-}

import Data.Scfg (
    Directive (directiveChildren, directiveName, directiveParams),
    ParseError (errorMessage),
    parse,
 )
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO

config :: Text
config =
    "train \"Shinkansen\" {\n\
    \  model \"E5\" {\n\
    \    max-speed 320km/h\n\
    \    weight 453.5t\n\
    \    lines-served \"Tōhoku\" \"Hokkaido\"\n\
    \  }\n\
    \  model \"E7\" {\n\
    \    max-speed 275km/h\n\
    \    weight 540t\n\
    \    lines-served \"Hokuriku\" \"Jōetsu\"\n\
    \  }\n\
    \}\n"

main :: IO ()
main = case parse config of
    Left err -> TIO.putStrLn $ "parse error: " <> errorMessage err
    Right cfg -> do
        let models = concatMap directiveChildren cfg
        mapM_ (\m -> TIO.putStrLn $ T.unwords (directiveName m : directiveParams m)) models

```

## Contributing

Feel free to send patches to my
[public-inbox](https://lists.sr.ht/~mariusl/public-inbox). Please note
what change the patch will have on the version in accordance with the
[Haskell Package Versioning Policy (PVP)](https://pvp.haskell.org/).

## License

MIT