diff --git a/src/DomainParser.purs b/src/DomainParser.purs index 3bcc59b..c643197 100644 --- a/src/DomainParser.purs +++ b/src/DomainParser.purs @@ -105,6 +105,16 @@ sub_eof = do did_we_parsed_the_final_point '.' sub = sub <> "." did_we_parsed_the_final_point _ sub = sub +-- | From RFC 1035: ::= | " " +-- | +-- | Accepting an optional '.' at the end of the subdomain doesn't conform +-- | to the (prefered) syntax of a domain as described in RFC 1035. +-- | However, this last '.' character should be acceptable in most applications. +-- | In some cases, a fully qualified domain name (FQDN) such as `example.com.` +-- | has to be differenciated from a "relative" name (www). +domain :: Parser String +domain = (string " " *> eof) <|> sub_eof + {- import Data.Either (Either(..)) -- import Data.String.Regex as R @@ -116,16 +126,6 @@ import Parsing (Parser, fail, runParser) import Parsing.String.Basic (alphaNum, letter) import Parsing.String (char, string, eof) --- | From RFC 1035: ::= | " " --- | --- | Accepting an optional '.' at the end of the subdomain doesn't conform --- | to the (prefered) syntax of a domain as described in RFC 1035. --- | However, this last '.' character should be acceptable in most applications. --- | In some cases, a fully qualified domain name (FQDN) such as `example.com.` --- | has to be differenciated from a "relative" name (www). -domain :: Parser String String -domain = PC.try (string " ") <|> sub_eof - -- | Converting a single letter parser to a String parser. char_to_string :: Parser String Char -> Parser String String diff --git a/src/Main.purs b/src/Main.purs index 676364f..c7a13c1 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -97,6 +97,8 @@ main = do log "" + logtest "sub_eof" sub_eof " " id + logtest "sub_eof" sub_eof " " id logtest "sub_eof" sub_eof "example.org" id logtest "sub_eof" sub_eof "" id logtest "sub_eof" sub_eof "a.x" id @@ -118,6 +120,31 @@ main = do logtest "sub_eof" sub_eof "-" id logtest "sub_eof" sub_eof "a-" id + log "" + + logtest "domain" domain " " id + logtest "domain" domain " " id + logtest "domain" domain "example.org" id + logtest "domain" domain "" id + logtest "domain" domain "a.x" id + logtest "domain" domain "a2.org" id + logtest "domain" domain "a33.org" id + logtest "domain" domain "a444.org" id + logtest "domain" domain "a5555.org" id + logtest "domain" domain "a66666.org" id + logtest "domain" domain "a777777.org" id + logtest "domain" domain "a8888888.org" id + logtest "domain" domain "xblah.a.x" id + logtest "domain" domain "xblah.a2.org" id + logtest "domain" domain "xblah.a33.org" id + logtest "domain" domain "xblah.a444.org" id + logtest "domain" domain "xblah.a5555.org" id + logtest "domain" domain "xblah.a66666.org" id + logtest "domain" domain "xblah.a777777.org" id + logtest "domain" domain "xblah.a8888888.org" id + logtest "domain" domain "-" id + logtest "domain" domain "a-" id + -- log $ "parsing the first 'f' in 'fiction' (sat): " <> case parse (sat (\x -> x == 'f')) "fiction" of -- Just (Tuple x y) -> show x <> " " <> show y -- Nothing -> "failed"