1
1
mirror of https://github.com/github/semantic.git synced 2025-01-07 07:58: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 require :: MonadEvaluatable location term value m
=> ModuleName => ModuleName
-> m (Environment location value, value) -> 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. -- | 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 load :: MonadEvaluatable location term value m
=> ModuleName => ModuleName
-> m (Environment location value, value) -> 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 where
notFound = throwLoadError (LoadError name) notFound = throwLoadError (LoadError name)
@ -141,7 +141,7 @@ load name = askModuleTable >>= maybe notFound pure . moduleTableLookup name >>=
evalAndCache' x = do evalAndCache' x = do
v <- evaluateModule x v <- evaluateModule x
env <- filterEnv <$> getExports <*> getEnv env <- filterEnv <$> getExports <*> getEnv
modifyModuleTable (moduleTableInsert name (env, v)) modifyModuleTable (ModuleTable.insert name (env, v))
pure (env, v) pure (env, v)
-- TODO: If the set of exports is empty because no exports have been -- TODO: If the set of exports is empty because no exports have been

View File

@ -2,8 +2,8 @@
module Data.Abstract.ModuleTable module Data.Abstract.ModuleTable
( ModuleName ( ModuleName
, ModuleTable (..) , ModuleTable (..)
, moduleTableLookup , lookup
, moduleTableInsert , insert
, fromList , fromList
) where ) where
@ -11,15 +11,16 @@ import Data.Abstract.Module
import qualified Data.Map as Map import qualified Data.Map as Map
import Data.Semigroup import Data.Semigroup
import GHC.Generics (Generic1) import GHC.Generics (Generic1)
import Prelude hiding (lookup)
newtype ModuleTable a = ModuleTable { unModuleTable :: Map.Map ModuleName a } newtype ModuleTable a = ModuleTable { unModuleTable :: Map.Map ModuleName a }
deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable) deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable)
moduleTableLookup :: ModuleName -> ModuleTable a -> Maybe a lookup :: ModuleName -> ModuleTable a -> Maybe a
moduleTableLookup k = Map.lookup k . unModuleTable lookup k = Map.lookup k . unModuleTable
moduleTableInsert :: ModuleName -> a -> ModuleTable a -> ModuleTable a insert :: ModuleName -> a -> ModuleTable a -> ModuleTable a
moduleTableInsert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable) insert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable)
-- | Construct a 'ModuleTable' from a list of 'Module's. -- | 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 Control.Monad (unless)
import Data.Abstract.Evaluatable import Data.Abstract.Evaluatable
import Data.Abstract.ModuleTable import Data.Abstract.ModuleTable as ModuleTable
import Data.Abstract.Path import Data.Abstract.Path
import Diffing.Algorithm import Diffing.Algorithm
import Prelude hiding (fail) import Prelude hiding (fail)
@ -30,7 +30,7 @@ doRequire :: MonadEvaluatable location term value m
-> m (Environment location value, value) -> m (Environment location value, value)
doRequire name = do doRequire name = do
moduleTable <- getModuleTable moduleTable <- getModuleTable
case moduleTableLookup name moduleTable of case ModuleTable.lookup name moduleTable of
Nothing -> (,) <$> (fst <$> load name) <*> boolean True Nothing -> (,) <$> (fst <$> load name) <*> boolean True
Just (env, _) -> (,) <$> pure env <*> boolean False Just (env, _) -> (,) <$> pure env <*> boolean False