use of de.be4.classicalb.core.parser.BParser in project prob2 by bendisposto.
the class ClassicalBFactory method parseAllMachines.
/**
* Given an {@link Start} ast, {@link File} f, and {@link BParser} bparser, all
* machines are loaded.
*
* @param ast
* {@link Start} representing the abstract syntax tree for the
* machine
* @param directory
* the directory relative to which machines should be loaded
* @param f
* {@link File} containing machine
* @param contentProvider
* the content provider to use
* @param bparser
* {@link BParser} for parsing
* @return {@link RecursiveMachineLoader} rml with all loaded machines
* @throws ProBError
* if the model could not be loaded
*/
public RecursiveMachineLoader parseAllMachines(final Start ast, final String directory, final File f, final IDefinitionFileProvider contentProvider, final BParser bparser) {
try {
ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
parsingBehaviour.setAddLineNumbers(true);
final RecursiveMachineLoader rml = new RecursiveMachineLoader(directory, contentProvider, parsingBehaviour);
rml.loadAllMachines(f, ast, bparser.getDefinitions());
logger.trace("Done parsing '{}'", f.getAbsolutePath());
return rml;
} catch (BCompoundException e) {
throw new ProBError(e);
}
}
use of de.be4.classicalb.core.parser.BParser in project prob2 by bendisposto.
the class ClassicalBFactory method parseString.
private Start parseString(final String model, final BParser bparser) {
try {
logger.trace("Parsing file");
Start ast = null;
ast = bparser.parse(model, false);
return ast;
} catch (BCompoundException e) {
throw new ProBError(e);
}
}
use of de.be4.classicalb.core.parser.BParser 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.BParser 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