From 78fac664f39dc52818fb99264c258b822df7d5b9 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 5 Oct 2022 14:28:00 +0300 Subject: Refactor Env into LContext --- src/Utils.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/Utils.hs') diff --git a/src/Utils.hs b/src/Utils.hs index 1e9afc5..6354a87 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -2,7 +2,7 @@ module Utils where import Control.Monad.Except -import Control.Monad.Reader +import Control.Monad.State import qualified Data.Map as M import qualified Data.List as L import qualified Data.Char as C @@ -22,10 +22,17 @@ data Config = Config { configUseREPL :: Bool } -type LContext a = ReaderT Config (ExceptT LException IO) a +type Env = M.Map String AST + +data LState = LState { + stateConfig :: Config, + stateEnv :: Env +} -runL :: Config -> LContext a -> IO (Either LException a) -runL config lc = runExceptT $ runReaderT lc config +type LContext a = StateT LState (ExceptT LException IO) a + +runL :: LState -> LContext a -> IO (Either LException (a, LState)) +runL s lc = runExceptT $ (flip runStateT) s lc data Token = Token { tokenContent :: String, @@ -40,8 +47,6 @@ instance (Eq Token) where instance (Show Token) where show token = show $ tokenContent token -type Env = M.Map String AST - type LFunction = (Env -> AST -> LContext AST) data ASTNode -- cgit v1.3