diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-10-05 14:28:00 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:53 +0200 |
| commit | 78fac664f39dc52818fb99264c258b822df7d5b9 (patch) | |
| tree | 9b7187e15c4b2690df89e7558c610f20c99e9efd /src/Utils.hs | |
| parent | 77968899b90cd9afe2ed2668b290b66cb553ced2 (diff) | |
Refactor Env into LContext
Diffstat (limited to 'src/Utils.hs')
| -rw-r--r-- | src/Utils.hs | 17 |
1 files changed, 11 insertions, 6 deletions
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 |
