From c6d5be92ee89cdedc645df2a4ac1b408ecc3dc77 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 17 May 2020 01:05:43 +0800 Subject: [PATCH] Add reified parsers --- .../description/CommandParserContext.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandParserContext.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandParserContext.kt index 1a9b8c2c6..ad4f0096d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandParserContext.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandParserContext.kt @@ -126,6 +126,9 @@ class CommandParserContextBuilder : MutableList> by mutableListOf( inline infix fun KClass.with(parser: CommandArgParser): ParserPair<*> = ParserPair(this, parser).also { add(it) } + inline infix fun add(parser: CommandArgParser): ParserPair<*> = + ParserPair(T::class, parser).also { add(it) } + /** * 添加一个指令解析器 */ @@ -142,6 +145,23 @@ class CommandParserContextBuilder : MutableList> by mutableListOf( inline infix fun KClass.with( crossinline parser: CommandArgParser.(s: String) -> T ): ParserPair<*> = ParserPair(this, CommandArgParser { s: String, _: CommandSender -> parser(s) }).also { add(it) } + + /** + * 添加一个指令解析器 + */ + @JvmSynthetic + inline infix fun add( + crossinline parser: CommandArgParser<*>.(s: String) -> T + ): ParserPair<*> = T::class with CommandArgParser { s: String, _: CommandSender -> parser(s) } + + /** + * 添加一个指令解析器 + */ + @JvmSynthetic + @LowPriorityInOverloadResolution + inline infix fun add( + crossinline parser: CommandArgParser<*>.(s: String, sender: CommandSender) -> T + ): ParserPair<*> = T::class with CommandArgParser(parser) }