2017-09-23 17:13:56 -07:00
|
|
|
package org.nwapw.abacus.plugin.standard.operator
|
2017-09-21 13:39:38 -07:00
|
|
|
|
2017-11-23 02:21:06 -08:00
|
|
|
import org.nwapw.abacus.context.PluginEvaluationContext
|
2017-09-21 13:39:38 -07:00
|
|
|
import org.nwapw.abacus.function.OperatorAssociativity
|
|
|
|
import org.nwapw.abacus.function.OperatorType
|
2017-11-14 23:03:12 -08:00
|
|
|
import org.nwapw.abacus.function.interfaces.NumberOperator
|
2017-09-21 13:39:38 -07:00
|
|
|
import org.nwapw.abacus.number.NumberInterface
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The addition operator.
|
|
|
|
*
|
|
|
|
* This is a standard operator that simply performs addition.
|
|
|
|
*/
|
2018-01-16 00:14:15 -08:00
|
|
|
class OperatorAdd: NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1) {
|
2017-09-21 13:39:38 -07:00
|
|
|
|
2017-11-23 02:21:06 -08:00
|
|
|
override fun matchesParams(context: PluginEvaluationContext, params: Array<out NumberInterface>) =
|
2017-09-21 13:39:38 -07:00
|
|
|
params.size == 2
|
2017-11-23 02:21:06 -08:00
|
|
|
override fun applyInternal(context: PluginEvaluationContext, params: Array<out NumberInterface>) =
|
2017-09-21 13:39:38 -07:00
|
|
|
params[0] + params[1]
|
|
|
|
|
|
|
|
}
|