Skip to content

Commit

Permalink
feat: move ghcpkgid to cabal's unitid
Browse files Browse the repository at this point in the history
  • Loading branch information
theobat authored and mpilgrem committed Jun 22, 2024
1 parent b403d1b commit cc2a57f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Stack/Types/GhcPkgId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Data.Char ( isAlphaNum )
import Data.Hashable ( Hashable(..) )
import Database.Persist.Sql ( PersistField (..), PersistFieldSql (..) )
import Distribution.Compat.Binary ( decode, encode )
import Distribution.Utils.ShortText ( ShortText, toShortText, fromShortText )
import Stack.Prelude
import Text.Read ( Read (..) )
import Distribution.Types.UnitId (UnitId, mkUnitId, unUnitId)

-- | A parse fail.
newtype GhcPkgIdParseFail
Expand All @@ -37,7 +37,7 @@ instance Exception GhcPkgIdParseFail where

-- | A ghc-pkg package identifier.
newtype GhcPkgId
= GhcPkgId ShortText
= GhcPkgId UnitId
deriving (Data, Eq, Generic, Ord, Typeable)

instance PersistField GhcPkgId where
Expand All @@ -56,7 +56,7 @@ instance Show GhcPkgId where
show = show . ghcPkgIdString

instance Read GhcPkgId where
readsPrec i = map (first (GhcPkgId . toShortText)) . readsPrec i
readsPrec i = map (first (GhcPkgId . mkUnitId)) . readsPrec i

instance FromJSON GhcPkgId where
parseJSON = withText "GhcPkgId" $ \t ->
Expand All @@ -80,7 +80,7 @@ parseGhcPkgId x = go x
ghcPkgIdParser :: Parser GhcPkgId
ghcPkgIdParser =
let elements = "_.-" :: String
in GhcPkgId . toShortText <$>
in GhcPkgId . mkUnitId <$>
many1 (choice [alphaNum, satisfy (`elem` elements)])

-- | Parse an alphanumerical character, as recognised by `isAlphaNum`.
Expand All @@ -90,7 +90,7 @@ alphaNum = satisfy isAlphaNum <?> "alphanumeric"

-- | Get a string representation of GHC package id.
ghcPkgIdString :: GhcPkgId -> String
ghcPkgIdString (GhcPkgId x) = fromShortText x
ghcPkgIdString (GhcPkgId x) = unUnitId x

-- | Get a text value of GHC package id.
ghcPkgIdToText :: GhcPkgId -> Text
Expand Down

0 comments on commit cc2a57f

Please # to comment.