Rename 'MyMonad' to 'ReferenceM'
This commit is contained in:
parent
b28555b0f4
commit
af1d0b9534
|
@ -142,7 +142,7 @@ instance Semigroup Node where
|
||||||
(NodeDef{}, NodeModule{}) -> c1
|
(NodeDef{}, NodeModule{}) -> c1
|
||||||
(NodeDef (FQN n0 _), NodeDef (FQN n1 a1)) -> NodeDef $ FQN (n0 <> n1) a1
|
(NodeDef (FQN n0 _), NodeDef (FQN n1 a1)) -> NodeDef $ FQN (n0 <> n1) a1
|
||||||
|
|
||||||
class Monad m => MyMonad (m :: Type -> Type) where
|
class Monad m => ReferenceM (m :: Type -> Type) where
|
||||||
declaration :: Node -> m ()
|
declaration :: Node -> m ()
|
||||||
application :: Node -> m ()
|
application :: Node -> m ()
|
||||||
getContext :: m Context
|
getContext :: m Context
|
||||||
|
@ -163,7 +163,7 @@ instance ToJSON Result where
|
||||||
go :: (Node, Set Node) -> (Text, Aeson.Value)
|
go :: (Node, Set Node) -> (Text, Aeson.Value)
|
||||||
go (x, y) = (prettyContext x, Aeson.toJSON y)
|
go (x, y) = (prettyContext x, Aeson.toJSON y)
|
||||||
|
|
||||||
instance MyMonad (State Env) where
|
instance ReferenceM (State Env) where
|
||||||
declaration q = modify go
|
declaration q = modify go
|
||||||
where
|
where
|
||||||
go :: Env -> Env
|
go :: Env -> Env
|
||||||
|
@ -192,7 +192,7 @@ instance MyMonad (State Env) where
|
||||||
where
|
where
|
||||||
go env = env { Rubyhs.References.context = q }
|
go env = env { Rubyhs.References.context = q }
|
||||||
|
|
||||||
findClosest :: MyMonad m => Set Node -> Node -> m Node
|
findClosest :: ReferenceM m => Set Node -> Node -> m Node
|
||||||
findClosest decls n = do
|
findClosest decls n = do
|
||||||
Context c <- getContext
|
Context c <- getContext
|
||||||
pure $ go $ c
|
pure $ go $ c
|
||||||
|
@ -211,7 +211,7 @@ findClosest decls n = do
|
||||||
(NodeModule (Namespace [])) -> error "__IMPOSSIBLE__"
|
(NodeModule (Namespace [])) -> error "__IMPOSSIBLE__"
|
||||||
(NodeModule (Namespace xs)) -> NodeModule $ Namespace $ reverse $ Prelude.tail $ reverse xs
|
(NodeModule (Namespace xs)) -> NodeModule $ Namespace $ reverse $ Prelude.tail $ reverse xs
|
||||||
|
|
||||||
locally :: MyMonad m => m a -> m a
|
locally :: ReferenceM m => m a -> m a
|
||||||
locally act = do
|
locally act = do
|
||||||
old <- getContext
|
old <- getContext
|
||||||
res <- act
|
res <- act
|
||||||
|
@ -219,7 +219,7 @@ locally act = do
|
||||||
pure res
|
pure res
|
||||||
|
|
||||||
class References a where
|
class References a where
|
||||||
entries :: MyMonad m => a -> m ()
|
entries :: ReferenceM m => a -> m ()
|
||||||
|
|
||||||
references :: Ruby.Begin -> Result
|
references :: Ruby.Begin -> Result
|
||||||
references q = Result $ HashMap.unionWith mappend applications declarations'
|
references q = Result $ HashMap.unionWith mappend applications declarations'
|
||||||
|
@ -229,7 +229,7 @@ references q = Result $ HashMap.unionWith mappend applications declarations'
|
||||||
declarations' = fromList $ (\x -> (x, mempty)) <$> toList declarations
|
declarations' = fromList $ (\x -> (x, mempty)) <$> toList declarations
|
||||||
|
|
||||||
instance References Ruby.Begin where
|
instance References Ruby.Begin where
|
||||||
entries :: forall m . MyMonad m => Ruby.Begin -> m ()
|
entries :: forall m . ReferenceM m => Ruby.Begin -> m ()
|
||||||
entries (Ruby.Begin defs) = traverse_ (locally . entries) defs
|
entries (Ruby.Begin defs) = traverse_ (locally . entries) defs
|
||||||
|
|
||||||
instance References Ruby.Statement where
|
instance References Ruby.Statement where
|
||||||
|
@ -293,7 +293,7 @@ instance References Ruby.Int where
|
||||||
instance References Ruby.Const where
|
instance References Ruby.Const where
|
||||||
entries con = application $ NodeModule $ constToNamespace con
|
entries con = application $ NodeModule $ constToNamespace con
|
||||||
|
|
||||||
updateContext :: MyMonad m => (Context -> Context) -> m ()
|
updateContext :: ReferenceM m => (Context -> Context) -> m ()
|
||||||
updateContext f = getContext >>= \c -> writeContext (f c)
|
updateContext f = getContext >>= \c -> writeContext (f c)
|
||||||
|
|
||||||
instance References Ruby.Module where
|
instance References Ruby.Module where
|
||||||
|
@ -305,7 +305,7 @@ instance References Ruby.Module where
|
||||||
declaration $ NodeModule c
|
declaration $ NodeModule c
|
||||||
entries begin
|
entries begin
|
||||||
|
|
||||||
atomToNode :: MyMonad m => Ruby.Atom -> m Node
|
atomToNode :: ReferenceM m => Ruby.Atom -> m Node
|
||||||
atomToNode (Ruby.Atom name) = do
|
atomToNode (Ruby.Atom name) = do
|
||||||
namespace <- getContext >>= pure . \case
|
namespace <- getContext >>= pure . \case
|
||||||
Context (NodeModule c) -> c
|
Context (NodeModule c) -> c
|
||||||
|
|
Loading…
Reference in a new issue