Copyright | (c) Dan Doel, 2016 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe |
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.
- 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.
Functor Recognizer Source # | |
Show a => Show (Recognizer a) Source # | |
Monoid (Recognizer a) Source # | |
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 |
Functor Recognition Source # | |
Show a => Show (Recognition a) Source # | |
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
.