never executed always true always false
1 {-# LANGUAGE DeriveGeneric #-}
2 module Distribution.Client.Types.RepoName (
3 RepoName (..),
4 unRepoName,
5 ) where
6
7 import Distribution.Client.Compat.Prelude
8 import Prelude ()
9
10 import qualified Distribution.Compat.CharParsing as P
11 import qualified Text.PrettyPrint as Disp
12
13 -- $setup
14 -- >>> import Distribution.Parsec
15
16 -- | Repository name.
17 --
18 -- May be used as path segment.
19 --
20 newtype RepoName = RepoName String
21 deriving (Show, Eq, Ord, Generic)
22
23 unRepoName :: RepoName -> String
24 unRepoName (RepoName n) = n
25
26 instance Binary RepoName
27 instance Structured RepoName
28 instance NFData RepoName
29
30 instance Pretty RepoName where
31 pretty = Disp.text . unRepoName
32
33 -- |
34 --
35 -- >>> simpleParsec "hackage.haskell.org" :: Maybe RepoName
36 -- Just (RepoName "hackage.haskell.org")
37 --
38 -- >>> simpleParsec "0123" :: Maybe RepoName
39 -- Nothing
40 --
41 instance Parsec RepoName where
42 parsec = RepoName <$> parser where
43 parser = (:) <$> lead <*> rest
44 lead = P.satisfy (\c -> isAlpha c || c == '_' || c == '-' || c == '.')
45 rest = P.munch (\c -> isAlphaNum c || c == '_' || c == '-' || c == '.')