This commit is contained in:
2025-12-30 19:55:39 +00:00
parent 91aac70edf
commit 579b82b4ed
2 changed files with 10 additions and 16 deletions
-2
View File
@@ -1,5 +1,3 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Placement.Instance.Sensor (
lightSensor,
damageSensor,
+10 -14
View File
@@ -1,5 +1,4 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
module Dodge.Terminal (
makeTermLine,
@@ -162,8 +161,8 @@ data TabCompletion a
| TabMultiComplete [String]
| TabFail
data RecCommands a =
RCommands {_rCommands :: (PTE.TrieMap Char (Either (RecCommands a) a))}
newtype RecCommands a =
RCommands {_rCommands :: PTE.TrieMap Char (Either (RecCommands a) a)}
-- assumes that each command Trie has at least one successful command
recComFindMin :: RecCommands a -> Maybe ([String], a)
@@ -207,9 +206,6 @@ recComFindPredecessor (s:ss) (RCommands m)
Just (s',Left rm') -> recComFindMax rm' & _Just . _1 .:~ s'
Nothing -> Nothing
recComFindPredecessor [] rm = recComFindMax rm
--
--recComFindPredecessor :: [String] -> RecCommands a -> Maybe ([String],a)
--recComFindPredecessor (s:ss) (RCommands m) = Nothing
instance Semigroup (RecCommands a) where
RCommands x <> RCommands y = RCommands $ x <> y
@@ -221,7 +217,7 @@ instance Monoid (RecCommands a) where
tbComplete :: String -> PTE.TrieMap Char a -> TabCompletion a
tbComplete s t = case e of
[] | Just x <- mx -> TabMatch x
[] -> case fmap fst $ PTE.toList t' of
[] -> case fst <$> PTE.toList t' of
[] -> TabFail
ss -> TabMultiComplete ss
_ -> TabComplete e
@@ -229,14 +225,14 @@ tbComplete s t = case e of
(e, mx, t') = PTE.splitPrefix $ PTE.deletePrefix s t
recTabComplete :: String -> TCommands -> TabCompletion [TerminalLine]
recTabComplete s (RCommands t) = fromMaybe (TabMultiComplete $ allstrings $ t) $ do
recTabComplete s (RCommands t) = fromMaybe (TabMultiComplete $ allstrings t) $ do
(s1,ss) <- stripHead $ words s
case tbComplete s1 t of
TabComplete e -> return $ TabComplete e
TabMultiComplete es -> return $ TabMultiComplete (fmap (s1 <>) es)
TabFail -> return $ TabFail
TabMatch (Right x) -> return $ TabMatch x
TabMatch (Left rm) -> return $ recTabComplete (unwords ss) rm
return $ case tbComplete s1 t of
TabComplete e -> TabComplete e
TabMultiComplete es -> TabMultiComplete (fmap (s1 <>) es)
TabFail -> TabFail
TabMatch (Right x) -> TabMatch x
TabMatch (Left rm) -> recTabComplete (unwords ss) rm
where
stripHead (x:xs) = Just (x,xs)
stripHead _ = Nothing