From 50cc51d08980b50a3955af6100479537e7fd8d15 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 23 Nov 2017 20:19:27 -0800 Subject: [PATCH] Load definition files. --- .../src/main/kotlin/org/nwapw/abacus/Abacus.kt | 8 ++++---- .../org/nwapw/abacus/fx/AbacusController.java | 18 +++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt b/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt index 661e92b..3acf465 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/Abacus.kt @@ -63,13 +63,13 @@ class Abacus(val configuration: Configuration) { * Reloads the Abacus core. */ fun reload(){ - pluginManager.reload() - with(mutableContext) { - numberImplementation = pluginManager.numberImplementationFor(configuration.numberImplementation) - ?: StandardPlugin.IMPLEMENTATION_NAIVE + with(mutableContext){ clearVariables() clearDefinitions() } + pluginManager.reload() + mutableContext.numberImplementation = pluginManager.numberImplementationFor(configuration.numberImplementation) + ?: StandardPlugin.IMPLEMENTATION_NAIVE } /** * Merges the current context with the provided one, updating diff --git a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 115bc2e..9dd75a0 100644 --- a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -325,7 +325,8 @@ public class AbacusController implements PluginListener { FileReader fileReader = new FileReader(definitionFile); Scanner scanner = new Scanner(fileReader); while(scanner.hasNext()){ - abacus.evaluateTree(abacus.parseString(scanner.nextLine())); + EvaluationResult result = abacus.evaluateTree(abacus.parseString(scanner.nextLine())); + abacus.applyToContext(result.getResultingContext()); } } catch (AbacusException abacusError) { outputText.setText(ERR_DEFINITION + "(" + abacusError.getMessage() + ")"); @@ -334,14 +335,6 @@ public class AbacusController implements PluginListener { } catch (FileNotFoundException ignored) {} } - private void reloadAbacus(){ - abacus.reload(); - ExtendedConfiguration abacusConfig = (ExtendedConfiguration) abacus.getConfiguration(); - for(String fileName: abacusConfig.getDefinitionFiles()) { - loadDefinitionFile(fileName); - } - } - @FXML public void performScan() { PluginManager abacusPluginManager = abacus.getPluginManager(); @@ -352,13 +345,13 @@ public class AbacusController implements PluginListener { } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } - reloadAbacus(); + abacus.reload(); } @FXML public void performReload() { alertIfApplyNeeded(true); - reloadAbacus(); + abacus.reload(); } @FXML @@ -425,6 +418,9 @@ public class AbacusController implements PluginListener { }).collect(Collectors.toCollection(ArrayList::new))); functionList.sort(Comparator.comparing(Documentation::getCodeName)); definitionFiles.addAll(configuration.getDefinitionFiles()); + for(String file : definitionFiles){ + loadDefinitionFile(file); + } } @Override