Safe Haskell | None |
---|---|
Language | Haskell2010 |
CalamityCommands.Parser
Description
Something that can parse user input
Synopsis
- class Typeable a => ParameterParser (a :: Type) r where
- type ParserResult a
- parserName :: Text
- parse :: Sem (ParserEffs c r) (ParserResult a)
- data Named (s :: Symbol) (a :: Type)
- data KleeneStarConcat (a :: Type)
- data KleenePlusConcat (a :: Type)
- type ParserEffs c r = State ParserState ': (Error (Text, Text) ': (Reader c ': r))
- runCommandParser :: c -> Text -> Sem (ParserEffs c r) a -> Sem r (Either (Text, Text) a)
- data ParserState = ParserState {}
- parseMP :: Text -> ParsecT SpannedError Text (Sem (ParserCtxE c r)) a -> Sem (ParserEffs c r) a
Documentation
class Typeable a => ParameterParser (a :: Type) r where Source #
A typeclass for things that can be parsed as parameters to commands.
Any type that is an instance of ParamerParser can be used in the type level
parameter ps
of command
,
buildCommand
, etc.
Minimal complete definition
Methods
parserName :: Text Source #
default parserName :: Text Source #
parse :: Sem (ParserEffs c r) (ParserResult a) Source #
Instances
data Named (s :: Symbol) (a :: Type) Source #
A named parameter, used to attach the name s
to a type in the command's
help output
Instances
(KnownSymbol s, ParameterParser a r) => ParameterParser (Named s a) r Source # | |
Defined in CalamityCommands.Parser Associated Types type ParserResult (Named s a) Source # | |
type ParserResult (Named s a) Source # | |
Defined in CalamityCommands.Parser |
data KleeneStarConcat (a :: Type) Source #
A parser that consumes zero or more of a
then concatenates them together.
therefore consumes all remaining input.KleeneStarConcat
Text
Instances
data KleenePlusConcat (a :: Type) Source #
A parser that consumes one or more of a
then concatenates them together.
therefore consumes all remaining input.KleenePlusConcat
Text
Instances
type ParserEffs c r = State ParserState ': (Error (Text, Text) ': (Reader c ': r)) Source #
runCommandParser :: c -> Text -> Sem (ParserEffs c r) a -> Sem r (Either (Text, Text) a) Source #
Run a command parser, ctx
is the context, t
is the text input
data ParserState Source #
The current state of the parser, used so that the entire remaining input is available.
This is used instead of just concatenating parsers to allow for more flexibility, for example, this could be used to construct flag-style parsers that parse a parameter from anywhere in the input message.
Constructors
ParserState | |
Instances
Show ParserState Source # | |
Defined in CalamityCommands.Parser Methods showsPrec :: Int -> ParserState -> ShowS # show :: ParserState -> String # showList :: [ParserState] -> ShowS # | |
Generic ParserState Source # | |
Defined in CalamityCommands.Parser Associated Types type Rep ParserState :: Type -> Type # | |
type Rep ParserState Source # | |
Defined in CalamityCommands.Parser type Rep ParserState = D1 ('MetaData "ParserState" "CalamityCommands.Parser" "calamity-commands-0.1.0.0-inplace" 'False) (C1 ('MetaCons "ParserState" 'PrefixI 'True) (S1 ('MetaSel ('Just "off") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "msg") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text))) |