diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-02-13 20:55:24 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-02-13 20:55:24 +0100 |
commit | 2886ae5ba8addbb86a3fad52ccc65b3309e12fcd (patch) | |
tree | c92a9654e9597c43b51402176d46fcdc5bf332d3 /Parser.hs | |
parent | 4eaad85056c7cbea2ece4ac3867dec1f7403ac33 (diff) |
Cleanup
Diffstat (limited to 'Parser.hs')
-rw-r--r-- | Parser.hs | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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 |