{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Uniform.Yaml
( module Uniform.Yaml,
ErrIO,
Y.ParseException (..),
Y.decodeFileThrow,
Y.encode,
Y.decode,
Y.decodeEither,
Options(..)
)
where
import Data.Aeson.Types (Options(..))
import qualified Data.Yaml as Y
import UniformBase
import Uniform.Json
decodeThrowT :: Text -> ErrIO Value
decodeThrowT :: Text -> ErrIO Value
decodeThrowT = forall (m :: * -> *) a.
(MonadThrow m, FromJSON a) =>
ByteString -> m a
Y.decodeThrow forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
t2b
newtype YamlText = YamlText Text deriving (Int -> YamlText -> ShowS
[YamlText] -> ShowS
YamlText -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [YamlText] -> ShowS
$cshowList :: [YamlText] -> ShowS
show :: YamlText -> String
$cshow :: YamlText -> String
showsPrec :: Int -> YamlText -> ShowS
$cshowsPrec :: Int -> YamlText -> ShowS
Show, ReadPrec [YamlText]
ReadPrec YamlText
Int -> ReadS YamlText
ReadS [YamlText]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [YamlText]
$creadListPrec :: ReadPrec [YamlText]
readPrec :: ReadPrec YamlText
$creadPrec :: ReadPrec YamlText
readList :: ReadS [YamlText]
$creadList :: ReadS [YamlText]
readsPrec :: Int -> ReadS YamlText
$creadsPrec :: Int -> ReadS YamlText
Read, YamlText -> YamlText -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: YamlText -> YamlText -> Bool
$c/= :: YamlText -> YamlText -> Bool
== :: YamlText -> YamlText -> Bool
$c== :: YamlText -> YamlText -> Bool
Eq, Eq YamlText
YamlText -> YamlText -> Bool
YamlText -> YamlText -> Ordering
YamlText -> YamlText -> YamlText
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: YamlText -> YamlText -> YamlText
$cmin :: YamlText -> YamlText -> YamlText
max :: YamlText -> YamlText -> YamlText
$cmax :: YamlText -> YamlText -> YamlText
>= :: YamlText -> YamlText -> Bool
$c>= :: YamlText -> YamlText -> Bool
> :: YamlText -> YamlText -> Bool
$c> :: YamlText -> YamlText -> Bool
<= :: YamlText -> YamlText -> Bool
$c<= :: YamlText -> YamlText -> Bool
< :: YamlText -> YamlText -> Bool
$c< :: YamlText -> YamlText -> Bool
compare :: YamlText -> YamlText -> Ordering
$ccompare :: YamlText -> YamlText -> Ordering
Ord)
unYAML :: YamlText -> Text
unYAML :: YamlText -> Text
unYAML (YamlText Text
a) = Text
a
extYAML :: Extension
extYAML :: Extension
extYAML = String -> Extension
Extension String
"yaml"
yamlFileType :: TypedFile5 Text YamlText
instance Zeros YamlText where zero :: YamlText
zero = Text -> YamlText
YamlText forall z. Zeros z => z
zero
yamlFileType :: TypedFile5 Text YamlText
yamlFileType = TypedFile5 {tpext5 :: Extension
tpext5 = Extension
extYAML} :: TypedFile5 Text YamlText
instance TypedFiles7 Text YamlText where
wrap7 :: Text -> YamlText
wrap7 = Text -> YamlText
YamlText
unwrap7 :: YamlText -> Text
unwrap7 (YamlText Text
a) = Text
a
readYaml2value :: Path Abs File -> ErrIO Value
readYaml2value :: Path Abs File -> ErrIO Value
readYaml2value Path Abs File
fp = do
YamlText
t <- forall a b.
TypedFiles7a a b =>
Path Abs File -> TypedFile5 a b -> ErrIO b
read8 Path Abs File
fp TypedFile5 Text YamlText
yamlFileType
forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. YamlText -> Value
yaml2value forall a b. (a -> b) -> a -> b
$ YamlText
t
yaml2value :: YamlText -> Value
yaml2value :: YamlText -> Value
yaml2value YamlText
yt = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => String -> a
error forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) forall a. a -> a
Prelude.id Either ParseException Value
vx
where
vx :: Either ParseException Value
vx = forall a. FromJSON a => ByteString -> Either ParseException a
Y.decodeEither' (Text -> ByteString
t2b forall b c a. (b -> c) -> (a -> b) -> a -> c
. YamlText -> Text
unYAML forall a b. (a -> b) -> a -> b
$ YamlText
yt) :: Either Y.ParseException Value
readYaml2rec :: (FromJSON a, Show a) => Path Abs File -> ErrIO a
readYaml2rec :: forall a. (FromJSON a, Show a) => Path Abs File -> ErrIO a
readYaml2rec Path Abs File
fn = do
Value
s0 :: Value <- Path Abs File -> ErrIO Value
readYaml2value Path Abs File
fn
a
s1 <- forall a. (FromJSON a, Show a) => Value -> ErrIO a
fromJSONerrio Value
s0
forall (m :: * -> *) a. Monad m => a -> m a
return a
s1