2017-08-25 17:46:25 -07:00
|
|
|
package org.nwapw.abacus.tree
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A unary operator node that reduces its children.
|
|
|
|
*
|
|
|
|
* NumberUnaryNode operates by simply reducing its child,
|
|
|
|
* and using the result of that reduction to reduce itself.
|
|
|
|
* @param operation the operation this node performs.
|
|
|
|
* @param child the child this node should be applied to.
|
|
|
|
*/
|
2017-09-07 12:31:40 -07:00
|
|
|
class NumberUnaryNode(operation: String, child: TreeNode)
|
2017-08-25 17:46:25 -07:00
|
|
|
: UnaryNode(operation, child) {
|
|
|
|
|
2017-09-07 12:53:12 -07:00
|
|
|
override fun <T : Any> reduce(reducer: Reducer<T>): T {
|
2017-09-07 12:31:40 -07:00
|
|
|
val child = applyTo.reduce(reducer)
|
2017-08-25 17:46:25 -07:00
|
|
|
return reducer.reduceNode(this, child)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|