hindent 5.2.4 → 5.2.4.1
raw patch · 4 files changed
+101/−120 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- hindent.cabal +1/−1
- src/HIndent/Pretty.hs +2/−1
- src/main/Main.hs +0/−20
- src/main/Path/Find.hs +98/−98
hindent.cabal view
@@ -1,5 +1,5 @@ name: hindent-version: 5.2.4+version: 5.2.4.1 synopsis: Extensible Haskell pretty printer description: Extensible Haskell pretty printer. Both a library and an executable. .
src/HIndent/Pretty.hs view
@@ -628,7 +628,8 @@ write " of") if null alts then write " {}"- else do indentedBlock (lined (map (withCaseContext True . pretty) alts))+ else do newline+ indentedBlock (lined (map (withCaseContext True . pretty) alts)) exp (Do _ stmts) = depend (write "do ") (lined (map pretty stmts))
src/main/Main.hs view
@@ -72,26 +72,6 @@ Failed (Wrap (Stopped Help) _) -> putStrLn (help defaultConfig) _ -> error (help defaultConfig) --- -- | Main entry point.--- testformat :: [String] -> IO ()--- testformat args = do--- config <- getConfig--- case consume (options config) (map T.pack args) of--- Succeeded (style, exts, mfilepath) ->--- case mfilepath of--- Just filepath -> do--- text <- S.readFile filepath--- case reformat style (Just exts) text of--- Left e -> error (filepath ++ ": " ++ e)--- Right out -> L8.putStrLn (S.toLazyByteString out)--- Nothing ->--- L8.interact--- (either error S.toLazyByteString . reformat style (Just exts) . L8.toStrict)--- Failed (Wrap (Stopped Version) _) ->--- putStrLn ("hindent " ++ showVersion version)--- Failed (Wrap (Stopped Help) _) -> putStrLn (help defaultConfig)--- _ -> error (help defaultConfig)- -- | Read config from a config file, or return 'defaultConfig'. getConfig :: IO Config getConfig = do
src/main/Path/Find.hs view
@@ -1,98 +1,98 @@-{-# LANGUAGE DataKinds #-} - --- | Finding files. - --- Lifted from Stack. - -module Path.Find - (findFileUp - ,findDirUp - ,findFiles - ,findInParents) - where - -import Control.Exception (evaluate) -import Control.DeepSeq (force) -import Control.Monad -import Control.Monad.Catch -import Control.Monad.IO.Class -import System.IO.Error (isPermissionError) -import Data.List -import Path -import Path.IO hiding (findFiles) -import System.PosixCompat.Files (getSymbolicLinkStatus, isSymbolicLink) - --- | Find the location of a file matching the given predicate. -findFileUp :: (MonadIO m,MonadThrow m) - => Path Abs Dir -- ^ Start here. - -> (Path Abs File -> Bool) -- ^ Predicate to match the file. - -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory. - -> m (Maybe (Path Abs File)) -- ^ Absolute file path. -findFileUp = findPathUp snd - --- | Find the location of a directory matching the given predicate. -findDirUp :: (MonadIO m,MonadThrow m) - => Path Abs Dir -- ^ Start here. - -> (Path Abs Dir -> Bool) -- ^ Predicate to match the directory. - -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory. - -> m (Maybe (Path Abs Dir)) -- ^ Absolute directory path. -findDirUp = findPathUp fst - --- | Find the location of a path matching the given predicate. -findPathUp :: (MonadIO m,MonadThrow m) - => (([Path Abs Dir],[Path Abs File]) -> [Path Abs t]) - -- ^ Choose path type from pair. - -> Path Abs Dir -- ^ Start here. - -> (Path Abs t -> Bool) -- ^ Predicate to match the path. - -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory. - -> m (Maybe (Path Abs t)) -- ^ Absolute path. -findPathUp pathType dir p upperBound = - do entries <- listDir dir - case find p (pathType entries) of - Just path -> return (Just path) - Nothing | Just dir == upperBound -> return Nothing - | parent dir == dir -> return Nothing - | otherwise -> findPathUp pathType (parent dir) p upperBound - --- | Find files matching predicate below a root directory. --- --- NOTE: this skips symbolic directory links, to avoid loops. This may --- not make sense for all uses of file finding. --- --- TODO: write one of these that traverses symbolic links but --- efficiently ignores loops. -findFiles :: Path Abs Dir -- ^ Root directory to begin with. - -> (Path Abs File -> Bool) -- ^ Predicate to match files. - -> (Path Abs Dir -> Bool) -- ^ Predicate for which directories to traverse. - -> IO [Path Abs File] -- ^ List of matching files. -findFiles dir p traversep = - do (dirs,files) <- catchJust (\ e -> if isPermissionError e - then Just () - else Nothing) - (listDir dir) - (\ _ -> return ([], [])) - filteredFiles <- evaluate $ force (filter p files) - filteredDirs <- filterM (fmap not . isSymLink) dirs - subResults <- - forM filteredDirs - (\entry -> - if traversep entry - then findFiles entry p traversep - else return []) - return (concat (filteredFiles : subResults)) - -isSymLink :: Path Abs t -> IO Bool -isSymLink = fmap isSymbolicLink . getSymbolicLinkStatus . toFilePath - --- | @findInParents f path@ applies @f@ to @path@ and its 'parent's until --- it finds a 'Just' or reaches the root directory. -findInParents :: MonadIO m => (Path Abs Dir -> m (Maybe a)) -> Path Abs Dir -> m (Maybe a) -findInParents f path = do - mres <- f path - case mres of - Just res -> return (Just res) - Nothing -> do - let next = parent path - if next == path - then return Nothing - else findInParents f next +{-# LANGUAGE DataKinds #-}++-- | Finding files.++-- Lifted from Stack.++module Path.Find+ (findFileUp+ ,findDirUp+ ,findFiles+ ,findInParents)+ where++import Control.Exception (evaluate)+import Control.DeepSeq (force)+import Control.Monad+import Control.Monad.Catch+import Control.Monad.IO.Class+import System.IO.Error (isPermissionError)+import Data.List+import Path+import Path.IO hiding (findFiles)+import System.PosixCompat.Files (getSymbolicLinkStatus, isSymbolicLink)++-- | Find the location of a file matching the given predicate.+findFileUp :: (MonadIO m,MonadThrow m)+ => Path Abs Dir -- ^ Start here.+ -> (Path Abs File -> Bool) -- ^ Predicate to match the file.+ -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.+ -> m (Maybe (Path Abs File)) -- ^ Absolute file path.+findFileUp = findPathUp snd++-- | Find the location of a directory matching the given predicate.+findDirUp :: (MonadIO m,MonadThrow m)+ => Path Abs Dir -- ^ Start here.+ -> (Path Abs Dir -> Bool) -- ^ Predicate to match the directory.+ -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.+ -> m (Maybe (Path Abs Dir)) -- ^ Absolute directory path.+findDirUp = findPathUp fst++-- | Find the location of a path matching the given predicate.+findPathUp :: (MonadIO m,MonadThrow m)+ => (([Path Abs Dir],[Path Abs File]) -> [Path Abs t])+ -- ^ Choose path type from pair.+ -> Path Abs Dir -- ^ Start here.+ -> (Path Abs t -> Bool) -- ^ Predicate to match the path.+ -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.+ -> m (Maybe (Path Abs t)) -- ^ Absolute path.+findPathUp pathType dir p upperBound =+ do entries <- listDir dir+ case find p (pathType entries) of+ Just path -> return (Just path)+ Nothing | Just dir == upperBound -> return Nothing+ | parent dir == dir -> return Nothing+ | otherwise -> findPathUp pathType (parent dir) p upperBound++-- | Find files matching predicate below a root directory.+--+-- NOTE: this skips symbolic directory links, to avoid loops. This may+-- not make sense for all uses of file finding.+--+-- TODO: write one of these that traverses symbolic links but+-- efficiently ignores loops.+findFiles :: Path Abs Dir -- ^ Root directory to begin with.+ -> (Path Abs File -> Bool) -- ^ Predicate to match files.+ -> (Path Abs Dir -> Bool) -- ^ Predicate for which directories to traverse.+ -> IO [Path Abs File] -- ^ List of matching files.+findFiles dir p traversep =+ do (dirs,files) <- catchJust (\ e -> if isPermissionError e+ then Just ()+ else Nothing)+ (listDir dir)+ (\ _ -> return ([], []))+ filteredFiles <- evaluate $ force (filter p files)+ filteredDirs <- filterM (fmap not . isSymLink) dirs+ subResults <-+ forM filteredDirs+ (\entry ->+ if traversep entry+ then findFiles entry p traversep+ else return [])+ return (concat (filteredFiles : subResults))++isSymLink :: Path Abs t -> IO Bool+isSymLink = fmap isSymbolicLink . getSymbolicLinkStatus . toFilePath++-- | @findInParents f path@ applies @f@ to @path@ and its 'parent's until+-- it finds a 'Just' or reaches the root directory.+findInParents :: MonadIO m => (Path Abs Dir -> m (Maybe a)) -> Path Abs Dir -> m (Maybe a)+findInParents f path = do+ mres <- f path+ case mres of+ Just res -> return (Just res)+ Nothing -> do+ let next = parent path+ if next == path+ then return Nothing+ else findInParents f next