From 2886ae5ba8addbb86a3fad52ccc65b3309e12fcd Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 13 Feb 2024 20:55:24 +0100 Subject: Cleanup --- Parser.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Parser.hs') diff --git a/Parser.hs b/Parser.hs index 27f4f59..c958069 100644 --- a/Parser.hs +++ b/Parser.hs @@ -21,6 +21,7 @@ import Control.Monad.Reader import Control.Monad.State.Lazy import Data.Bifunctor (first) import Data.Char +import Data.List.NonEmpty (NonEmpty(..)) import Data.These import Data.Tuple (swap) @@ -141,11 +142,11 @@ pFunDef0 = do (clauses, name) <- someClauses mname return (FunDef name mtype clauses) where - someClauses :: Maybe Name -> Parser ([FunEq ()], Name) + someClauses :: Maybe Name -> Parser (NonEmpty (FunEq ()), Name) someClauses Nothing = do clause@(FunEq name _ _) <- pFunEq Nothing - (,name) . (clause:) <$> many (pFunEq (Just name)) - someClauses (Just name) = (,name) <$> some (pFunEq (Just name)) + (,name) . (clause :|) <$> many (pFunEq (Just name)) + someClauses (Just name) = (,name) <$> someNE (pFunEq (Just name)) -- | Given the name of the type signature, if any. pFunEq :: Maybe Name -> Parser (FunEq ()) @@ -724,7 +725,7 @@ satisfy p = do traceM "got rest" r `seq` return () traceM "seqd rest" - traceM ("rest is " ++ r) + traceM ("rest is " ++ show r) case r of c : rest | c /= '\n', p c -> do modify (\ps -> ps { psCol = psCol ps + 1 @@ -772,3 +773,6 @@ whenM mb mx = mb >>= \b -> if b then mx else return mempty optional_ :: Alternative f => f a -> f () optional_ a = (() <$ a) <|> pure () + +someNE :: Alternative f => f a -> f (NonEmpty a) +someNE a = (:|) <$> a <*> many a -- cgit v1.2.3-70-g09d2