when writing nested DSLs, is there a good way to d...
# getting-started
b
when writing nested DSLs, is there a good way to deal with the scope growing larger and potential accidental assignment to outer scopes? E.g. in the following example, name is accidentally assigned to the root node twice
Copy code
class Node(var name: String)
class NodeWithoutName
fun node(block: Node.() -> Unit) {}
fun nodeWithoutName(block: NodeWithoutName.() -> Unit) {}

node {
    name = "test"
    nodeWithoutName {
        name = "test"
    }
}
1
j
Annotate your receiver classes with an annotation like
@MyDsl
that is itself marked with
@DslMarker
b
oh, thank you 🙂