ref: 105cf036ac97ef512fb36f047bda3473642dff1f
parent: 2561f291a37c4f12b37f88bc3c0457a3bbe81549
author: Lennart Augustsson <lennart@augustsson.net>
date: Wed Apr 3 16:56:00 EDT 2024
Move a function
--- a/src/MicroHs/Interactive.hs
+++ b/src/MicroHs/Interactive.hs
@@ -8,6 +8,7 @@
import MicroHs.Expr(EType, showEType)
import MicroHs.Flags
import MicroHs.Ident(mkIdent, Ident, unIdent, isIdentChar)
+import MicroHs.List
import MicroHs.Parse
import MicroHs.StateIO
import MicroHs.SymTab(Entry(..), stEmpty, stKeysGlbU)
@@ -28,8 +29,6 @@
mainInteractive :: Flags -> IO ()
mainInteractive flags = do
--- when (not usingMhs) $
--- error "Interactive mhs not available when compiled with ghc"
putStrLn "Welcome to interactive MicroHs!"
let flags' = flags{ loading = True }cash <- getCached flags'
@@ -179,7 +178,7 @@
err e = err' $ displayException e
err' :: String -> IO ()
-err' s = putStrLn $ "Error: " ++ s
+err' s = putStrLn $ "Exception: " ++ s
oneline :: String -> I ()
oneline line = do
@@ -277,6 +276,12 @@
TModule _ _ tys _ _ _ _ _ ->
head $ [ k | TypeExport i' (Entry _ k) _ <- tys, i == i' ] ++ [undefined]
+-- This could be smarter:
+-- ":a" should complete with commands
+-- "import A" should complete with modules
+-- operator completion
+-- completion with qualified names
+
complete :: Symbols -> (String, String) -> [String]
complete (tys, vals) (rpre, _post) =
let pre = reverse $ takeWhile isIdentChar rpre
@@ -290,11 +295,3 @@
case findCommonPrefix ss of
[] -> ss
p -> [p]
-
-findCommonPrefix :: Eq a => [[a]] -> [a]
-findCommonPrefix [] = []
-findCommonPrefix ([] : _) = []
-findCommonPrefix ((x:xs) : ys) | Just ys' <- mapM (f x) ys = x : findCommonPrefix (xs:ys')
- | otherwise = []
- where f a (b:bs) | a == b = Just bs
- f _ _ = Nothing
--- a/src/MicroHs/List.hs
+++ b/src/MicroHs/List.hs
@@ -60,3 +60,11 @@
showPairS :: forall a b . (a -> String) -> (b -> String) -> (a, b) -> String
showPairS sa sb (a, b) = "(" ++ sa a ++ "," ++ sb b ++ ")"+
+findCommonPrefix :: Eq a => [[a]] -> [a]
+findCommonPrefix [] = []
+findCommonPrefix ([] : _) = []
+findCommonPrefix ((x:xs) : ys) | Just ys' <- mapM (f x) ys = x : findCommonPrefix (xs:ys')
+ | otherwise = []
+ where f a (b:bs) | a == b = Just bs
+ f _ _ = Nothing
--
⑨