module Hhp.Check (
checkSyntax
, check
, expandTemplate
, expand
) where
import DynFlags (dopt_set, DumpFlag(Opt_D_dump_splices))
import GHC (Ghc, DynFlags(..))
import Hhp.GHCApi
import Hhp.Logger
import Hhp.Types
checkSyntax :: Options
-> Cradle
-> [FilePath]
-> IO String
checkSyntax _ _ [] = return ""
checkSyntax opt cradle files = withGHC sessionName $ do
initializeFlagsWithCradle opt cradle
either id id <$> check opt files
where
sessionName = case files of
[file] -> file
_ -> "MultipleFiles"
check :: Options
-> [FilePath]
-> Ghc (Either String String)
check opt fileNames = withLogger opt (setAllWaringFlags . setPartialSignatures . setDeferTypedHoles) $
setTargetFiles fileNames
expandTemplate :: Options
-> Cradle
-> [FilePath]
-> IO String
expandTemplate _ _ [] = return ""
expandTemplate opt cradle files = withGHC sessionName $ do
initializeFlagsWithCradle opt cradle
either id id <$> expand opt files
where
sessionName = case files of
[file] -> file
_ -> "MultipleFiles"
expand :: Options
-> [FilePath]
-> Ghc (Either String String)
expand opt fileNames = withLogger opt (setDumpSplices . setNoWaringFlags) $
setTargetFiles fileNames
setDumpSplices :: DynFlags -> DynFlags
setDumpSplices dflag = dopt_set dflag Opt_D_dump_splices