haskell-scfg
Haskell library for scfg. Available on Hackage.
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
Documentation
Releases
- 2026-09-17 - 1.0.1
- 2026-03-23 - 1.0.0
Dependencies
- base (>=4.19.0.0 && <4.21)
- megaparsec (>=9.7.0 && <9.8)
- text (>=2.1.0 && <2.2)
Tested with
- ghc 9.8.2
- ghc 9.10.3
License
MIT
Git repository
git clone https://git.sr.ht/~lundy/haskell-scfgContributing
Send patches and bug reports to my public-inbox.