Add reified parsers

This commit is contained in:
Him188 2020-05-17 01:05:43 +08:00
parent 2dda8a4a7e
commit c6d5be92ee

View File

@ -126,6 +126,9 @@ class CommandParserContextBuilder : MutableList<ParserPair<*>> by mutableListOf(
inline infix fun <T : Any> KClass<T>.with(parser: CommandArgParser<T>): ParserPair<*> =
ParserPair(this, parser).also { add(it) }
inline infix fun <reified T : Any> add(parser: CommandArgParser<T>): ParserPair<*> =
ParserPair(T::class, parser).also { add(it) }
/**
* 添加一个指令解析器
*/
@ -142,6 +145,23 @@ class CommandParserContextBuilder : MutableList<ParserPair<*>> by mutableListOf(
inline infix fun <T : Any> KClass<T>.with(
crossinline parser: CommandArgParser<T>.(s: String) -> T
): ParserPair<*> = ParserPair(this, CommandArgParser { s: String, _: CommandSender -> parser(s) }).also { add(it) }
/**
* 添加一个指令解析器
*/
@JvmSynthetic
inline infix fun <reified T : Any> add(
crossinline parser: CommandArgParser<*>.(s: String) -> T
): ParserPair<*> = T::class with CommandArgParser { s: String, _: CommandSender -> parser(s) }
/**
* 添加一个指令解析器
*/
@JvmSynthetic
@LowPriorityInOverloadResolution
inline infix fun <reified T : Any> add(
crossinline parser: CommandArgParser<*>.(s: String, sender: CommandSender) -> T
): ParserPair<*> = T::class with CommandArgParser(parser)
}