-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMain.hs
38 lines (33 loc) · 1.15 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-|
Module : Main
Description : Decoder driver for BurntSushi TOML test suite
Copyright : (c) Eric Mertens, 2023
License : ISC
Maintainer : emertens@gmail.com
Decode TOML into JSON for use with <https://github.com/BurntSushi/toml-test>
-}
module Main (main) where
import Data.Text.IO qualified as Text
import Prettyprinter.Render.Terminal
import Toml
import Toml.Pretty (prettyLocated, prettyTomlOrdered)
import Toml.Syntax (parseRawToml)
import Toml.Semantics (semantics)
import Toml.Semantics.Ordered (extractTableOrder, projectKey)
main :: IO ()
main =
do txt <- Text.getContents
case parseRawToml txt of
Left e -> fail (prettyLocated e)
Right exprs ->
let to = extractTableOrder exprs in
case semantics exprs of
Left e -> fail (prettySemanticError e)
Right toml -> putDoc (style <$> prettyTomlOrdered (projectKey to) toml)
style :: DocClass -> AnsiStyle
style TableClass = colorDull Yellow <> bold
style NumberClass = colorDull Cyan
style DateClass = colorDull Green
style StringClass = colorDull Red
style KeyClass = colorDull Blue
style BoolClass = colorDull Magenta