aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Expansion/Global.hs
blob: b92b4afd4603991f2ee27ab402d5ba465047cd20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Data.JLD.Expansion.Global (
    JLDExpansionT,
    JLDExpansionEnv (..),
    JLDExpansionState (..),
    hoistEnv,
    modifyContextCache,
    modifyDocumentCache,
) where

import Data.JLD.Prelude

import Data.JLD.Control.Monad.RES (REST)
import Data.JLD.Error (JLDError)
import Data.JLD.Options (ContextCache, DocumentCache, DocumentLoader (..), JLDVersion (..), hoistDocumentLoader)

type JLDExpansionT e m = REST (JLDExpansionEnv e m) (JLDError e) JLDExpansionState m

data JLDExpansionEnv e m = JLDExpansionEnv
    { jldExpansionEnvDocumentLoader :: DocumentLoader e m
    , jldExpansionEnvProcessingMode :: JLDVersion
    , jldExpansionEnvMaxRemoteContexts :: Int
    }
    deriving (Show)

data JLDExpansionState = JLDExpansionState
    { jldExpansionStateContextCache :: ContextCache
    , jldExpansionStateDocumentCache :: DocumentCache
    }
    deriving (Show, Eq)

hoistEnv :: (forall a. m a -> n a) -> JLDExpansionEnv e m -> JLDExpansionEnv e n
hoistEnv map' options = options{jldExpansionEnvDocumentLoader = options |> jldExpansionEnvDocumentLoader .> hoistDocumentLoader map'}

modifyContextCache :: MonadState JLDExpansionState m => (ContextCache -> ContextCache) -> m ()
modifyContextCache fn = modify \s -> s{jldExpansionStateContextCache = fn (jldExpansionStateContextCache s)}

modifyDocumentCache :: MonadState JLDExpansionState m => (DocumentCache -> DocumentCache) -> m ()
modifyDocumentCache fn = modify \s -> s{jldExpansionStateDocumentCache = fn (jldExpansionStateDocumentCache s)}