1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Rename the ModuleTable symbols.

This commit is contained in:
Rob Rix 2018-03-30 18:13:21 -04:00
parent d63d956cc8
commit a8d03f2f3e
3 changed files with 12 additions and 11 deletions

View File

@ -119,7 +119,7 @@ instance Evaluatable [] where
require :: MonadEvaluatable location term value m
=> ModuleName
-> m (Environment location value, value)
require name = getModuleTable >>= maybe (load name) pure . moduleTableLookup name
require name = getModuleTable >>= maybe (load name) pure . ModuleTable.lookup name
-- | Load another module by name and return it's environment and value.
--
@ -127,7 +127,7 @@ require name = getModuleTable >>= maybe (load name) pure . moduleTableLookup nam
load :: MonadEvaluatable location term value m
=> ModuleName
-> m (Environment location value, value)
load name = askModuleTable >>= maybe notFound pure . moduleTableLookup name >>= evalAndCache
load name = askModuleTable >>= maybe notFound pure . ModuleTable.lookup name >>= evalAndCache
where
notFound = throwLoadError (LoadError name)
@ -141,7 +141,7 @@ load name = askModuleTable >>= maybe notFound pure . moduleTableLookup name >>=
evalAndCache' x = do
v <- evaluateModule x
env <- filterEnv <$> getExports <*> getEnv
modifyModuleTable (moduleTableInsert name (env, v))
modifyModuleTable (ModuleTable.insert name (env, v))
pure (env, v)
-- TODO: If the set of exports is empty because no exports have been

View File

@ -2,8 +2,8 @@
module Data.Abstract.ModuleTable
( ModuleName
, ModuleTable (..)
, moduleTableLookup
, moduleTableInsert
, lookup
, insert
, fromList
) where
@ -11,15 +11,16 @@ import Data.Abstract.Module
import qualified Data.Map as Map
import Data.Semigroup
import GHC.Generics (Generic1)
import Prelude hiding (lookup)
newtype ModuleTable a = ModuleTable { unModuleTable :: Map.Map ModuleName a }
deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable)
moduleTableLookup :: ModuleName -> ModuleTable a -> Maybe a
moduleTableLookup k = Map.lookup k . unModuleTable
lookup :: ModuleName -> ModuleTable a -> Maybe a
lookup k = Map.lookup k . unModuleTable
moduleTableInsert :: ModuleName -> a -> ModuleTable a -> ModuleTable a
moduleTableInsert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable)
insert :: ModuleName -> a -> ModuleTable a -> ModuleTable a
insert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable)
-- | Construct a 'ModuleTable' from a list of 'Module's.

View File

@ -3,7 +3,7 @@ module Language.Ruby.Syntax where
import Control.Monad (unless)
import Data.Abstract.Evaluatable
import Data.Abstract.ModuleTable
import Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Path
import Diffing.Algorithm
import Prelude hiding (fail)
@ -30,7 +30,7 @@ doRequire :: MonadEvaluatable location term value m
-> m (Environment location value, value)
doRequire name = do
moduleTable <- getModuleTable
case moduleTableLookup name moduleTable of
case ModuleTable.lookup name moduleTable of
Nothing -> (,) <$> (fst <$> load name) <*> boolean True
Just (env, _) -> (,) <$> pure env <*> boolean False