use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project prob2 by bendisposto.
the class TLAFactory method extract.
@Override
public ExtractedModel<ClassicalBModel> extract(final String fileName) throws IOException, ModelTranslationError {
ClassicalBModel classicalBModel = modelCreator.get();
File f = new File(fileName);
if (!f.exists()) {
throw new FileNotFoundException("The TLA Model" + fileName + " was not found.");
}
Translator translator;
Start ast;
try {
translator = new Translator(f.getAbsolutePath());
ast = translator.translate();
} catch (TLA2BException e) {
throw new ModelTranslationError("Translation Error: " + e.getMessage(), e);
}
BParser bparser = new BParser();
bparser.getDefinitions().addDefinitions(translator.getBDefinitions());
try {
final RecursiveMachineLoader rml = parseAllMachines(ast, f, bparser);
classicalBModel = classicalBModel.create(ast, rml, f, bparser);
} catch (BCompoundException e) {
throw new ModelTranslationError(e.getMessage(), e);
}
return new ExtractedModel<>(classicalBModel, classicalBModel.getMainMachine());
}
use of de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader in project prob2 by bendisposto.
the class LoadBProjectCommandTest method testWriteCommand.
@Test
public void testWriteCommand() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
URL resource = classLoader.getResource("examples/scheduler.mch");
File f = new File(resource.toURI());
StructuredPrologOutput prologTermOutput = new StructuredPrologOutput();
ClassicalBFactory factory = new ClassicalBFactory(null);
BParser bparser = new BParser();
Start ast = factory.parseFile(f, bparser);
RecursiveMachineLoader rml = factory.parseAllMachines(ast, f.getParent(), f, bparser.getContentProvider(), bparser);
LoadBProjectCommand command = new LoadBProjectCommand(rml, f);
command.writeCommand(prologTermOutput);
prologTermOutput.fullstop().flush();
Collection<PrologTerm> sentences = prologTermOutput.getSentences();
PrologTerm next = sentences.iterator().next();
assertNotNull(next);
assertTrue(next instanceof CompoundPrologTerm);
CompoundPrologTerm t = (CompoundPrologTerm) next;
assertEquals("load_classical_b_from_list_of_facts", t.getFunctor());
assertEquals(2, t.getArity());
PrologTerm argument = t.getArgument(2);
assertTrue(argument.isList());
}
Aggregations