cspmchecker 0.1 → 0.1.1
raw patch · 3 files changed
+90/−37 lines, 3 filesdep ~libcspm
Dependency ranges changed: libcspm
Files
- cspmchecker.cabal +22/−20
- src/Checker/Main.hs +29/−17
- src/Checker/Monad.hs +39/−0
cspmchecker.cabal view
@@ -10,7 +10,7 @@ Build-type: Simple Cabal-version: >=1.9.2 Synopsis: A command line type checker for CSPM files.-Version: 0.1+Version: 0.1.1 Source-Repository head type: git@@ -21,29 +21,31 @@ type: git location: git://github.com/tomgr/libcspm.git subdir: cspmchecker- tag: 0.1+ tag: release-0.1.1 Executable cspmchecker- Main-is: Main.hs- - Build-depends: - base >= 4 && < 5,- libcspm,- filepath >= 1.2,- mtl >= 2.0,- directory >= 1.0+ Main-is: Main.hs+ Other-modules: Monad - Hs-Source-Dirs: src/Checker+ Build-depends: + base >= 4 && < 5,+ libcspm >= 0.1.1,+ filepath >= 1.2,+ mtl >= 2.0,+ directory >= 1.0+ + Hs-Source-Dirs: src/Checker --Executable cspmcheckeri--- Main-is: Main.hs+-- Main-is: Main.hs+-- Other-modules: Monad -- --- Build-depends: --- base >= 4 && < 5,--- libcspm,--- filepath >= 1.2, --- mtl >= 2.0,--- directory >= 1.0,--- haskeline >= 0.6+-- Build-depends: +-- base >= 4 && < 5,+-- libcspm,+-- filepath >= 1.2, +-- mtl >= 2.0,+-- directory >= 1.0,+-- haskeline >= 0.6 -- --- Hs-Source-Dirs: src/InteractiveChecker+-- Hs-Source-Dirs: src/InteractiveChecker
src/Checker/Main.hs view
@@ -11,6 +11,9 @@ import System.Exit import System.IO +import qualified Paths_cspmchecker as C+import Data.Version (showVersion)+ import CSPM import CSPM.PrettyPrinter import Monad@@ -66,15 +69,20 @@ data Options = Options { recursive :: Bool,- help :: Bool+ help :: Bool,+ printVersion :: Bool } defaultOptions = Options { recursive = False, - help = False + help = False,+ printVersion = False } options :: [OptDescr (Options -> Options)] options = [+ Option ['v'] ["version"] + (NoArg (\o -> o { printVersion = True }))+ "Print out the version number", Option ['r'] ["recursive"] (NoArg (\o -> o { recursive = True })) "If the input file is a directory, check all files contained in all subdirectories",@@ -90,18 +98,22 @@ main = do args <- getArgs st <- initSfdrState- runSfdr st $ - case getOpt RequireOrder options args of- (_,_,e:es) -> liftIO $ putStr $ concat (e:es) ++ usageInfo header options- (o,files, []) -> do- let opts = foldl (flip id) defaultOptions o- case (opts, files) of- (_, []) -> - liftIO $ putStr $ usageInfo header options- (Options { help = True }, files) -> - liftIO $ putStr $ usageInfo header options- (Options { recursive = True }, dirs) -> do- tasks <- mapM (liftIO . getFilesFromDir) dirs- countSuccesses (map doFile (concat tasks))- (_, files) -> - countSuccesses (map doFile files)+ runSfdr st $ case getOpt RequireOrder options args of+ (_,_,e:es) -> liftIO $ putStr $ show $ concat (e:es) ++ usageInfo header options+ (o,files, []) -> do+ let opts = foldl (flip id) defaultOptions o+ case (opts, files) of+ (Options { printVersion = True }, []) ->+ liftIO $ putStrLn $ show $ + text "cspmchecker version" <+> text (showVersion C.version)+ $$+ text "using libcspm version" <+> text (showVersion getLibCSPMVersion)+ (Options { help = True }, []) -> + liftIO $ putStr $ usageInfo header options+ (Options { recursive = True }, dirs) -> do+ tasks <- mapM (liftIO . getFilesFromDir) dirs+ countSuccesses (map doFile (concat tasks))+ (_, []) -> + liftIO $ putStr $ usageInfo header options+ (_, files) -> + countSuccesses (map doFile files)
+ src/Checker/Monad.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}+module Monad where++import Control.Monad.State++import CSPM+import Util.Exception+import Util.PrettyPrint++data SfdrState = SfdrState {+ cspmSession :: CSPMSession,+ lastWarnings :: [ErrorMessage]+ }++initSfdrState :: IO SfdrState+initSfdrState = do+ sess <- newCSPMSession+ return $ SfdrState sess []++resetCSPM :: Sfdr ()+resetCSPM = do+ sess <- liftIO $ newCSPMSession+ modify (\st -> st { cspmSession = sess, lastWarnings = [] })++type Sfdr = StateT SfdrState IO++runSfdr :: SfdrState -> Sfdr a -> IO a+runSfdr st a = runStateT a st >>= return . fst++getState :: (SfdrState -> a) -> Sfdr a+getState = gets++modifyState :: (SfdrState -> SfdrState) -> Sfdr ()+modifyState = modify++instance CSPMMonad Sfdr where+ getSession = gets cspmSession+ setSession s = modify (\ st -> st { cspmSession = s })+ handleWarnings ws = modify (\ st -> st { lastWarnings = ws })