aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordan <[email protected]>2024-04-20 14:59:38 -0400
committerdan <[email protected]>2024-04-20 14:59:38 -0400
commitfe7d9b9482d8b48603973791519d3272dbfb22af (patch)
tree0135b3dd1b2163077649e7cdda4b4f047521b058
parent98080ab5812849ed72ddce162e02a0e34e6a334e (diff)
downloadbizexp-fe7d9b9482d8b48603973791519d3272dbfb22af.tar.gz
bizexp-fe7d9b9482d8b48603973791519d3272dbfb22af.tar.bz2
bizexp-fe7d9b9482d8b48603973791519d3272dbfb22af.zip
fix: REPL handles EOF properly
-rwxr-xr-xsrc/BizExpr.hs14
1 files changed, 11 insertions, 3 deletions
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