hsimport 0.6.6 → 0.6.7
raw patch · 3 files changed
+49/−23 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG +8/−0
- hsimport.cabal +2/−2
- lib/HsImport/Parse.hs +39/−21
CHANGELOG view
@@ -1,3 +1,11 @@+0.6.7+-----+* More robust handling of invalid Haskell source code++0.6.6+-----+* Raise upper bounds of dependencies+ 0.6.5 ----- * Support GHC 7.10.1
hsimport.cabal view
@@ -1,5 +1,5 @@ name: hsimport-version: 0.6.6+version: 0.6.7 cabal-version: >=1.9.2 build-type: Simple license: BSD3@@ -10,7 +10,7 @@ A command line program for extending the import list of a Haskell source file. category: Utils, Development author: Daniel Trstenjak-tested-with: GHC ==7.6.2 GHC ==7.6.3 GHC ==7.8.3 GHC ==7.10.1+tested-with: GHC ==7.6.2 GHC ==7.6.3 GHC ==7.8.3 GHC ==7.10.1 GHC ==7.10.2 extra-source-files: README.md CHANGELOG
lib/HsImport/Parse.hs view
@@ -26,12 +26,12 @@ HS.ParseOk _ -> return $ Right result HS.ParseFailed srcLoc _ -> do- srcResult <- parseInvalidSource (lines srcFile) (HS.srcLine srcLoc) 0 (HS.srcLine srcLoc)+ srcResult <- parseInvalidSource (lines srcFile) (HS.srcLine srcLoc) return $ Right $ fromMaybe result srcResult) (\(e :: SomeException) -> do let srcLines = lines srcFile- srcResult <- parseInvalidSource srcLines (length srcLines) 0 (length srcLines)+ srcResult <- parseInvalidSource srcLines (length srcLines) return $ maybe (Left $ show e) Right srcResult) where -- | replace CPP directives by a fake comment@@ -96,27 +96,45 @@ -- | tries to find the maximal part of the source file (from the beginning) that contains -- valid/complete Haskell code-parseInvalidSource :: [String] -> Int -> Int -> Int -> IO (Maybe (HS.ParseResult HS.Module))-parseInvalidSource srcLines firstInvalidLine lastValidLine currLastLine- | null srcLines || lastValidLine >= currLastLine = return Nothing- | otherwise =- catch (case parseFileContents source of- result@(HS.ParseOk _)- | (nextLine + 1) == currLastLine ->- return $ Just result- | otherwise ->- parseInvalidSource srcLines firstInvalidLine nextLine currLastLine+parseInvalidSource :: [String] -> Int -> IO (Maybe (HS.ParseResult HS.Module))+parseInvalidSource srcLines firstInvalidLine = do+ parseInvalidSource' 1 firstInvalidLine Nothing 0+ where+ parseInvalidSource' :: Int -> Int -> Maybe (Int, HS.ParseResult HS.Module) -> Int -> IO (Maybe (HS.ParseResult HS.Module))+ parseInvalidSource' lastValidLine currLastLine maxParseOk iteration+ | null srcLines || lastValidLine >= currLastLine+ = return Nothing - HS.ParseFailed srcLoc _- | HS.srcLine srcLoc == firstInvalidLine ->- parseInvalidSource srcLines firstInvalidLine lastValidLine nextLine- | otherwise ->- parseInvalidSource srcLines firstInvalidLine nextLine currLastLine)+ | iteration >= 10+ = return (snd <$> maxParseOk) - (\(_ :: SomeException) -> parseInvalidSource srcLines firstInvalidLine lastValidLine nextLine)- where- source = unlines $ take (nextLine + 1) srcLines- nextLine = lastValidLine + (floor ((realToFrac (currLastLine - lastValidLine) / 2) :: Double) :: Int)+ | otherwise = do+ catch (case parseFileContents source of+ result@(HS.ParseOk _)+ | nextLine == currLastLine ->+ return $ Just result+ | otherwise ->+ parseInvalidSource' nextLine currLastLine (maxParseOk' result) iteration'++ HS.ParseFailed srcLoc _+ | HS.srcLine srcLoc == firstInvalidLine ->+ parseInvalidSource' lastValidLine nextLine maxParseOk iteration'+ | otherwise ->+ parseInvalidSource' nextLine currLastLine maxParseOk iteration')++ (\(_ :: SomeException) -> parseInvalidSource' lastValidLine nextLine maxParseOk iteration')+ where+ source = unlines $ take nextLine srcLines+ nextLine = lastValidLine + (floor ((realToFrac (currLastLine - lastValidLine) / 2) :: Double) :: Int)+ iteration' = iteration + 1++ maxParseOk' nextResult =+ case maxParseOk of+ Just (maxLine, _)+ | nextLine > maxLine -> Just (nextLine, nextResult)+ | otherwise -> maxParseOk++ _ -> Just (nextLine, nextResult) parseFileContents :: String -> HS.ParseResult HS.Module