From 77117fa515c5853b5f756d899db0ec9b502298e7 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 6 Oct 2022 12:28:24 +0300 Subject: Add line info to REPL --- app/Main.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index a422a5b..1ee5bd8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -24,20 +24,23 @@ parseArgs config args = _ -> config repl :: LState -> InputT IO () -repl ls = do - minput <- getInputLine "> " +repl = repl' 1 + +repl' :: LineNo -> LState -> InputT IO () +repl' lineNo ls = do + minput <- getInputLine $ show lineNo ++ ":> " case minput of Nothing -> return () Just input -> do - result <- lift $ runL ls (runInlineScript "" input) + result <- lift $ runL ls $ runInlineScript' lineNo "" input case result of Left (LException mp ex) -> do outputStrLn $ case mp of Just p -> p ++ " error: " ++ ex Nothing -> "error: " ++ ex - repl ls + repl' (lineNo + 1) ls Right (_, LState { stateEnv = newEnv }) -> do - repl ls { stateEnv = newEnv } + repl' (lineNo + 1) ls { stateEnv = newEnv } main :: IO () main = do @@ -81,8 +84,8 @@ main = do Nothing -> putStrLn $ "error: " ++ ex Right (_, LState { stateEnv = evaledEnv }) -> do when (configUseREPL config) $ - runInputT defaultSettings (repl ls { stateEnv = evaledEnv }) + runInputT defaultSettings $ repl ls { stateEnv = evaledEnv } Nothing -> do putStrLn $ "Lang REPL" putStrLn $ "Use CTRL+D to exit" - runInputT defaultSettings (repl ls) + runInputT defaultSettings $ repl ls -- cgit v1.3