License | BSD (see the LICENSE file) |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Command.Parser
Description
Parser component for Commands. Its usage is mainly internal, to be used from Command.Command.
If you want to add your own parser argument type, you can either add it here (to be reused across multiple modules), or in your receive module (if it is only used there). Either works really, but sometimes you need the other to prevent looping imports.
Synopsis
- class ParsableArgument a where
- parserForArg :: Parser a
- newtype RemainingText = Remaining {}
- manyTill1 :: Stream s m t => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
- endOrSpaces :: Parser ()
Documentation
class ParsableArgument a where Source #
A ParsableArgument
is a dataclass that represents arguments that can be
parsed from a message text. Any datatype that is an instance of this dataclass
can be used as function arguments for a command handler in command
.
Instances
ParsableArgument String Source # | Any number of non-space characters. If quoted, spaces are allowed.
Quotes in quoted phrases can be escaped with a backslash. The following is
parsed as a single string:
|
Defined in Command.Parser Methods | |
ParsableArgument Text Source # | Wrapper for the String version, since Text is the trend nowadays. Both are provided so that it can easily be used for arguments in other functions that only accept one of the types. |
Defined in Command.Parser Methods | |
ParsableArgument ActivityType Source # | Parses "playing", "streaming", "listening to" and "competing in" as
|
Defined in Command.Parser Methods | |
ParsableArgument UpdateStatusType Source # | Parses "online" "dnd" "idle" and "invisible" as |
Defined in Command.Parser Methods | |
ParsableArgument Snowflake Source # | |
Defined in Command.Parser Methods | |
ParsableArgument RemainingText Source # | The rest of the arguments. Spaces and quotes are preserved as-is, unlike
with |
Defined in Command.Parser Methods | |
ParsableArgument [Text] Source # | Zero or more texts. Each one could be quoted or not. |
Defined in Command.Parser Methods parserForArg :: Parser [Text] Source # | |
ParsableArgument a => ParsableArgument (Maybe a) Source # | An argument that can or cannot exist. |
Defined in Command.Parser Methods parserForArg :: Parser (Maybe a) Source # | |
(ParsableArgument a, ParsableArgument b) => ParsableArgument (a, b) Source # | An argument that always has to be followed by another. |
Defined in Command.Parser Methods parserForArg :: Parser (a, b) Source # |
newtype RemainingText Source #
Datatype wrapper for the remaining text in the input. Handy for capturing
everything remaining. The accessor function getDeez
isn't really meant to be
used since pattern matching can do everything. Open to renaming.
Example usage:
setStatus = command "status" $ \msg newStatus newType (Remaining newName) -> do ...
Instances
ParsableArgument RemainingText Source # | The rest of the arguments. Spaces and quotes are preserved as-is, unlike
with |
Defined in Command.Parser Methods |
manyTill1 :: Stream s m t => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a] Source #
manyTill1 p end
is a parser that applies parser p
one or more times
until parser end
succeeds. This is a variation on manyTill
from Parsec.
endOrSpaces :: Parser () Source #
eofOrSpaces
is a parser that parses an end of command, or at least one
space and skips the result.