From d327b943f9d1c75ff554a07128b334f3fdb9d87a Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 13 Jan 2024 01:22:15 +0100 Subject: [PATCH] subdomain kinda works --- src/DomainParser.purs | 92 ++++++++++++++++++++----------------------- src/Main.purs | 42 ++++++++++++++++---- 2 files changed, 76 insertions(+), 58 deletions(-) diff --git a/src/DomainParser.purs b/src/DomainParser.purs index 0222ad3..bb996e6 100644 --- a/src/DomainParser.purs +++ b/src/DomainParser.purs @@ -4,11 +4,12 @@ module DomainParser where import Prelude --import Prelude (bind, discard, pure, show, ($), (<>), (>)) +import Control.Lazy (defer) import Data.Maybe (Maybe(..)) import Data.Array as A import Data.String as S import Data.Tuple (Tuple(..)) -import Data.Array.NonEmpty as NonEmpty +-- import Data.Array.NonEmpty as NonEmpty import Data.String.CodeUnits as CU import Control.Alt ((<|>)) import Control.Plus (empty) @@ -42,45 +43,54 @@ parse_last_char s p = case last_char s of Nothing -> false _ -> true -try :: Parser String -> Parser String +-- | FIXME: This is flawed. +-- | We cannot know if it worked: in case there is a problem with the parser `p`, +-- | the code will "continue to work" but without what's been parsed. +-- | This may sound reasonable but it prevents knowing if a problem actually occured! +-- | We cannot do a `try parser <|> alternative` since it will always work! +try :: forall a. Monoid a => Parser a -> Parser a try p = Parser p' where p' str = case parse p str of - Nothing -> Just (Tuple "" str) -- FIXME: This is flawed: we cannot know if it worked! + Nothing -> Just (Tuple mempty str) -- FIXME! Need a better base structure. Just x -> pure x -- From RFC 1035: