You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
958 B
Kotlin
34 lines
958 B
Kotlin
package me.eater.hefbrug.dsl.context
|
|
|
|
import me.eater.hefbrug.dsl.annotation.HefbrugDSL
|
|
import me.eater.hefbrug.selector.*
|
|
|
|
@HefbrugDSL
|
|
interface SelectionDefinitionContext<C> {
|
|
fun select(selector: SelectorInterface, block: C)
|
|
fun all() = TrueSelector()
|
|
fun node(selector: String): SelectorInterface = NodeSelector(selector)
|
|
fun group(name: String): SelectorInterface = GroupSelector(name)
|
|
fun group(vararg name: String): SelectorInterface = AllSelector(name.map { GroupSelector(it) })
|
|
|
|
|
|
fun group(name: String, block: C) {
|
|
select(GroupSelector(name), block)
|
|
}
|
|
|
|
fun group(vararg name: String, block: C) {
|
|
select(group(*name), block)
|
|
}
|
|
|
|
fun node(selector: String, block: C) {
|
|
select(node(selector), block)
|
|
}
|
|
|
|
fun all(block: C) {
|
|
select(all(), block)
|
|
}
|
|
|
|
operator fun SelectorInterface.invoke(block: C) {
|
|
this@SelectionDefinitionContext.select(this, block)
|
|
}
|
|
} |