aboutsummaryrefslogtreecommitdiff
path: root/Parser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Parser.hs')
-rw-r--r--Parser.hs12
1 files changed, 8 insertions, 4 deletions
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