{-# LANGUAGE CPP, TemplateHaskell #-} module HMGit.Development.TH ( relativeProjRoot ) where import Control.Monad ((>=>)) import Data.FileEmbed (makeRelativeToProject) import Data.String (fromString) import Language.Haskell.TH.Syntax #ifndef MIN_VERSION_template_haskell #define MIN_VERSION_template_haskell(x,y,z) 0 #endif strToExp :: String -> Q Exp #if MIN_VERSION_template_haskell(2, 5, 0) strToExp :: String -> Q Exp strToExp String s = Exp -> Q Exp forall (m :: * -> *) a. Monad m => a -> m a return (Exp -> Q Exp) -> Exp -> Q Exp forall a b. (a -> b) -> a -> b $ Name -> Exp VarE 'fromString Exp -> Exp -> Exp `AppE` Lit -> Exp LitE (String -> Lit StringL String s) #else strToExp s = do helper <- [| fromString |] return $! AppE helper $! LitE $! StringL s #endif relativeProjRoot :: FilePath -> Q Exp relativeProjRoot :: String -> Q Exp relativeProjRoot = String -> Q String makeRelativeToProject (String -> Q String) -> (String -> Q Exp) -> String -> Q Exp forall (m :: * -> *) a b c. Monad m => (a -> m b) -> (b -> m c) -> a -> m c >=> String -> Q Exp strToExp