mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add a separate class of exceptions for NumberReducer.
This commit is contained in:
parent
76fcd8ec1c
commit
8dc7acd4b3
|
@ -0,0 +1,25 @@
|
||||||
|
package org.nwapw.abacus.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown by the NumberReducer if something goes wrong when
|
||||||
|
* transforming a parse tree into a single value.
|
||||||
|
*/
|
||||||
|
public class NumberReducerException extends AbacusException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new NumberReducerException with
|
||||||
|
* no additional message.
|
||||||
|
*/
|
||||||
|
public NumberReducerException() {
|
||||||
|
this("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new NumberReducerException with the given message.
|
||||||
|
* @param message the message.
|
||||||
|
*/
|
||||||
|
public NumberReducerException(String message) {
|
||||||
|
super("Error evaluating expression", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,16 +1,14 @@
|
||||||
package org.nwapw.abacus.exception;
|
package org.nwapw.abacus.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An exception thrown primarily from Tree Value operators and functions,
|
* An exception thrown from TreeReducers.
|
||||||
* which have to deal with the result of a Reducer as well as the results
|
|
||||||
* of Applicable.
|
|
||||||
*/
|
*/
|
||||||
public class EvaluationException extends AbacusException {
|
public class ReductionException extends AbacusException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new EvaluationException with the default string.
|
* Creates a new EvaluationException with the default string.
|
||||||
*/
|
*/
|
||||||
public EvaluationException() {
|
public ReductionException() {
|
||||||
this("");
|
this("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +16,7 @@ public class EvaluationException extends AbacusException {
|
||||||
* Creates a new EvaluationError with the given message string.
|
* Creates a new EvaluationError with the given message string.
|
||||||
* @param message the message string.
|
* @param message the message string.
|
||||||
*/
|
*/
|
||||||
public EvaluationException(String message) {
|
public ReductionException(String message) {
|
||||||
super("Evaluation error", message);
|
super("Evaluation error", message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ package org.nwapw.abacus.tree
|
||||||
|
|
||||||
import org.nwapw.abacus.Abacus
|
import org.nwapw.abacus.Abacus
|
||||||
import org.nwapw.abacus.context.EvaluationContext
|
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
|
import org.nwapw.abacus.number.NumberInterface
|
||||||
|
|
||||||
class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<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
|
if(variable != null) return variable
|
||||||
val definition = context.getDefinition(treeNode.variable)
|
val definition = context.getDefinition(treeNode.variable)
|
||||||
if(definition != null) return definition.reduce(this)
|
if(definition != null) return definition.reduce(this)
|
||||||
throw EvaluationException("variable is not defined.")
|
throw NumberReducerException("variable is not defined.")
|
||||||
}
|
}
|
||||||
is NumberUnaryNode -> {
|
is NumberUnaryNode -> {
|
||||||
val child = children[0] as NumberInterface
|
val child = children[0] as NumberInterface
|
||||||
|
@ -57,7 +58,7 @@ class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<Nu
|
||||||
abacus.pluginManager.treeValueFunctionFor(treeNode.callTo)
|
abacus.pluginManager.treeValueFunctionFor(treeNode.callTo)
|
||||||
.apply(context, *treeNode.children.toTypedArray())
|
.apply(context, *treeNode.children.toTypedArray())
|
||||||
}
|
}
|
||||||
else -> throw EvaluationException("unrecognized tree node.")
|
else -> throw ReductionException("unrecognized tree node.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,8 @@ import javafx.util.StringConverter;
|
||||||
import org.nwapw.abacus.Abacus;
|
import org.nwapw.abacus.Abacus;
|
||||||
import org.nwapw.abacus.config.Configuration;
|
import org.nwapw.abacus.config.Configuration;
|
||||||
import org.nwapw.abacus.exception.AbacusException;
|
import org.nwapw.abacus.exception.AbacusException;
|
||||||
import org.nwapw.abacus.exception.ComputationInterruptedException;
|
|
||||||
import org.nwapw.abacus.function.Documentation;
|
import org.nwapw.abacus.function.Documentation;
|
||||||
import org.nwapw.abacus.function.DocumentationType;
|
import org.nwapw.abacus.function.DocumentationType;
|
||||||
import org.nwapw.abacus.exception.DomainException;
|
|
||||||
import org.nwapw.abacus.exception.EvaluationException;
|
|
||||||
import org.nwapw.abacus.number.*;
|
import org.nwapw.abacus.number.*;
|
||||||
import org.nwapw.abacus.plugin.ClassFinder;
|
import org.nwapw.abacus.plugin.ClassFinder;
|
||||||
import org.nwapw.abacus.plugin.PluginListener;
|
import org.nwapw.abacus.plugin.PluginListener;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user