Search in sources :

Example 11 with RecursiveMachineLoader

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());
}
Also used : ClassicalBModel(de.prob.model.classicalb.ClassicalBModel) Translator(de.tla2bAst.Translator) Start(de.be4.classicalb.core.parser.node.Start) TLA2BException(de.tla2b.exceptions.TLA2BException) FileNotFoundException(java.io.FileNotFoundException) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) File(java.io.File) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 12 with RecursiveMachineLoader

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());
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) ClassicalBFactory(de.prob.scripting.ClassicalBFactory) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) File(java.io.File) URL(java.net.URL) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) Test(org.junit.Test)

Aggregations

RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)11 BParser (de.be4.classicalb.core.parser.BParser)8 File (java.io.File)8 Start (de.be4.classicalb.core.parser.node.Start)7 ClassicalBModel (de.prob.model.classicalb.ClassicalBModel)4 Test (org.junit.Test)4 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)2 StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)2 PrologTerm (de.prob.prolog.term.PrologTerm)2 Ast2String (util.Ast2String)2 CachingDefinitionFileProvider (de.be4.classicalb.core.parser.CachingDefinitionFileProvider)1 ProBError (de.prob.exception.ProBError)1 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)1 ClassicalBFactory (de.prob.scripting.ClassicalBFactory)1 TLA2BException (de.tla2b.exceptions.TLA2BException)1 Translator (de.tla2bAst.Translator)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1