Skip to content
Snippets Groups Projects
Commit ea258a8e authored by dgelessus's avatar dgelessus
Browse files

Use file extension mappings from ProB 2 instead of a custom map

parent ee8a3ec1
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
* Added a `--user` flag to the installer to allow installing the kernel into the user home directory. This allows installing the kernel without `sudo` when not using a virtual environment. * Added a `--user` flag to the installer to allow installing the kernel into the user home directory. This allows installing the kernel without `sudo` when not using a virtual environment.
* Added `:let` and `:unlet` commands to (un)define local variables. * Added `:let` and `:unlet` commands to (un)define local variables.
* **Note:** Local variables are currently stored and expanded in text form. Values whose text form is not parsable cannot be stored in local variables, and storing large values may cause performance issues. * **Note:** Local variables are currently stored and expanded in text form. Values whose text form is not parsable cannot be stored in local variables, and storing large values may cause performance issues.
* Added `.sys` to the list of recognized extensions for classical B. * Added support for additional languages and file extensions. The `:load` command now recognizes all languages and file extensions supported by ProB 2.
* **Note:** Some languages are not fully working yet (for example XTL).
* Added support for Java 11. * Added support for Java 11.
* Updated ProB 2 to version 3.2.12. * Updated ProB 2 to version 3.2.12.
* Fixed confusing handling of trailing spaces in commands. * Fixed confusing handling of trailing spaces in commands.
......
...@@ -4,8 +4,6 @@ import java.io.IOException; ...@@ -4,8 +4,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -15,13 +13,9 @@ import com.google.inject.Inject; ...@@ -15,13 +13,9 @@ import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provider; import com.google.inject.Provider;
import de.prob.scripting.CSPFactory; import de.prob.scripting.FactoryProvider;
import de.prob.scripting.ClassicalBFactory;
import de.prob.scripting.EventBFactory;
import de.prob.scripting.EventBPackageFactory;
import de.prob.scripting.ModelFactory; import de.prob.scripting.ModelFactory;
import de.prob.scripting.ModelTranslationError; import de.prob.scripting.ModelTranslationError;
import de.prob.scripting.TLAFactory;
import de.prob.statespace.AnimationSelector; import de.prob.statespace.AnimationSelector;
import de.prob.statespace.Trace; import de.prob.statespace.Trace;
import de.prob2.jupyter.ProBKernel; import de.prob2.jupyter.ProBKernel;
...@@ -38,24 +32,6 @@ import org.slf4j.LoggerFactory; ...@@ -38,24 +32,6 @@ import org.slf4j.LoggerFactory;
public final class LoadFileCommand implements Command { public final class LoadFileCommand implements Command {
private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(LoadFileCommand.class); private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(LoadFileCommand.class);
private static final @NotNull Map<@NotNull String, @NotNull Class<? extends ModelFactory<?>>> EXTENSION_TO_FACTORY_MAP;
static {
final Map<String, Class<? extends ModelFactory<?>>> extensionToFactoryMap = new HashMap<>();
extensionToFactoryMap.put("mch", ClassicalBFactory.class);
extensionToFactoryMap.put("ref", ClassicalBFactory.class);
extensionToFactoryMap.put("imp", ClassicalBFactory.class);
extensionToFactoryMap.put("sys", ClassicalBFactory.class);
extensionToFactoryMap.put("eventb", EventBPackageFactory.class);
extensionToFactoryMap.put("bum", EventBFactory.class);
extensionToFactoryMap.put("buc", EventBFactory.class);
extensionToFactoryMap.put("csp", CSPFactory.class);
extensionToFactoryMap.put("cspm", CSPFactory.class);
extensionToFactoryMap.put("tla", TLAFactory.class);
// FIXME Not currently possible, because RulesModelFactory does not implement the ModelFactory interface
//extensionToFactoryMap.put("rmch", RulesModelFactory.class);
EXTENSION_TO_FACTORY_MAP = Collections.unmodifiableMap(extensionToFactoryMap);
}
private final @NotNull Injector injector; private final @NotNull Injector injector;
private final @NotNull AnimationSelector animationSelector; private final @NotNull AnimationSelector animationSelector;
private final @NotNull Provider<ProBKernel> proBKernelProvider; private final @NotNull Provider<ProBKernel> proBKernelProvider;
...@@ -104,13 +80,13 @@ public final class LoadFileCommand implements Command { ...@@ -104,13 +80,13 @@ public final class LoadFileCommand implements Command {
throw new UserErrorException("File has no extension, unable to determine language: " + machineFileName); throw new UserErrorException("File has no extension, unable to determine language: " + machineFileName);
} }
final String extension = machineFileName.substring(dotIndex+1); final String extension = machineFileName.substring(dotIndex+1);
if (!EXTENSION_TO_FACTORY_MAP.containsKey(extension)) { if (!FactoryProvider.isExtensionKnown(extension)) {
throw new UserErrorException("Unsupported file type: ." + extension); throw new UserErrorException("Unsupported file type: ." + extension);
} }
final Map<String, String> preferences = CommandUtils.parsePreferences(args.subList(1, args.size())); final Map<String, String> preferences = CommandUtils.parsePreferences(args.subList(1, args.size()));
try { try {
final ModelFactory<?> factory = this.injector.getInstance(EXTENSION_TO_FACTORY_MAP.get(extension)); final ModelFactory<?> factory = this.injector.getInstance(FactoryProvider.factoryClassFromExtension(extension));
this.animationSelector.changeCurrentAnimation(new Trace(factory.extract(machineFilePath.toString()).load(preferences))); this.animationSelector.changeCurrentAnimation(new Trace(factory.extract(machineFilePath.toString()).load(preferences)));
this.proBKernelProvider.get().setCurrentMachineDirectory(machineFileDirectory); this.proBKernelProvider.get().setCurrentMachineDirectory(machineFileDirectory);
} catch (IOException | ModelTranslationError e) { } catch (IOException | ModelTranslationError e) {
...@@ -146,7 +122,7 @@ public final class LoadFileCommand implements Command { ...@@ -146,7 +122,7 @@ public final class LoadFileCommand implements Command {
return false; return false;
} }
final String extension = s.substring(dotIndex+1); final String extension = s.substring(dotIndex+1);
return EXTENSION_TO_FACTORY_MAP.containsKey(extension); return FactoryProvider.isExtensionKnown(extension);
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} catch (final IOException e) { } catch (final IOException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment