X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fharbl.git;a=blobdiff_plain;f=src%2FDomain.hs;h=87a63d9757f8bb2c6cfda6bac49651101a3153ab;hp=446a8a63409a8ca9a7e6f7dd48877f4de40426ab;hb=80b389fd4d76bc8b2cb5dfad0f066fd7a838bdfb;hpb=3beaa57bb0853ef3ab417a3f1bbbcddc2589cee4 diff --git a/src/Domain.hs b/src/Domain.hs index 446a8a6..87a63d9 100644 --- a/src/Domain.hs +++ b/src/Domain.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE DoAndIfThenElse #-} + -- | The 'Domain' data type and its parser. A 'Domain' represents a -- name in the domain name system (DNS) as described by -- RFC1035. In particular, we enforce the restrictions from Section @@ -5,6 +7,13 @@ -- -- -- +-- We basically work with strings and characters everywhere, even +-- though this isn't really correct. The length specifications in +-- the RFCs are all in terms of octets, so really a ByteString.Char8 +-- would be more appropriate. With strings, for example, we could +-- have a unicode mumbo jumbo character that takes up two bytes +-- (octets). +-- module Domain ( UserDomain, user_domain ) @@ -12,18 +21,11 @@ where import Data.Char ( toLower ) import Text.Parsec ( - ParseError, (<|>), - alphaNum, char, - eof, - many1, - option, optionMaybe, - parse, string, - try, - unexpected ) + try ) import qualified Text.Parsec as Parsec ( digit, letter) import Text.Parsec.String ( Parser ) @@ -67,7 +69,11 @@ letter = fmap Letter Parsec.letter -- manner... -- -- Since each part of DNS name is composed of our custom types, it --- suffices to munge the equality for 'Letter'. +-- suffices to munge the equality for 'Letter'. RFC4343 +-- clarifies the +-- case-insensitivity rules, but the fact that we're treating DNS +-- names as strings makes most of those problems go away (in +-- exchange for new ones). -- instance Eq Letter where (Letter l1) == (Letter l2) = (toLower l1) == (toLower l2) @@ -193,6 +199,7 @@ instance Pretty LdhStr where -- -- As well as strings of them: -- +-- >>> import Text.Parsec ( parse ) -- >>> pretty_print $ parse ldh_str "" "a0-b" -- a0-b -- @@ -217,6 +224,8 @@ ldh_str = try both <|> just_one -- -- ==== _Examples_ -- +-- >>> import Text.Parsec ( parse ) +-- -- >>> let (Right r) = parse ldh_str "" "a" -- >>> last_ldh_str r -- LetDigHypLetDig (LetDigLetter (Letter 'a')) @@ -240,6 +249,8 @@ last_ldh_str (LdhStrMultipleLdh _ x) = last_ldh_str x -- -- ==== _Examples_ -- +-- >>> import Text.Parsec ( parse ) +-- -- >>> let (Right r) = parse ldh_str "" "a" -- >>> init_ldh_str r -- Nothing @@ -269,6 +280,8 @@ init_ldh_str (LdhStrMultipleLdh h t) = -- -- ==== _Examples_ -- +-- >>> import Text.Parsec ( parse ) +-- -- >>> let (Right r) = parse ldh_str "" "a" -- >>> length_ldh_str r -- 1 @@ -306,7 +319,7 @@ instance Pretty LdhStrLetDig where -- -- ==== _Examples_ -- --- >>> import Text.Parsec ( parseTest ) +-- >>> import Text.Parsec ( parse, parseTest ) -- -- Make sure we can parse a single character: -- @@ -357,6 +370,8 @@ ldh_str_let_dig = do -- -- ==== _Examples_ -- +-- >>> import Text.Parsec ( parse ) +-- -- >>> let (Right r) = parse ldh_str_let_dig "" "a" -- >>> length_ldh_str_let_dig r -- 1 @@ -377,6 +392,14 @@ length_ldh_str_let_dig (LdhStrLetDig (Just ldhstring) _) = -- --