Copyright | (c) Dan Doel 2016 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module implements a trie for recognizing valid commands. This allows entered strings to be classified as either a valid command (with an associated value), the prefix of a valid command, or invalid.
Synopsis
- data Recognizer a
- recognize :: Text -> Recognizer a -> Recognition a
- data Recognition a
- fromCommands :: [(Text, a)] -> Recognizer a
- addCommand :: Text -> a -> Recognizer a -> Recognizer a
- keys :: Recognizer a -> [Text]
Documentation
data Recognizer a Source #
A map from Text
values to a
values that is capable of yielding more
detailed information when looking up keys that are not actually in the map.
Instances
recognize :: Text -> Recognizer a -> Recognition a Source #
Attempt to recognize a string, yielding a Recognition
result.
data Recognition a Source #
Possible results of recognizing text.
Exact a | text matched exactly, yielding the given value |
Prefix [Text] | text would be recognized if joined to the given suffixes |
Invalid | text could not possibly be recognized |
Instances
Functor Recognition Source # | |
Defined in Client.Commands.Recognizer fmap :: (a -> b) -> Recognition a -> Recognition b # (<$) :: a -> Recognition b -> Recognition a # | |
Show a => Show (Recognition a) Source # | |
Defined in Client.Commands.Recognizer showsPrec :: Int -> Recognition a -> ShowS # show :: Recognition a -> String # showList :: [Recognition a] -> ShowS # |
fromCommands :: [(Text, a)] -> Recognizer a Source #
Create a Recognizer
from an association list. If a key appears twice, the
earliest associated value will be used.
addCommand :: Text -> a -> Recognizer a -> Recognizer a Source #
Add a key-value pair to a Recognizer
. This will override the value
already present if one exists.
keys :: Recognizer a -> [Text] Source #
Compute all strings that will be recognized by a Recognizer
.