Add haddock documentation
This commit is contained in:
parent
a1837d70fe
commit
c32525c9ce
12
src/Json.hs
12
src/Json.hs
@ -1,3 +1,4 @@
|
|||||||
|
-- | JSON utilities
|
||||||
module Json where
|
module Json where
|
||||||
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
@ -8,17 +9,19 @@ import Data.List (intercalate)
|
|||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import qualified Data.HashMap.Strict as H
|
import qualified Data.HashMap.Strict as H
|
||||||
|
|
||||||
-- Get the JSON value of a key
|
-- | Get the JSON value of a key
|
||||||
(|.) :: Object -> Text -> Value
|
(|.) :: Object -> Text -> Value
|
||||||
obj |. key = case parse (.: key) obj of
|
obj |. key = case parse (.: key) obj of
|
||||||
Success val -> val
|
Success val -> val
|
||||||
Error err -> toJSON err
|
Error err -> toJSON err
|
||||||
|
|
||||||
-- Get the String value of a key
|
|
||||||
|
-- | Get the String value of a key
|
||||||
(|:) :: Object -> Text -> String
|
(|:) :: Object -> Text -> String
|
||||||
obj |: key = repr (obj |. key)
|
obj |: key = repr (obj |. key)
|
||||||
|
|
||||||
-- Create a String representation of a JSON value
|
|
||||||
|
-- | Create a String representation of a 'Value'
|
||||||
repr :: Value -> String
|
repr :: Value -> String
|
||||||
repr obj = repr' obj 0 where
|
repr obj = repr' obj 0 where
|
||||||
repr' val lev =
|
repr' val lev =
|
||||||
@ -34,6 +37,7 @@ repr obj = repr' obj 0 where
|
|||||||
indent l = '\n' : (concat . replicate l) " "
|
indent l = '\n' : (concat . replicate l) " "
|
||||||
dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)]
|
dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)]
|
||||||
|
|
||||||
-- Pretty print a JSON value
|
|
||||||
|
-- | Pretty print a JSON 'Value'
|
||||||
pprint :: Value -> IO ()
|
pprint :: Value -> IO ()
|
||||||
pprint = putStrLn . repr
|
pprint = putStrLn . repr
|
@ -1,4 +1,6 @@
|
|||||||
{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
|
{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
|
||||||
|
-- | Main module
|
||||||
|
module Main where
|
||||||
|
|
||||||
import Json
|
import Json
|
||||||
|
|
||||||
@ -56,6 +58,9 @@ description = info (helper <*> options)
|
|||||||
<> footer "Stat rosa pristina nomine, nomina nuda tenemus." )
|
<> footer "Stat rosa pristina nomine, nomina nuda tenemus." )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- * Program
|
||||||
|
|
||||||
-- | Main function
|
-- | Main function
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = execParser description >>= exec where
|
main = execParser description >>= exec where
|
||||||
|
Loading…
Reference in New Issue
Block a user