ghc-mod/Check.hs

45 lines
1.3 KiB
Haskell
Raw Normal View History

2010-03-11 10:03:17 +00:00
module Check (checkSyntax) where
import Control.Applicative
2010-03-11 15:20:02 +00:00
import Control.Monad
2010-03-11 10:03:17 +00:00
import Data.Char
import Data.List
2010-03-11 13:39:07 +00:00
import Param
2010-03-11 15:20:02 +00:00
import System.Directory
import System.FilePath
2010-03-11 10:03:17 +00:00
import System.IO
import System.Process
----------------------------------------------------------------
2010-03-11 13:39:07 +00:00
checkSyntax :: Options -> String -> IO String
checkSyntax opt file = do
2010-03-11 15:20:02 +00:00
makeDirectory (outDir opt)
(_,_,herr,_) <- runInteractiveProcess (ghc opt) ["--make","-Wall",file,"-outputdir","dist/flymake","-o","dist/flymake/a.out"] Nothing Nothing
2010-03-11 10:03:17 +00:00
refine <$> hGetContents herr
where
refine = unfoldLines start . map (dropWhile isSpace) . filter (/="") . lines
start = (file `isPrefixOf`)
unfoldLines :: (String -> Bool) -> [String] -> String
2010-03-11 13:39:07 +00:00
unfoldLines _ [] = ""
unfoldLines p (x:xs) = x ++ unfold xs
2010-03-11 10:03:17 +00:00
where
unfold [] = "\n"
unfold (l:ls)
| p l = ('\n':l) ++ unfold ls
2010-03-11 10:12:15 +00:00
| otherwise = (' ' :l) ++ unfold ls
2010-03-11 15:20:02 +00:00
----------------------------------------------------------------
makeDirectory :: FilePath -> IO ()
makeDirectory dir = makeDirectoryRecur $ normalise dir
where
makeDirectoryRecur "" = return ()
makeDirectoryRecur cur = do
exist <- doesDirectoryExist cur
let par = takeDirectory cur
unless exist $ do
makeDirectoryRecur par
createDirectory cur