1 -- | The simplest module you'll ever see. It contains the 'Digit' type
2 -- and a Parsec parser to parse one. We don't export its constructor
3 -- because then you could do something dumb like stick a letter
6 -- These are defined in RFC1035, Section 2.3.1, \"Preferred name
7 -- syntax\" <https://tools.ietf.org/html/rfc1035#section-2.3.1>:
9 -- <digit> ::= any one of the ten digits 0 through 9
11 module Network.DNS.RBL.Domain.Digit (
16 import qualified Text.Parsec as Parsec ( digit )
17 import Text.Parsec.String ( Parser )
19 import Network.DNS.RBL.Pretty ( Pretty(..) )
22 -- | A wrapper around a single digit character.
29 -- >>> let d1 = Digit '2'
30 -- >>> let d2 = Digit '2'
31 -- >>> let d3 = Digit '3'
37 newtype Digit = Digit Char deriving (Eq, Show)
40 -- | Pretty-printing for digits that we've already parsed. Just
41 -- shows/prints the digit character.
45 -- >>> let d = Digit '1'
49 instance Pretty Digit where pretty_show (Digit d) = [d]
52 -- | Parse a single digit, but wrap it in our 'Digit' type.
56 -- >>> import Text.Parsec ( parseTest )
58 -- Digits are parsed correctly:
60 -- >>> parseTest digit "3"
63 -- But letters are not:
65 -- >>> parseTest digit "x"
66 -- parse error at (line 1, column 1):
71 digit = fmap Digit Parsec.digit