diff --git a/drop/PlayingWithParsers.purs b/drop/PlayingWithParsers.purs new file mode 100644 index 0000000..ceaae71 --- /dev/null +++ b/drop/PlayingWithParsers.purs @@ -0,0 +1,77 @@ +module PlayingWithParsers where + +import Prelude + +import Data.Foldable (fold) +import Effect (Effect) +import TryPureScript (h1, h3, p, text, render, code) +import Parsing (Parser, runParser) +import Parsing.Combinators as PC +import Parsing.String (char, string) +import Parsing.String.Basic (alphaNum, letter) +import Control.Alt ((<|>)) +import Control.Lazy (defer) +import Data.Array (many) + +domain :: Parser String String +domain = subdomain <|> string " " + +subdomain :: Parser String String +subdomain = label <|> defer \_ -> subdomain *> string "." *> label + +label :: Parser String String +label = PC.try let_str_alpha <|> let_alpha <|> (letter >>= \_ -> string "") + +let_str_alpha :: Parser String String +let_str_alpha = do + _ <- letter + _ <- ldhstr + _ <- alphaNum + pure "" + +let_alpha :: Parser String String +let_alpha = do + _ <- letter + _ <- alphaNum + pure "" + +ldhstr :: Parser String String +ldhstr = let_dig_hyp *> (defer \_ -> ldhstr) <|> defer \_ -> let_dig_hyp *> string "" + +let_dig_hyp :: Parser String Char +let_dig_hyp = alphaNum <|> char '-' + +aye :: Parser String Char +aye = defer \_ -> char 'a' *> aye + +-- From RFC 1035 +--