@hackage scfg1.0.0

SCFG parser for Haskell

haskell-scfg

builds.sr.ht status

Haskell library for scfg.

Usage

{-# 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. Please note what change the patch will have on the version in accordance with the Haskell Package Versioning Policy (PVP).

License

MIT