{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
module Prettyprinter.Interpolate
( di
, __di
, diii
, __di'E
, __di'L
, diii'E
, diii'L
, d__i'E
, d__i'L
) where
#if MIN_VERSION_prettyprinter(1,7,0)
import Prettyprinter (Pretty(pretty))
#else
import Data.Text.Prettyprint.Doc (Pretty(pretty))
#endif
import Data.String.Interpolate
import Data.Text (Text)
import Language.Haskell.TH (Q)
import Language.Haskell.TH.Quote (QuasiQuoter(..))
import Language.Haskell.TH.Syntax (Name)
wrapper :: Name -> QuasiQuoter -> QuasiQuoter
wrapper :: Name -> QuasiQuoter -> QuasiQuoter
wrapper Name
nm QuasiQuoter
wrapped = QuasiQuoter :: (String -> Q Exp)
-> (String -> Q Pat)
-> (String -> Q Type)
-> (String -> Q [Dec])
-> QuasiQuoter
QuasiQuoter
{ quoteExp :: String -> Q Exp
quoteExp = \String
s -> [| pretty ($(quoteExp wrapped s) :: Text) |]
, quotePat :: String -> Q Pat
quotePat = Q Pat -> String -> Q Pat
forall a b. a -> b -> a
const (Q Pat -> String -> Q Pat) -> Q Pat -> String -> Q Pat
forall a b. (a -> b) -> a -> b
$ Name -> String -> Q Pat
forall a. Name -> String -> Q a
errQQType Name
nm String
"pattern"
, quoteType :: String -> Q Type
quoteType = Q Type -> String -> Q Type
forall a b. a -> b -> a
const (Q Type -> String -> Q Type) -> Q Type -> String -> Q Type
forall a b. (a -> b) -> a -> b
$ Name -> String -> Q Type
forall a. Name -> String -> Q a
errQQType Name
nm String
"type"
, quoteDec :: String -> Q [Dec]
quoteDec = Q [Dec] -> String -> Q [Dec]
forall a b. a -> b -> a
const (Q [Dec] -> String -> Q [Dec]) -> Q [Dec] -> String -> Q [Dec]
forall a b. (a -> b) -> a -> b
$ Name -> String -> Q [Dec]
forall a. Name -> String -> Q a
errQQType Name
nm String
"declaration"
}
di :: QuasiQuoter
di :: QuasiQuoter
di = Name -> QuasiQuoter -> QuasiQuoter
wrapper 'di QuasiQuoter
i
__di :: QuasiQuoter
__di :: QuasiQuoter
__di = Name -> QuasiQuoter -> QuasiQuoter
wrapper '__di QuasiQuoter
__i
diii :: QuasiQuoter
diii :: QuasiQuoter
diii = Name -> QuasiQuoter -> QuasiQuoter
wrapper 'diii QuasiQuoter
iii
__di'E :: QuasiQuoter
__di'E :: QuasiQuoter
__di'E = Name -> QuasiQuoter -> QuasiQuoter
wrapper '__di'E QuasiQuoter
__i'E
__di'L :: QuasiQuoter
__di'L :: QuasiQuoter
__di'L = Name -> QuasiQuoter -> QuasiQuoter
wrapper '__di'L QuasiQuoter
__i'L
diii'E :: QuasiQuoter
diii'E :: QuasiQuoter
diii'E = Name -> QuasiQuoter -> QuasiQuoter
wrapper 'diii'E QuasiQuoter
iii'E
diii'L :: QuasiQuoter
diii'L :: QuasiQuoter
diii'L = Name -> QuasiQuoter -> QuasiQuoter
wrapper 'diii'L QuasiQuoter
iii'L
d__i'E :: QuasiQuoter
d__i'E :: QuasiQuoter
d__i'E = Name -> QuasiQuoter -> QuasiQuoter
wrapper 'd__i'E QuasiQuoter
__i'E
{-# DEPRECATED d__i'E "'d__i'E' is a deprecated alias for '__di'E' and will be removed in prettyprinter-interp 0.3" #-}
d__i'L :: QuasiQuoter
d__i'L :: QuasiQuoter
d__i'L = Name -> QuasiQuoter -> QuasiQuoter
wrapper 'd__i'L QuasiQuoter
__i'L
{-# DEPRECATED d__i'L "'d__i'L' is a deprecated alias for '__di'L' and will be removed in prettyprinter-interp 0.3" #-}
errQQ :: Name -> String -> Q a
errQQ :: Name -> String -> Q a
errQQ Name
nm String
msg = String -> Q a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Q a) -> String -> Q a
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Show a => a -> String
show Name
nm String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
": " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
msg
errQQType :: Name -> String -> Q a
errQQType :: Name -> String -> Q a
errQQType Name
nm String
ty = Name -> String -> Q a
forall a. Name -> String -> Q a
errQQ Name
nm (String -> Q a) -> String -> Q a
forall a b. (a -> b) -> a -> b
$ String
"This QuasiQuoter cannot be used as a " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
ty