module Distribution.Types.ComponentId
( ComponentId, unComponentId, mkComponentId
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Utils.ShortText
import qualified Distribution.Compat.ReadP as Parse
import qualified Distribution.Compat.CharParsing as P
import Distribution.Text
import Distribution.Pretty
import Distribution.Parsec.Class
import Text.PrettyPrint (text)
newtype ComponentId = ComponentId ShortText
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
mkComponentId :: String -> ComponentId
mkComponentId = ComponentId . toShortText
unComponentId :: ComponentId -> String
unComponentId (ComponentId s) = fromShortText s
instance IsString ComponentId where
fromString = mkComponentId
instance Binary ComponentId
instance Pretty ComponentId where
pretty = text . unComponentId
instance Parsec ComponentId where
parsec = mkComponentId `fmap` P.munch1 abi_char
where abi_char c = isAlphaNum c || c `elem` "-_."
instance Text ComponentId where
parse = mkComponentId `fmap` Parse.munch1 abi_char
where abi_char c = isAlphaNum c || c `elem` "-_."
instance NFData ComponentId where
rnf = rnf . unComponentId