diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-10-28 20:14:16 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-10-28 20:14:16 +0100 |
| commit | 1d1f0efc7de1eaa0c8a6b503892c2f950008fde6 (patch) | |
| tree | bd2e2ea5963d8a208d302854502f580d8ffd73cb /lambda-calcul/haskell/src/Minilang/REPL.hs | |
| parent | a210419fd60c00d011f70fb1b968031621e4c01a (diff) | |
| download | lambda-nantes-1d1f0efc7de1eaa0c8a6b503892c2f950008fde6.tar.gz | |
wip: port REPL from minilang
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL.hs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL.hs b/lambda-calcul/haskell/src/Minilang/REPL.hs new file mode 100644 index 0000000..a5ffce1 --- /dev/null +++ b/lambda-calcul/haskell/src/Minilang/REPL.hs @@ -0,0 +1,59 @@ +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# OPTIONS_GHC "-fno-warn-orphans" #-} + +module Minilang.REPL where + +import Control.Monad.Catch.Pure (CatchT (..)) +import Control.Monad.State +import Data.Text hiding (replicate) +import Minilang.REPL.Haskeline +import Minilang.REPL.IO +import Minilang.REPL.Pure +import Minilang.REPL.Purer +import Minilang.REPL.Run +import Minilang.REPL.Types +import System.Console.Haskeline ( + defaultBehavior, + defaultSettings, + historyFile, + runInputTBehavior, + setComplete, + ) +import System.IO (Handle) + +-- * Haskeline REPL + +withTerminal :: IO () +withTerminal = + runInputTBehavior defaultBehavior settings $ evalStateT (runHaskeline runREPL) initialREPL + where + settings = setComplete completion $ defaultSettings{historyFile = Just "~/.minilang.history"} + +-- * Other REPLs + +{- | Pure IO REPL + Used for testing purposes +-} + +-- | +withHandles :: + Handle -> Handle -> IO () +withHandles hin hout = + evalStateT (runConsole runREPL) (IOEnv hin hout initialREPL) + +-- * Pure REPL + +withInput :: + [Text] -> [Text] +withInput stream = + outputText $ execState (runCatchT (runPure runREPL)) (PureEnv stream [] initialREPL) +-- * Purer REPL + +-- This useful for rehydrating and environment from a sequence of inputs + +withInputs :: + REPLEnv -> [In] -> PurerEnv +withInputs initEnv stream = + execState (runCatchT (runPurer runREPL)) (PurerEnv stream [] initEnv) |
