-
Notifications
You must be signed in to change notification settings - Fork 11
/
Main.hs
29 lines (24 loc) · 1.26 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Main (main) where
import Control.Monad (forM, when)
import qualified Options.Applicative as OptParse
import System.Exit (exitFailure)
import qualified Text.Parsec.Pos as Pos
import Text.PrettyPrint.ANSI.Leijen (Pretty (..))
import Infernu.Options (Options (..), opts)
import Infernu.Types (QualType)
import Infernu.Source (Source(..))
import Infernu.Util
import Infernu.Prelude
process :: [(Source, QualType)] -> [(Pos.SourceName, [String])] -> String
process ts sourceCodes = concatMap (\(f, ds) -> annotatedSource (filteredTypes f ts) ds) sourceCodes
where filteredTypes f' = filter (\(Source (_, p), _) -> (Pos.sourceName p == f'))
main :: IO ()
main = do
options <- OptParse.execParser opts
let files = optFileNames options
res <- checkFiles options files
case res of
Right ts -> when (not $ optQuiet options) $ do sourceCodes <- forM files $ \f -> do d <- readFile f
return (f, lines d)
putStrLn $ process ts sourceCodes
Left e -> putStrLn (show $ pretty e) >> exitFailure