]> gitweb.michael.orlitzky.com - dead/harbl.git/blob - harbl/src/Network/DNS/RBL/Domain/Hyphen.hs
1e49ff2cb6e4a64b9206dde89420b22313f0ffe4
[dead/harbl.git] / harbl / src / Network / DNS / RBL / Domain / Hyphen.hs
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.
6 --
7 module Network.DNS.RBL.Domain.Hyphen (
8 Hyphen,
9 hyphen )
10 where
11
12 import Text.Parsec ( char )
13 import Text.Parsec.String ( Parser )
14
15 import Network.DNS.RBL.Pretty ( Pretty(..) )
16
17
18
19 -- | A type representing a single hyphen character.
20 --
21 -- ==== _Examples_
22 --
23 -- >>> Hyphen
24 -- Hyphen
25 --
26 -- >>> let h1 = Hyphen
27 -- >>> let h2 = Hyphen
28 -- >>> h1 == h2
29 -- True
30 --
31 data Hyphen = Hyphen deriving (Eq, Show)
32
33
34 -- | Pretty-print a hyphen; they all display as \'-\'.
35 --
36 -- ==== _Examples_
37 --
38 -- >>> let h = Hyphen
39 -- >>> pretty_print h
40 -- -
41 --
42 instance Pretty Hyphen where pretty_show _ = "-"
43
44
45 -- | Parse a single hyphen and return a 'Hyphen'.
46 --
47 -- ==== _Examples_
48 --
49 -- >>> import Text.Parsec ( parseTest )
50 --
51 -- Hyphens are parsed:
52 --
53 -- >>> parseTest hyphen "-"
54 -- Hyphen
55 --
56 -- But not letters or digits:
57 --
58 -- >>> parseTest hyphen "1"
59 -- parse error at (line 1, column 1):
60 -- unexpected "1"
61 -- expecting "-"
62 --
63 -- >>> parseTest hyphen "x"
64 -- parse error at (line 1, column 1):
65 -- unexpected "x"
66 -- expecting "-"
67 --
68 hyphen :: Parser Hyphen
69 hyphen = char '-' >> return Hyphen