1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-09-22 03:12:33 +00:00

Add a separate class of exceptions for NumberReducer.

This commit is contained in:
2017-09-22 11:58:19 -07:00
parent 76fcd8ec1c
commit 8dc7acd4b3
4 changed files with 33 additions and 12 deletions

View File

@@ -2,7 +2,8 @@ package org.nwapw.abacus.tree
import org.nwapw.abacus.Abacus
import org.nwapw.abacus.context.EvaluationContext
import org.nwapw.abacus.exception.EvaluationException
import org.nwapw.abacus.exception.NumberReducerException
import org.nwapw.abacus.exception.ReductionException
import org.nwapw.abacus.number.NumberInterface
class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<NumberInterface> {
@@ -24,7 +25,7 @@ class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<Nu
if(variable != null) return variable
val definition = context.getDefinition(treeNode.variable)
if(definition != null) return definition.reduce(this)
throw EvaluationException("variable is not defined.")
throw NumberReducerException("variable is not defined.")
}
is NumberUnaryNode -> {
val child = children[0] as NumberInterface
@@ -57,7 +58,7 @@ class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<Nu
abacus.pluginManager.treeValueFunctionFor(treeNode.callTo)
.apply(context, *treeNode.children.toTypedArray())
}
else -> throw EvaluationException("unrecognized tree node.")
else -> throw ReductionException("unrecognized tree node.")
}
}