module CustomInterpolation.Config where
import Data.Default.Class (Default (..))
import Language.Haskell.TH (Exp, Q, appE)
data InterpolationConfig a = InterpolationConfig
{
forall a. InterpolationConfig a -> [Interpolator a]
handlers :: [Interpolator a],
forall a. InterpolationConfig a -> ([a], Q Exp) -> Q Exp
finalize :: ([a], Q Exp) -> Q Exp,
forall a. InterpolationConfig a -> Char -> Char
escape :: Char -> Char
}
simpleConfig :: InterpolationConfig ()
simpleConfig :: InterpolationConfig ()
simpleConfig = forall a. InterpolationConfig a
defaultConfig
defaultConfig :: InterpolationConfig a
defaultConfig :: forall a. InterpolationConfig a
defaultConfig = InterpolationConfig {handlers :: [Interpolator a]
handlers = [], finalize :: ([a], Q Exp) -> Q Exp
finalize = forall a b. (a, b) -> b
snd, escape :: Char -> Char
escape = forall a. a -> a
id}
instance Default (InterpolationConfig a) where
def :: InterpolationConfig a
def = forall a. InterpolationConfig a
defaultConfig
data Interpolator a = Interpolator
{
forall a. Interpolator a -> Prefix
prefix :: Prefix,
forall a. Interpolator a -> Q Exp -> (a, Q Exp)
handler :: Q Exp -> (a, Q Exp),
forall a. Interpolator a -> Brackets
brackets :: Brackets
}
type Prefix = String
data Brackets = Brackets {Brackets -> Char
opening :: Char, Brackets -> Char
closing :: Char} deriving (Int -> Brackets -> ShowS
[Brackets] -> ShowS
Brackets -> Prefix
forall a.
(Int -> a -> ShowS) -> (a -> Prefix) -> ([a] -> ShowS) -> Show a
showList :: [Brackets] -> ShowS
$cshowList :: [Brackets] -> ShowS
show :: Brackets -> Prefix
$cshow :: Brackets -> Prefix
showsPrec :: Int -> Brackets -> ShowS
$cshowsPrec :: Int -> Brackets -> ShowS
Show)
curlyBrackets :: Brackets
curlyBrackets :: Brackets
curlyBrackets = Char -> Char -> Brackets
Brackets Char
'{' Char
'}'
roundBrackets :: Brackets
roundBrackets :: Brackets
roundBrackets = Char -> Char -> Brackets
Brackets Char
'(' Char
')'
squareBrackets :: Brackets
squareBrackets :: Brackets
squareBrackets = Char -> Char -> Brackets
Brackets Char
'[' Char
']'
angleBrackets :: Brackets
angleBrackets :: Brackets
angleBrackets = Char -> Char -> Brackets
Brackets Char
'<' Char
'>'
simpleInterpolator :: Interpolator ()
simpleInterpolator :: Interpolator ()
simpleInterpolator = Interpolator {prefix :: Prefix
prefix = Prefix
"", handler :: Q Exp -> ((), Q Exp)
handler = forall (f :: * -> *) a. Applicative f => a -> f a
pure, brackets :: Brackets
brackets = Brackets
curlyBrackets}
applyInterpolator :: Monoid a => Q Exp -> Interpolator a
applyInterpolator :: forall a. Monoid a => Q Exp -> Interpolator a
applyInterpolator Q Exp
funExp = Interpolator ()
simpleInterpolator {handler :: Q Exp -> (a, Q Exp)
handler = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Quote m => m Exp -> m Exp -> m Exp
appE Q Exp
funExp}