From 16fcfe1b2021e7da22028d85701f06615bd32326 Mon Sep 17 00:00:00 2001 From: David Ogborn Date: Thu, 5 Dec 2019 11:57:17 -0500 Subject: [PATCH] added MonadPlus instance; fixed two warnings --- Language/Haskellish.hs | 10 ++++++++-- haskellish.cabal | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Language/Haskellish.hs b/Language/Haskellish.hs index 43cf048..29dc14c 100644 --- a/Language/Haskellish.hs +++ b/Language/Haskellish.hs @@ -2,6 +2,7 @@ module Language.Haskellish where import Language.Haskell.Exts import Control.Applicative +import Control.Monad import Data.Either (isRight) import Data.Maybe (catMaybes) @@ -48,6 +49,10 @@ instance Monad Haskellish where runHaskellish (f x') e ) +instance MonadPlus Haskellish where + mzero = empty + mplus = (<|>) + identifier :: Haskellish String -- note: we don't distinguish between identifiers and symbols identifier = Haskellish f @@ -113,9 +118,9 @@ tuple p1 p2 = Haskellish (\e -> do asRightSection :: Haskellish (a -> b -> c) -> Haskellish b -> Haskellish (a -> c) asRightSection opP bP = Haskellish (\e -> do (opExp,bExp) <- f e - op <- runHaskellish opP opExp + op' <- runHaskellish opP opExp b <- runHaskellish bP bExp - return $ flip op b + return $ flip op' b ) where f (Paren _ x) = f x @@ -129,6 +134,7 @@ collectDoStatements (Do _ xs) = catMaybes $ fmap f xs where f (Qualifier _ e) = Just e f _ = Nothing +collectDoStatements _ = [] listOfDoStatements :: Haskellish a -> Haskellish [a] listOfDoStatements p = Haskellish (\e -> mapM (runHaskellish p) $ collectDoStatements e) diff --git a/haskellish.cabal b/haskellish.cabal index 20feee2..d4715f5 100644 --- a/haskellish.cabal +++ b/haskellish.cabal @@ -1,5 +1,5 @@ name: haskellish -version: 0.1.0 +version: 0.1.1 synopsis: For parsing Haskell-ish languages homepage: http://github.com/dktr0/Haskellish license: BSD3