diff --git a/app/Run.hs b/app/Run.hs index 55caba0..c942ac2 100644 --- a/app/Run.hs +++ b/app/Run.hs @@ -22,29 +22,29 @@ printErrors :: HHHandle -> Env -> IO () printErrors hand (Env defines_ []) = printErrors hand (Env defines_ ["Unable to compute"]) printErrors hand (Env defines_ errors_) = - mapM_ putStrLn errors_ >> handleInput hand (Env defines_ []) + mapM_ putStrLn errors_ >> handleInput hand (Env defines_ []) [] checkComputing :: HHHandle -> (Env, Maybe Result) -> IO () checkComputing hand (env, Nothing) = printErrors hand env -checkComputing hand (env, Just result) = print result >> handleInput hand env +checkComputing hand (env, Just result) = print result >> handleInput hand env [] -checkParsing :: HHHandle -> Maybe (Tree, String) -> Env -> IO () -checkParsing _ Nothing _ = return () -checkParsing hand (Just (tree, _)) env = +checkParsing :: HHHandle -> String -> Maybe (Tree, String) -> Env -> IO () +checkParsing hand str Nothing env = handleInput hand env str +checkParsing hand _ (Just (tree, _)) env = checkComputing hand (computeAST env tree) checkInput :: HHHandle -> String -> Env -> IO () checkInput _ ":q" _ = return () -checkInput hand input env = checkParsing hand (runParser (parseTree) input) env +checkInput hand input env = checkParsing hand input (runParser (parseTree) input) env -checkEOF :: HHHandle -> Env -> Bool -> IO () -checkEOF _ _ True = return () -checkEOF (HHHandle ff shouldClosee) env False = hGetLine ff >>= - (\x -> checkInput (HHHandle ff shouldClosee) x env) +checkEOF :: HHHandle -> Env -> String -> Bool -> IO () +checkEOF _ _ _ True = return () +checkEOF (HHHandle ff shouldClosee) env prevStr False = hGetLine ff >>= + (\x -> checkInput (HHHandle ff shouldClosee) (prevStr ++ x) env) -handleInput :: HHHandle -> Env -> IO () -handleInput (HHHandle ff shouldClosee) env = - hIsEOF ff >>= (\x -> checkEOF (HHHandle ff shouldClosee) env x) +handleInput :: HHHandle -> Env -> String -> IO () +handleInput (HHHandle ff shouldClosee) env prevStr = + hIsEOF ff >>= (\x -> checkEOF (HHHandle ff shouldClosee) env prevStr x) runStdin :: IO () runStdin = runFileHandle stdin False @@ -58,5 +58,5 @@ onEnd _ = return () runFileHandle :: Handle -> Bool -> IO () runFileHandle ff shouldClosee = - handleInput (HHHandle ff shouldClosee) (Env [] []) >> + handleInput (HHHandle ff shouldClosee) (Env [] []) [] >> onEnd (HHHandle ff shouldClosee)