+{-# 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
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 )
--
-- As well as strings of them:
--
+-- >>> import Text.Parsec ( parse )
-- >>> pretty_print $ parse ldh_str "" "a0-b"
-- a0-b
--
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
+--
-- >>> let (Right r) = parse ldh_str "" "a"
-- >>> last_ldh_str r
-- LetDigHypLetDig (LetDigLetter (Letter 'a'))
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
+--
-- >>> let (Right r) = parse ldh_str "" "a"
-- >>> init_ldh_str r
-- Nothing
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
+--
-- >>> let (Right r) = parse ldh_str "" "a"
-- >>> length_ldh_str r
-- 1
--
-- ==== _Examples_
--
--- >>> import Text.Parsec ( parseTest )
+-- >>> import Text.Parsec ( parse, parseTest )
--
-- Make sure we can parse a single character:
--
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
+--
-- >>> let (Right r) = parse ldh_str_let_dig "" "a"
-- >>> length_ldh_str_let_dig r
-- 1
--
-- ==== _Examples_
--
--- >>> import Text.Parsec ( parseTest )
+-- >>> import Text.Parsec ( parse, parseTest )
--
-- Make sure we can parse a single character:
--
--
-- ==== _Examples_
--
--- >>> import Text.Parsec ( parseTest )
+-- >>> import Text.Parsec ( parse, parseTest )
--
-- Make sure we can parse a single character:
--
both :: Parser Subdomain
both = do
l <- label
- char '.'
+ _ <- char '.'
s <- subdomain
let result = SubdomainMultipleLabel l s
if (subdomain_has_equal_neighbors result)
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
+--
-- >>> let (Right r) = parse subdomain "" "a"
-- >>> pretty_print $ subdomain_labels r
-- ["a"]
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
-- >>> let (Right r) = parse subdomain "" "www.example.com"
-- >>> pretty_print $ subdomain_label_neighbors r
-- ["(\"www\",\"example\")","(\"example\",\"com\")"]
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parse )
+--
-- >>> let (Right r) = parse subdomain "" "www.example.com"
-- >>> subdomain_has_equal_neighbors r
-- False
--
-- ==== _Examples_
--
--- >>> import Text.Parsec ( parseTest )
+-- >>> import Text.Parsec ( parse, parseTest )
--
-- Make sure we can parse a single character:
--
parse_subdomain :: Parser Domain
parse_subdomain = do
s <- subdomain
- if (length $ pretty_show s) <= 255
+ if length (pretty_show s) <= 255
then return $ DomainName s
else fail "subdomains can be at most 255 characters"
--
-- ==== _Examples_
--
--- >>> import Text.Parsec ( parseTest )
+-- >>> import Text.Parsec ( parse, parseTest )
--
-- We can really parse the root now!
--
absolute :: Parser UserDomain
absolute = do
d <- domain
- r <- char '.'
+ _ <- char '.'
return $ UserDomainAbsolute d
relative :: Parser UserDomain