Browse files

Import datatype from Cabal 1.5

Instead of depending on the yet unstable cabal 1.5, import the
Distribution.Package.PackageName and call it PN.
This also required some modification of the surrounding code.
  • Loading branch information...
1 parent 494fa91 commit 3125bdce7bab9bfb04a92f90c195dc13f9f74260 @kolmodin kolmodin committed Sep 4, 2008
Showing with 21 additions and 6 deletions.
  1. +21 −6 Portage/PackageId.hs
@@ -16,27 +16,42 @@ import Distribution.Text (Text(..))
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>))
-import qualified Data.Char as Char (isAlphaNum, toLower)
+import qualified Data.Char as Char (isAlphaNum, isDigit, toLower)
+import Data.List (intersperse)
newtype Category = Category String
deriving (Eq, Ord, Show, Read)
-data PackageName = PackageName Category Cabal.PackageName
+data PackageName = PackageName Category PN
deriving (Eq, Ord, Show, Read)
data PackageId = PackageId PackageName Portage.Version
deriving (Eq, Ord, Show, Read)
+data PN = PN String -- replace with Cabal.PackageName once we use Cabal>=1.5
+ deriving (Eq, Ord, Show, Read)
+instance Text PN where
+ disp (PN n) = Disp.text n
+ parse = do
+ ns <- Parse.sepBy1 component (Parse.char '-')
+ return (PN (concat (intersperse "-" ns)))
+ where
+ component = do
+ cs <- Parse.munch1 Char.isAlphaNum
+ if all Char.isDigit cs then Parse.pfail else return cs
+ -- each component must contain an alphabetic character, to avoid
+ -- ambiguity in identifiers like foo-1 (the 1 is the version number).
fromCabalPackageId :: Category -> Cabal.PackageIdentifier -> PackageId
fromCabalPackageId category (Cabal.PackageIdentifier name version) =
- PackageId (PackageName category (lowercase name))
+ PackageId (PackageName category (PN (lowercase name)))
(Portage.fromCabalVersion version)
- lowercase (Cabal.PackageName n) = Cabal.PackageName (map Char.toLower n)
+ lowercase = map Char.toLower
toCabalPackageId :: PackageId -> Maybe Cabal.PackageIdentifier
-toCabalPackageId (PackageId (PackageName _cat name) version) =
+toCabalPackageId (PackageId (PackageName _cat (PN name)) version) =
fmap (Cabal.PackageIdentifier name) (Portage.toCabalVersion version)
instance Text Category where

0 comments on commit 3125bdc

Please sign in to comment.