diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2022-09-23 11:05:28 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-05 14:21:52 +0200 |
| commit | 335ed87f5d672fd6a3de856fef62963c2946318f (patch) | |
| tree | 1c9494ff04d70ac4a39c330dbc5dbb574df1fa0e | |
| parent | 11ba54ee5c0f3dfd0c3d62a1943d87426280f84d (diff) | |
Add dumb REPL
| -rw-r--r-- | app/Main.hs | 15 | ||||
| -rw-r--r-- | lang.cabal | 3 | ||||
| -rw-r--r-- | package.yaml | 1 | ||||
| -rw-r--r-- | src/Lib.hs | 7 | ||||
| -rw-r--r-- | stack.yaml | 2 | ||||
| -rw-r--r-- | stack.yaml.lock | 14 |
6 files changed, 39 insertions, 3 deletions
diff --git a/app/Main.hs b/app/Main.hs index 3e92547..6115252 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,6 +2,7 @@ module Main (main) where import System.Environment import Control.Monad.Except import Control.Monad.Reader +import System.Console.Haskeline import Types import Lib @@ -16,6 +17,16 @@ parseArgs config args = config { configShowHelp = True } rest _ -> config +repl :: InputT IO () +repl = do + minput <- getInputLine "> " + case minput of + Nothing -> return () + Just "exit" -> return () + Just input -> do + outputStrLn $ "Input was: " ++ input + repl + main :: IO () main = do args <- getArgs @@ -44,6 +55,6 @@ main = do case result of Left (LException ex) -> putStrLn $ "Error: " ++ ex Right () -> return () - Nothing -> error "TODO REPL" - + Nothing -> do + runInputT defaultSettings repl return () @@ -36,6 +36,7 @@ library build-depends: base >=4.7 && <5 , containers + , haskeline ==0.8.2 , mtl default-language: Haskell2010 @@ -49,6 +50,7 @@ executable lang-exe build-depends: base >=4.7 && <5 , containers + , haskeline ==0.8.2 , lang , mtl default-language: Haskell2010 @@ -64,6 +66,7 @@ test-suite lang-test build-depends: base >=4.7 && <5 , containers + , haskeline ==0.8.2 , lang , mtl default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 0ac218c..894f5f4 100644 --- a/package.yaml +++ b/package.yaml @@ -23,6 +23,7 @@ dependencies: - base >= 4.7 && < 5 - containers - mtl +- haskeline == 0.8.2 ghc-options: - -Wall @@ -1,6 +1,6 @@ module Lib ( runScriptFile, - LContext + runInlineScript, ) where import qualified Data.Map as M @@ -9,6 +9,7 @@ import Control.Monad.Except import Control.Monad.Reader import Data.List import Debug.Trace +import System.Console.Haskeline import Types import Utils @@ -75,6 +76,10 @@ parse src = [] runScriptFile :: String -> LContext () runScriptFile fileName = do src <- liftIO $ readFile fileName + runInlineScript src + +runInlineScript :: String -> LContext () +runInlineScript src = do tokenized <- tokenize src config <- ask when (configVerboseMode config) $ liftIO $ putStrLn $ "tokenized:\t\t" ++ show tokenized @@ -4,3 +4,5 @@ system-ghc: true resolver: compiler: ghc-9.4.2 require-stack-version: ==2.7.5 +extra-deps: + - haskeline-0.8.2
\ No newline at end of file diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..5200f97 --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,14 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: haskeline-0.8.2@sha256:3a80aff4c751b475337ace00ac5757c5d47a47de94954fb87cce168a90e19c7a,6005 + pantry-tree: + size: 2955 + sha256: a51f2be1d61d077b8c972d762e9799983f08c95cae5123cf8ade8803e3250579 + original: + hackage: haskeline-0.8.2 +snapshots: [] |
