1 -- | OK, I lied about "Network.DNS.RBL.Domain.Digit" and
2 -- "Network.DNS.RBL.Domain.Letter" being the simplest modules you'd
3 -- ever see. Because this is. It contains the 'Hyphen' type and a
4 -- Parsec parser to parse one. We don't export its constructor because
5 -- then you could do something dumb like stick a letter inside one.
7 module Network.DNS.RBL.Domain.Hyphen (
12 import Text.Parsec ( char )
13 import Text.Parsec.String ( Parser )
15 import Network.DNS.RBL.Pretty ( Pretty(..) )
19 -- | A wrapper around a single hyphen character.
26 -- >>> let h1 = Hyphen '-'
27 -- >>> let h2 = Hyphen '-'
31 newtype Hyphen = Hyphen Char
34 -- | Equality is defined semantically (all hyphens are equal).
38 -- >>> let h1 = Hyphen '-'
39 -- >>> let h2 = Hyphen '-'
43 -- If you do something stupid, that's your fault:
45 -- >>> let h1 = Hyphen '-'
46 -- >>> let h2 = Hyphen 'x'
50 instance Eq Hyphen where _ == _ = True
53 -- | 'Show' is defined semantically; all hyphens display as \'-\'.
54 -- The implementation is based on what GHC derives, discovered via
55 -- @ghci -ddump-deriv@.
59 -- >>> let h = Hyphen '-'
63 -- If you do something stupid, that's your fault:
65 -- >>> let h = Hyphen 'x'
69 instance Show Hyphen where
71 showParen (d > application_precedence) (showString "Hyphen '-'")
73 application_precedence = 10
76 -- | 'Pretty' is defined semantically; all hyphens display as \'-\'.
80 -- >>> let h = Hyphen '-'
84 -- If you do something stupid, that's your fault:
86 -- >>> let h = Hyphen 'x'
90 instance Pretty Hyphen where pretty_show _ = "-"
93 -- | Parse a single hyphen and wrap it in our 'Hyphen' type.
97 -- >>> import Text.Parsec ( parseTest )
99 -- Hyphens are parsed:
101 -- >>> parseTest hyphen "-"
104 -- But not letters or digits:
106 -- >>> parseTest hyphen "1"
107 -- parse error at (line 1, column 1):
111 -- >>> parseTest hyphen "x"
112 -- parse error at (line 1, column 1):
116 hyphen :: Parser Hyphen
117 hyphen = fmap Hyphen (char '-')