brandonchinn178 / toml-reader

Haskell library for parsing v1.0 TOML files
https://hackage.haskell.org/package/toml-reader
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link
haskell toml

toml-reader

GitHub Actions

TOML format parser compliant with v1.0.0 (verified with the toml-test tool).

Usage

{-# LANGUAGE OverloadedStrings #-}

import TOML (DecodeTOML, tomlDecoder, getField, decodeFile)

data MyConfig = MyConfig
  { field1 :: Int
  , field2 :: Bool
  } deriving (Show)

instance DecodeTOML MyConfig where
  tomlDecoder =
    MyConfig
      <$> getField "field1"
      <*> getField "field2"

main :: IO ()
main = do
  result <- decodeFile "config.toml"
  case result of
    Right cfg -> print (cfg :: MyConfig)
    Left e -> print e

Design decisions