1
0
mirror of https://github.com/DanilaFe/abacus synced 2025-12-28 03:31:08 +00:00

Switch Abacus to returning an EvaluationResult with the context.

This commit is contained in:
2017-09-06 22:22:15 -07:00
parent 782669a32b
commit ef1890f24d
4 changed files with 29 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import org.nwapw.abacus.plugin.ClassFinder;
import org.nwapw.abacus.plugin.PluginListener;
import org.nwapw.abacus.plugin.PluginManager;
import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.tree.EvaluationResult;
import org.nwapw.abacus.tree.TreeNode;
import java.io.File;
@@ -144,12 +145,14 @@ public class AbacusController implements PluginListener {
if (constructedTree == null) {
return ERR_SYNTAX;
}
NumberInterface evaluatedNumber = abacus.evaluateTree(constructedTree);
EvaluationResult result = abacus.evaluateTree(constructedTree);
NumberInterface evaluatedNumber = result.getValue();
if (evaluatedNumber == null) {
return ERR_EVAL;
}
String resultingString = evaluatedNumber.toString();
historyData.add(new HistoryModel(inputField.getText(), constructedTree.toString(), resultingString));
abacus.applyToContext(result.getResultingContext());
return resultingString;
} catch (ComputationInterruptedException exception) {
return ERR_STOP;