diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-02 18:18:50 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-02 18:18:50 +0100 |
| commit | d8e4ef2a4611682e273ca18189b1bebf791a1bb8 (patch) | |
| tree | 64f95ac3e30a6a2a7898da300f982257202f4393 /lambda-calcul/haskell/src/Minilang/REPL | |
| parent | 00ef8caacaa576b4045d43a5bdddd81a2d093496 (diff) | |
| download | lambda-nantes-d8e4ef2a4611682e273ca18189b1bebf791a1bb8.tar.gz | |
fix tests and add HTML stuff to deployment
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs | 2 | ||||
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL/IO.hs | 3 | ||||
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL/Pure.hs | 11 |
3 files changed, 12 insertions, 4 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs b/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs index a822116..cbc7988 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs @@ -83,7 +83,7 @@ completion' (inputString, _) = ] completeLoadWithFiles prefix = do - files <- filter (prefix `isPrefixOf`) . filter (".mtt" `isSuffixOf`) <$> listDirectory "." + files <- filter (prefix `isPrefixOf`) . filter (".lisp" `isSuffixOf`) <$> listDirectory "." pure ("", fmap (\fp -> Completion (":load " <> fp) fp True) files) setUnsetCompletion com = diff --git a/lambda-calcul/haskell/src/Minilang/REPL/IO.hs b/lambda-calcul/haskell/src/Minilang/REPL/IO.hs index 90b1e5d..ad6d52b 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/IO.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/IO.hs @@ -11,6 +11,7 @@ import Data.Text.IO as Text import Minilang.REPL.Types import System.IO (Handle, hFlush) import System.IO.Error (isEOFError) +import Minilang.REPL.Pure (render) data IOEnv = IOEnv { inputHandle :: Handle, @@ -23,7 +24,7 @@ newtype CONSOLE m a = CONSOLE {runConsole :: StateT IOEnv m a} instance MonadREPL (CONSOLE IO) where input = get >>= lift . (\h -> (interpret <$> hGetLine h) `catch` \(isEOFError -> True) -> pure EOF) . inputHandle - output a = get >>= lift . flip hPutStrLn (pack $ show a) . outputHandle + output a = get >>= lift . flip hPutStrLn (render a) . outputHandle prompt = get >>= lift . (\h -> hPutStr h "λΠ> " >> hFlush h) . outputHandle getEnv = get >>= pure . repl setEnv e' = modify $ \e -> e {repl = e'} diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs index 23c45e1..91e71b9 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs @@ -8,6 +8,8 @@ import Control.Monad.Catch import Control.Monad.Catch.Pure (CatchT (..)) import Control.Monad.State import Data.Text hiding (replicate) +import Minilang.Lambda.Parser (pretty, resugar) +import qualified Minilang.Lambda.Unify as Type import Minilang.REPL.Types data PureEnv = PureEnv @@ -21,20 +23,25 @@ newtype PureREPL a = PureREPL {runPure :: CatchT (State PureEnv) a} instance MonadREPL PureREPL where input = do - ins <- inputText <$> get + ins <- gets inputText case ins of [] -> pure EOF (t : ts) -> modify (\e -> e {inputText = ts}) >> pure (interpret t) output t = modify $ \e -> e {outputText = render t : outputText e} + prompt = pure () - getEnv = get >>= pure . pureREPL + + getEnv = gets pureREPL + setEnv e' = modify $ \e -> e {pureREPL = e'} + load f = pure $ Left $ REPLError $ "cannot load file " <> f <> " in Pure interpreter" render :: Out -> Text render = \case Msg t -> t + Evaluated term typ -> pretty (resugar term) <> " : " <> Type.pretty typ Bye -> "Bye!" other -> pack (show other) |
