1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-13 19:49:20 +03:00
juvix/app/Commands/Repl/Base.hs
Jan Mas Rovira e944f85074
Add :def command to the repl (#2119)
This pr adds a new command, `:def` to the repl. This command expects a
single identifier that must be in scope and then prints its definition.
For constructors, the whole type definition is printed.

It also applies some refactors to the code for repl command.
1. Before there was a mega `where` block of definitions. I have hoisted
most of the definitions there to the top level. I feel like now it is
easier to navigate and read.
2. Use `ExceptT` instead of local `case` expressions for errors.
3. Use forks of `haskeline` and `repline`. These forks are necessary
because these libraries do not export the constructors `HaskelineT` and
`InputT` respectively, thus, making it impossible to catch errors in
their underlying monad.
2023-05-30 10:19:09 +02:00

35 lines
836 B
Haskell

module Commands.Repl.Base where
import Commands.Base hiding
( command,
)
import Commands.Repl.Options
import Control.Monad.Except qualified as Except
import Control.Monad.Reader qualified as Reader
import Control.Monad.State.Strict qualified as State
import System.Console.Repline
type ReplS = Reader.ReaderT ReplEnv (State.StateT ReplState (Except.ExceptT JuvixError IO))
type Repl a = HaskelineT ReplS a
data ReplContext = ReplContext
{ _replContextArtifacts :: Artifacts,
_replContextEntryPoint :: EntryPoint
}
data ReplEnv = ReplEnv
{ _replRoots :: Roots,
_replOptions :: ReplOptions
}
data ReplState = ReplState
{ _replStateRoots :: Roots,
_replStateContext :: Maybe ReplContext,
_replStateGlobalOptions :: GlobalOptions
}
makeLenses ''ReplState
makeLenses ''ReplContext
makeLenses ''ReplEnv