-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depend on Cabal for dependency parsing
- Loading branch information
Showing
8 changed files
with
185 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{-# LANGUAGE CPP #-} | ||
module Hpack.Dependency ( | ||
parseDependency | ||
) where | ||
|
||
import Prelude () | ||
import Prelude.Compat | ||
|
||
import Text.PrettyPrint (renderStyle, Style(..), Mode(..)) | ||
import qualified Distribution.Compat.ReadP as D | ||
import qualified Distribution.Package as D | ||
import qualified Distribution.Text as D | ||
import qualified Distribution.Version as D | ||
|
||
dependencyName :: D.Dependency -> String | ||
#if MIN_VERSION_Cabal(2,0,0) | ||
dependencyName = D.unPackageName . D.depPkgName | ||
#else | ||
dependencyName (D.Dependency (D.PackageName name) _) = name | ||
#endif | ||
|
||
dependencyVersionRange :: D.Dependency -> D.VersionRange | ||
#if MIN_VERSION_Cabal(2,0,0) | ||
dependencyVersionRange = D.depVerRange | ||
#else | ||
dependencyVersionRange (D.Dependency _ versionRange) = versionRange | ||
#endif | ||
|
||
parseDependency :: Monad m => String -> m (String, Maybe String) | ||
parseDependency = fmap render . parseCabalDependency | ||
where | ||
render :: D.Dependency -> (String, Maybe String) | ||
render d = (name, range) | ||
where | ||
name = dependencyName d | ||
versionRange = dependencyVersionRange d | ||
|
||
range | ||
| D.isAnyVersion versionRange = Nothing | ||
| otherwise = Just . renderStyle style . D.disp $ versionRange | ||
where | ||
style = Style OneLineMode 0 0 | ||
|
||
parseCabalDependency :: Monad m => String -> m D.Dependency | ||
parseCabalDependency s = case [d | (d, "") <- D.readP_to_S D.parse s] of | ||
[d] -> return d | ||
_ -> fail $ "invalid dependency " ++ show s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.