From fe7d9b9482d8b48603973791519d3272dbfb22af Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 20 Apr 2024 14:59:38 -0400 Subject: fix: REPL handles EOF properly --- src/BizExpr.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/BizExpr.hs b/src/BizExpr.hs index 20a25d1..b11ffc1 100755 --- a/src/BizExpr.hs +++ b/src/BizExpr.hs @@ -6,13 +6,21 @@ import Data.Maybe (fromMaybe) import Text.Read (readMaybe) import qualified Data.Text.Lazy as L import qualified Data.Map as M - +import System.IO (isEOF) +import Control.Monad (when) type Context = M.Map L.Text L.Text ---import Data.Text as T repl :: IO () -repl = getLine >>= putStrLn . maybe "Failed to evaluate expression" id . (eval M.empty :: String -> Maybe String) >> repl +repl = do + eof <- isEOF + when (not eof) ( + getLine >>= + putStrLn + . maybe "Failed to evaluate expression" id + . (eval M.empty :: String -> Maybe String) + >> repl + ) maybeHead (x:_) = Just x maybeHead _ = Nothing -- cgit v1.2.3