Skip to content

Instantly share code, notes, and snippets.

@AndyG
Created February 24, 2018 00:00
Show Gist options
  • Save AndyG/335283bf51eb54e822c9e359ffe5ce6a to your computer and use it in GitHub Desktop.
Save AndyG/335283bf51eb54e822c9e359ffe5ce6a to your computer and use it in GitHub Desktop.
Basic Abstract Syntax Tree Node
open class Node {
private var children: MutableCollection<Node>? = null
fun getChildren(): Collection<Node>? = children
fun hasChildren(): Boolean = children?.isNotEmpty() == true
fun addChild(child: Node) {
children = (children ?: ArrayList()).apply {
add(child)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment