2017-08-07 18:57:43 -07:00
|
|
|
package org.nwapw.abacus.tree
|
|
|
|
|
2017-08-07 19:11:13 -07:00
|
|
|
/**
|
|
|
|
* A tree node that holds a unary operation.
|
|
|
|
*
|
|
|
|
* This node holds a single operator applied to a single parameter, and does not care
|
|
|
|
* whether the operation was found before or after the parameter in the text.
|
|
|
|
*
|
|
|
|
* @param operation the operation applied to the given node.
|
|
|
|
* @param applyTo the node to which the operation will be applied.
|
|
|
|
*/
|
2017-08-25 01:07:59 -07:00
|
|
|
class UnaryNode(val operation: String, val applyTo: TreeNode? = null) : TreeNode() {
|
2017-08-07 18:57:43 -07:00
|
|
|
|
|
|
|
override fun <T : Any> reduce(reducer: Reducer<T>): T? {
|
|
|
|
val reducedChild = applyTo?.reduce(reducer) ?: return null
|
|
|
|
return reducer.reduceNode(this, reducedChild)
|
|
|
|
}
|
|
|
|
|
2017-08-07 19:22:35 -07:00
|
|
|
override fun toString(): String {
|
|
|
|
return "(" + (applyTo?.toString() ?: "null") + ")" + operation
|
|
|
|
}
|
|
|
|
|
2017-08-07 18:57:43 -07:00
|
|
|
}
|