dhall-check 1.0.0.1 → 1.1.0.0
raw patch · 2 files changed
+15/−15 lines, 2 files
Files
- dhall-check.cabal +1/−1
- src/Main.hs +14/−14
dhall-check.cabal view
@@ -1,5 +1,5 @@ name: dhall-check-version: 1.0.0.1+version: 1.1.0.0 cabal-version: >=1.10 build-type: Simple license: BSD3
src/Main.hs view
@@ -40,13 +40,17 @@ -- >>> dhallTypeOf "file.entry.dh" -- DhallType "entry" dhallTypeOf :: FilePath -> DhallType-dhallTypeOf = DhallType . tail . map toLower . takeExtension . dropExtension+dhallTypeOf f =+ case takeExtension . dropExtension $ f of+ "" -> throw $ WithoutType f+ (_:xs) -> DhallType . map toLower $ xs data CheckException = CouldntFindTypeDefs | ParseException FilePath ParseError | UnknownType FilePath DhallType+ | WithoutType FilePath | TypeChecking FilePath (TypeError Src) deriving (Show) @@ -59,6 +63,8 @@ "While parsing " ++ f ++ ":" ++ displayException pe displayException (TypeChecking f te) = "While type checking " ++ f ++ ":" ++ displayException te+ displayException (WithoutType f) =+ "The file " ++ f ++ " seems to have no type associated with it." main :: IO ()@@ -67,11 +73,8 @@ printExceptions $ do typedefs <- allTypeDefs here dhallfiles <- allDhallFiles here- -- Check all files once- printExceptions $ do- checkAll typedefs dhallfiles- putStrLn "No errors."- -- and then watch for changes+ forM_ dhallfiles $ printExceptions . checkFile typedefs+ putStrLn "Watching for changes.." withManager $ \mgr -> do watchTree mgr here isDhallFile $ \event -> do case event of@@ -97,7 +100,7 @@ Left e -> putStrLn $ displayException (e :: CheckException) Right v -> pure v - isDhallFile f = (flip elem [".dhall", ".dh"] . takeExtension . eventPath) f+ isDhallFile f = ((==".dh") . takeExtension . eventPath) f && (not . (==) '.' . head . takeFileName . eventPath) f @@ -137,7 +140,7 @@ -- | Get all a list of all dhall files in the given directory using absolute paths. allDhallFiles :: FilePath -> IO [(FilePath, Expr Src X)] allDhallFiles dir = do- files <- allFiles dir [".dh", ".dhall"]+ files <- allFiles dir [".dh"] forM files $ \f -> do sequence (f, loadFile f) @@ -149,7 +152,9 @@ content <- TLIO.readFile f case exprFromText delta content of Left e -> throwIO $ ParseException f e- Right e -> load e+ Right e -> do+ setCurrentDirectory (takeDirectory f)+ load e -- | Typecheck a single file against one of the given types.@@ -173,8 +178,3 @@ case typeOf annot of Left err -> throwIO $ TypeChecking f err Right _ -> pure ()----- | Perform 'checkFile' on every file in the Foldable.-checkAll :: Foldable t => Map DhallType (Expr Src X) -> t (FilePath, Expr Src X) -> IO ()-checkAll types = mapM_ (checkFile types)