1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 07:20:09 -08:00

Load definition files.

This commit is contained in:
Danila Fedorin 2017-11-23 20:19:27 -08:00
parent 8f682e96af
commit 50cc51d089
2 changed files with 11 additions and 15 deletions

View File

@ -63,13 +63,13 @@ class Abacus(val configuration: Configuration) {
* Reloads the Abacus core. * Reloads the Abacus core.
*/ */
fun reload(){ fun reload(){
pluginManager.reload()
with(mutableContext){ with(mutableContext){
numberImplementation = pluginManager.numberImplementationFor(configuration.numberImplementation)
?: StandardPlugin.IMPLEMENTATION_NAIVE
clearVariables() clearVariables()
clearDefinitions() clearDefinitions()
} }
pluginManager.reload()
mutableContext.numberImplementation = pluginManager.numberImplementationFor(configuration.numberImplementation)
?: StandardPlugin.IMPLEMENTATION_NAIVE
} }
/** /**
* Merges the current context with the provided one, updating * Merges the current context with the provided one, updating

View File

@ -325,7 +325,8 @@ public class AbacusController implements PluginListener {
FileReader fileReader = new FileReader(definitionFile); FileReader fileReader = new FileReader(definitionFile);
Scanner scanner = new Scanner(fileReader); Scanner scanner = new Scanner(fileReader);
while(scanner.hasNext()){ while(scanner.hasNext()){
abacus.evaluateTree(abacus.parseString(scanner.nextLine())); EvaluationResult result = abacus.evaluateTree(abacus.parseString(scanner.nextLine()));
abacus.applyToContext(result.getResultingContext());
} }
} catch (AbacusException abacusError) { } catch (AbacusException abacusError) {
outputText.setText(ERR_DEFINITION + "(" + abacusError.getMessage() + ")"); outputText.setText(ERR_DEFINITION + "(" + abacusError.getMessage() + ")");
@ -334,14 +335,6 @@ public class AbacusController implements PluginListener {
} catch (FileNotFoundException ignored) {} } catch (FileNotFoundException ignored) {}
} }
private void reloadAbacus(){
abacus.reload();
ExtendedConfiguration abacusConfig = (ExtendedConfiguration) abacus.getConfiguration();
for(String fileName: abacusConfig.getDefinitionFiles()) {
loadDefinitionFile(fileName);
}
}
@FXML @FXML
public void performScan() { public void performScan() {
PluginManager abacusPluginManager = abacus.getPluginManager(); PluginManager abacusPluginManager = abacus.getPluginManager();
@ -352,13 +345,13 @@ public class AbacusController implements PluginListener {
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
reloadAbacus(); abacus.reload();
} }
@FXML @FXML
public void performReload() { public void performReload() {
alertIfApplyNeeded(true); alertIfApplyNeeded(true);
reloadAbacus(); abacus.reload();
} }
@FXML @FXML
@ -425,6 +418,9 @@ public class AbacusController implements PluginListener {
}).collect(Collectors.toCollection(ArrayList::new))); }).collect(Collectors.toCollection(ArrayList::new)));
functionList.sort(Comparator.comparing(Documentation::getCodeName)); functionList.sort(Comparator.comparing(Documentation::getCodeName));
definitionFiles.addAll(configuration.getDefinitionFiles()); definitionFiles.addAll(configuration.getDefinitionFiles());
for(String file : definitionFiles){
loadDefinitionFile(file);
}
} }
@Override @Override