Parser domain works, for the naive Parser implementation.
parent
15f4983fe2
commit
33e09a1a3d
|
@ -105,6 +105,16 @@ sub_eof = do
|
||||||
did_we_parsed_the_final_point '.' sub = sub <> "."
|
did_we_parsed_the_final_point '.' sub = sub <> "."
|
||||||
did_we_parsed_the_final_point _ sub = sub
|
did_we_parsed_the_final_point _ sub = sub
|
||||||
|
|
||||||
|
-- | From RFC 1035: <domain> ::= <subdomain> | " "
|
||||||
|
-- |
|
||||||
|
-- | 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.Either (Either(..))
|
||||||
-- import Data.String.Regex as R
|
-- import Data.String.Regex as R
|
||||||
|
@ -116,16 +126,6 @@ import Parsing (Parser, fail, runParser)
|
||||||
import Parsing.String.Basic (alphaNum, letter)
|
import Parsing.String.Basic (alphaNum, letter)
|
||||||
import Parsing.String (char, string, eof)
|
import Parsing.String (char, string, eof)
|
||||||
|
|
||||||
-- | From RFC 1035: <domain> ::= <subdomain> | " "
|
|
||||||
-- |
|
|
||||||
-- | 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.
|
-- | Converting a single letter parser to a String parser.
|
||||||
char_to_string :: Parser String Char -> Parser String String
|
char_to_string :: Parser String Char -> Parser String String
|
||||||
|
|
|
@ -97,6 +97,8 @@ main = do
|
||||||
|
|
||||||
log ""
|
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 "example.org" id
|
||||||
logtest "sub_eof" sub_eof "" id
|
logtest "sub_eof" sub_eof "" id
|
||||||
logtest "sub_eof" sub_eof "a.x" 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 "-" id
|
||||||
logtest "sub_eof" sub_eof "a-" 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
|
-- log $ "parsing the first 'f' in 'fiction' (sat): " <> case parse (sat (\x -> x == 'f')) "fiction" of
|
||||||
-- Just (Tuple x y) -> show x <> " " <> show y
|
-- Just (Tuple x y) -> show x <> " " <> show y
|
||||||
-- Nothing -> "failed"
|
-- Nothing -> "failed"
|
||||||
|
|
Loading…
Reference in New Issue