X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fharbl.git;a=blobdiff_plain;f=harbl%2Fsrc%2FNetwork%2FDNS%2FRBL%2FDomain%2FDigit.hs;fp=harbl%2Fsrc%2FNetwork%2FDNS%2FRBL%2FDomain%2FDigit.hs;h=fd7ce063c72068baee51fc472d8349950a1acf19;hp=0000000000000000000000000000000000000000;hb=4dd314687c806419fac1fc88c96df6541e1dff4b;hpb=7decace098b98d7f19b7af43e9d0c641f445640f diff --git a/harbl/src/Network/DNS/RBL/Domain/Digit.hs b/harbl/src/Network/DNS/RBL/Domain/Digit.hs new file mode 100644 index 0000000..fd7ce06 --- /dev/null +++ b/harbl/src/Network/DNS/RBL/Domain/Digit.hs @@ -0,0 +1,71 @@ +-- | The simplest module you'll ever see. It contains the 'Digit' type +-- and a Parsec parser to parse one. We don't export its constructor +-- because then you could do something dumb like stick a letter +-- inside one. +-- +-- These are defined in RFC1035, Section 2.3.1, \"Preferred name +-- syntax\" : +-- +-- ::= any one of the ten digits 0 through 9 +-- +module Network.DNS.RBL.Domain.Digit ( + Digit, + digit ) +where + +import qualified Text.Parsec as Parsec ( digit ) +import Text.Parsec.String ( Parser ) + +import Network.DNS.RBL.Pretty ( Pretty(..) ) + + +-- | A wrapper around a single digit character. +-- +-- ==== _Examples_ +-- +-- >>> Digit '1' +-- Digit '1' +-- +-- >>> let d1 = Digit '2' +-- >>> let d2 = Digit '2' +-- >>> let d3 = Digit '3' +-- >>> d1 == d2 +-- True +-- >>> d1 == d3 +-- False +-- +newtype Digit = Digit Char deriving (Eq, Show) + + +-- | Pretty-printing for digits that we've already parsed. Just +-- shows/prints the digit character. +-- +-- ==== _Examples_ +-- +-- >>> let d = Digit '1' +-- >>> pretty_print d +-- 1 +-- +instance Pretty Digit where pretty_show (Digit d) = [d] + + +-- | Parse a single digit, but wrap it in our 'Digit' type. +-- +-- ==== _Examples_ +-- +-- >>> import Text.Parsec ( parseTest ) +-- +-- Digits are parsed correctly: +-- +-- >>> parseTest digit "3" +-- Digit '3' +-- +-- But letters are not: +-- +-- >>> parseTest digit "x" +-- parse error at (line 1, column 1): +-- unexpected "x" +-- expecting digit +-- +digit :: Parser Digit +digit = fmap Digit Parsec.digit