2023-01-15 21:20:40 +01:00
|
|
|
{-# LANGUAGE TemplateHaskellQuotes #-}
|
|
|
|
|
|
|
|
module AesonQQ where
|
|
|
|
|
|
|
|
import Data.Aeson qualified as Json
|
2023-08-06 12:46:50 +02:00
|
|
|
import Language.Haskell.TH.Quote (QuasiQuoter)
|
2023-05-28 20:58:20 +02:00
|
|
|
import PossehlAnalyticsPrelude
|
2023-01-15 21:20:40 +01:00
|
|
|
import PyF qualified
|
|
|
|
import PyF.Internal.QQ qualified as PyFConf
|
|
|
|
|
2023-08-06 12:46:50 +02:00
|
|
|
aesonQQ :: QuasiQuoter
|
2023-01-15 21:20:40 +01:00
|
|
|
aesonQQ =
|
|
|
|
PyF.mkFormatter
|
|
|
|
"aesonQQ"
|
|
|
|
PyF.defaultConfig
|
|
|
|
{ PyFConf.delimiters = Just ('|', '|'),
|
2023-08-06 12:46:50 +02:00
|
|
|
PyFConf.postProcess = \exp_ -> do
|
2023-01-15 21:20:40 +01:00
|
|
|
-- TODO: this does not throw an error at compilation time if the json does not parse
|
|
|
|
[|
|
2023-08-06 12:46:50 +02:00
|
|
|
case Json.eitherDecodeStrict' @Json.Value $ textToBytesUtf8 $ stringToText $(exp_) of
|
2023-01-15 21:20:40 +01:00
|
|
|
Left err -> error err
|
|
|
|
Right a -> a
|
|
|
|
|]
|
|
|
|
}
|