Safe Haskell | None |
---|---|
Language | Haskell2010 |
Something that can parse user input
Synopsis
- class Typeable a => ParameterParser (a :: Type) c r where
- type ParserResult a
- parameterInfo :: ParameterInfo
- parameterDescription :: 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 (Reader c ': r)) a -> Sem (ParserEffs c r) a
- data SpannedError = SpannedError Text !Int !Int
Documentation
class Typeable a => ParameterParser (a :: Type) c 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.
type ParserResult a Source #
type ParserResult a = a
parameterInfo :: ParameterInfo Source #
default parameterInfo :: ParameterInfo Source #
parameterDescription :: 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 c r) => ParameterParser (Named s a) c r Source # | |
Defined in CalamityCommands.Parser type ParserResult (Named s a) Source # parameterInfo :: ParameterInfo Source # parameterDescription :: Text Source # parse :: Sem (ParserEffs c r) (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
Parameter parsing utilities
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.
Instances
Show ParserState Source # | |
Defined in CalamityCommands.Parser showsPrec :: Int -> ParserState -> ShowS # show :: ParserState -> String # showList :: [ParserState] -> ShowS # | |
Generic ParserState Source # | |
Defined in CalamityCommands.Parser type Rep ParserState :: Type -> Type # from :: ParserState -> Rep ParserState x # to :: Rep ParserState x -> ParserState # | |
type Rep ParserState Source # | |
Defined in CalamityCommands.Parser type Rep ParserState = D1 ('MetaData "ParserState" "CalamityCommands.Parser" "calamity-commands-0.2.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))) |
:: Text | The name of the parser |
-> ParsecT SpannedError Text (Sem (Reader c ': r)) a | The megaparsec parser |
-> Sem (ParserEffs c r) a |
Parse a paremeter using a MegaParsec parser.
On failure this constructs a nice-looking megaparsec error for the failed parameter.
data SpannedError Source #
Instances
Eq SpannedError Source # | |
Defined in CalamityCommands.Parser (==) :: SpannedError -> SpannedError -> Bool # (/=) :: SpannedError -> SpannedError -> Bool # | |
Ord SpannedError Source # | |
Defined in CalamityCommands.Parser compare :: SpannedError -> SpannedError -> Ordering # (<) :: SpannedError -> SpannedError -> Bool # (<=) :: SpannedError -> SpannedError -> Bool # (>) :: SpannedError -> SpannedError -> Bool # (>=) :: SpannedError -> SpannedError -> Bool # max :: SpannedError -> SpannedError -> SpannedError # min :: SpannedError -> SpannedError -> SpannedError # | |
Show SpannedError Source # | |
Defined in CalamityCommands.Parser showsPrec :: Int -> SpannedError -> ShowS # show :: SpannedError -> String # showList :: [SpannedError] -> ShowS # | |
ShowErrorComponent SpannedError Source # | |
Defined in CalamityCommands.Parser |