License | GPL-2 |
---|---|
Maintainer | yi-devel@googlegroups.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Little helper for completion interfaces.
Intended to be imported qualified:
import qualified Yi.CompletionTree as CT
Synopsis
- newtype CompletionTree a = CompletionTree (Map a (CompletionTree a))
- fromList :: (Ord a, ListLike a i, Eq i) => [a] -> CompletionTree a
- toList :: (Ord a, ListLike a i) => CompletionTree a -> [a]
- complete :: (Eq i, Ord a, ListLike a i) => CompletionTree a -> (a, CompletionTree a)
- update :: (Ord a, ListLike a i, Eq i) => CompletionTree a -> a -> CompletionTree a
- pretty :: Show a => CompletionTree a -> String
- unCompletionTree :: Lens' (CompletionTree a) (Map a (CompletionTree a))
CompletionTree type
newtype CompletionTree a Source #
A CompletionTree is a map of partial completions.
Example:
fromList ["put","putStr","putStrLn","print","abc"]
Gives the following tree:
/ "p" "abc" / "ut" "rint" / Str "" / Ln ""
(The empty strings are needed to denote the end of a word) (A CompletionTree is not limited to a binary tree)
CompletionTree (Map a (CompletionTree a)) |
Instances
Lists
fromList :: (Ord a, ListLike a i, Eq i) => [a] -> CompletionTree a Source #
This function converts a list of completable elements to a CompletionTree It finds elements that share a common prefix and groups them.
fromList . toList = id
toList :: (Ord a, ListLike a i) => CompletionTree a -> [a] Source #
Converts a CompletionTree to a list of completions.
toList . fromList = sort . nub
Examples:
>>>
toList mempty
[]
>>>
toList (fromList ["a"])
["a"]
>>>
toList (fromList ["a","a","a"])
["a"]
>>>
toList (fromList ["z","x","y"])
["x","y","z"]
Modification
complete :: (Eq i, Ord a, ListLike a i) => CompletionTree a -> (a, CompletionTree a) Source #
Complete as much as possible without guessing.
Examples:
>>>
complete $ fromList ["put","putStrLn","putStr"]
("put", fromList ["","Str","StrLn"])
>>>
complete $ fromList ["put","putStr","putStrLn","abc"]
("", fromList ["put","putStr","putStrLn","abc"])
update :: (Ord a, ListLike a i, Eq i) => CompletionTree a -> a -> CompletionTree a Source #
Update the CompletionTree with new information. An empty list means that there is no completion left. A [mempty] means that the end of a word is reached.
Examples:
>>>
update (fromList ["put","putStr"]) "p"
fromList ["ut","utStr"]
>>>
update (fromList ["put","putStr"]) "put"
fromList ["","Str"]
>>>
update (fromList ["put","putStr"]) "putS"
fromList ["tr"]
>>>
update (fromList ["put"]) "find"
fromList []
>>>
update (fromList ["put"]) "put"
fromList [""]
Debugging
pretty :: Show a => CompletionTree a -> String Source #
For debugging purposes.
Example:
>>>
putStrLn $ pretty $ fromList ["put", "putStr", "putStrLn"]
["put"[""|"Str"[""|"Ln"]]]
Lens
unCompletionTree :: Lens' (CompletionTree a) (Map a (CompletionTree a)) Source #