1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 12:51:52 +03:00

Define a withModules function running an action with a module table constructed from a list of modules.

This commit is contained in:
Rob Rix 2018-03-21 20:01:13 -04:00
parent 9819f2c29b
commit b08969b44c

View File

@ -3,6 +3,7 @@
module Control.Abstract.Analysis module Control.Abstract.Analysis
( MonadAnalysis(..) ( MonadAnalysis(..)
, evaluateTerm , evaluateTerm
, withModules
, withModulesForBlobs , withModulesForBlobs
, require , require
, load , load
@ -60,6 +61,10 @@ evaluateTerm :: MonadAnalysis term value m => term -> m value
evaluateTerm = foldSubterms analyzeTerm evaluateTerm = foldSubterms analyzeTerm
withModules :: MonadAnalysis term value m => [Module term] -> m a -> m a
withModules modules = localModuleTable (const moduleTable)
where moduleTable = ModuleTable (Map.fromListWith (<>) (map ((,) . moduleName <*> pure) modules))
-- | Run an action with the passed ('Blob', @term@) pairs available for imports. -- | Run an action with the passed ('Blob', @term@) pairs available for imports.
withModulesForBlobs :: MonadAnalysis term value m => Blob -> [(Blob, term)] -> m a -> m a withModulesForBlobs :: MonadAnalysis term value m => Blob -> [(Blob, term)] -> m a -> m a
withModulesForBlobs blob pairs = localModuleTable (const moduleTable) withModulesForBlobs blob pairs = localModuleTable (const moduleTable)