kdl-hs: KDL language parser and API

[ bsd3, library, text ] [ Propose Tags ] [ Report a vulnerability ]
Versions [RSS] 0.1.0, 0.2.0, 0.2.1
Change log CHANGELOG.md
Dependencies base (<5), containers, megaparsec, prettyprinter (>=1.7.0), scientific, text, transformers [details]
License BSD-3-Clause
Author Brandon Chinn <brandonchinn178@gmail.com>
Maintainer Brandon Chinn <brandonchinn178@gmail.com>
Category Text
Home page https://github.com/brandonchinn178/kdl-hs#readme
Bug tracker https://github.com/brandonchinn178/kdl-hs/issues
Source repo head: git clone https://github.com/brandonchinn178/kdl-hs
Uploaded by brandonchinn178 at 2026-01-05T05:35:02Z
Distributions Stackage:0.2.1
Downloads 7 total (7 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-01-05 [all 1 reports]

Readme for kdl-hs-0.2.1

[back to package description]

kdl-hs

GitHub Actions

kdl-hs can parse and manage KDL configuration files.

Quickstart

Given a file config.kdl:

package {
  name my-pkg
  version "1.2.3"

  dependencies {
    aeson ">= 2.2.3.0" optional=#true
    text ">= 2"
  }
}

Parse it with kdl-hs:

import KDL qualified

main :: IO ()
main = do
  config <- KDL.decodeFileWith decoder "config.kdl"
  print config

decoder :: KDL.DocumentDecoder Config
decoder = KDL.document $ do
  KDL.node "package"

data Config = Config
  { name :: Text
  , version :: Text
  , dependencies :: Map Text Dep
  }
  deriving (Show)

data Dep = Dep
  { version :: Text
  , optional :: Bool
  }
  deriving (Show)

instance KDL.DecodeNode Config where
  nodeDecoder = do
    name <- KDL.argAt "name"
    version <- KDL.argAt "version"
    dependencies <- KDL.nodeWith "dependencies" . KDL.children $ KDL.remainingNodes
    pure Config{..}

instance KDL.DecodeNode Dep where
  nodeDecoder = do
    version <- KDL.arg
    optional <- KDL.option False $ KDL.prop "optional"
    pure Dep{..}

Acknowledgements

  • The KDL spec authors for devising a super cool configuration language
  • kdl-rs for providing a guide for implementation
  • hustle for the initial parser implementation that got me started.