Search in sources :

Example 11 with StructuredPrologOutput

use of de.prob.prolog.output.StructuredPrologOutput in project probparsers by bendisposto.

the class BParser method getASTasFastProlog.

private static String getASTasFastProlog(final BParser parser, final File bfile, final Start tree, final ParsingBehaviour parsingBehaviour, IDefinitionFileProvider contentProvider) throws BCompoundException {
    final RecursiveMachineLoader rml = new RecursiveMachineLoader(bfile.getParent(), contentProvider, parsingBehaviour);
    rml.loadAllMachines(bfile, tree, parser.getDefinitions());
    StructuredPrologOutput structuredPrologOutput = new StructuredPrologOutput();
    rml.printAsProlog(structuredPrologOutput);
    Collection<PrologTerm> sentences = structuredPrologOutput.getSentences();
    StructuredPrologOutput output = new StructuredPrologOutput();
    output.openList();
    for (PrologTerm term : sentences) {
        output.printTerm(term);
    }
    output.closeList();
    output.fullstop();
    FastReadTransformer transformer = new FastReadTransformer(output);
    return transformer.write();
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) RecursiveMachineLoader(de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 12 with StructuredPrologOutput

use of de.prob.prolog.output.StructuredPrologOutput in project prob2 by bendisposto.

the class LoadBProjectCommand method printLoadTerm.

private void printLoadTerm(IPrologTermOutput pto) {
    StructuredPrologOutput parserOutput = new StructuredPrologOutput();
    this.rml.printAsProlog(parserOutput);
    nodeIdMapping = this.rml.getNodeIdMapping();
    for (PrologTerm term : parserOutput.getSentences()) {
        pto.printTerm(term);
    }
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) PrologTerm(de.prob.prolog.term.PrologTerm)

Example 13 with StructuredPrologOutput

use of de.prob.prolog.output.StructuredPrologOutput 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)

Example 14 with StructuredPrologOutput

use of de.prob.prolog.output.StructuredPrologOutput in project prob2 by bendisposto.

the class GetOperationsWithTimeoutTest method testWriteCommand.

@Test
public void testWriteCommand() {
    StructuredPrologOutput prologTermOutput = new StructuredPrologOutput();
    GetOperationsWithTimeout command = new GetOperationsWithTimeout("state");
    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("op_timeout_occurred", t.getFunctor());
    assertEquals(2, t.getArity());
    PrologTerm argument = t.getArgument(1);
    assertTrue(argument.isAtom());
    PrologTerm argument2 = t.getArgument(2);
    assertTrue(argument2.isVariable());
}
Also used : StructuredPrologOutput(de.prob.prolog.output.StructuredPrologOutput) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) CompoundPrologTerm(de.prob.prolog.term.CompoundPrologTerm) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm) Test(org.junit.Test)

Aggregations

StructuredPrologOutput (de.prob.prolog.output.StructuredPrologOutput)14 PrologTerm (de.prob.prolog.term.PrologTerm)10 CompoundPrologTerm (de.prob.prolog.term.CompoundPrologTerm)7 Test (org.junit.Test)7 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)5 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)2 BParser (de.be4.classicalb.core.parser.BParser)1 Start (de.be4.classicalb.core.parser.node.Start)1 LtlAdapterException (de.be4.ltl.core.parser.internal.LtlAdapterException)1 ClassicalB (de.prob.animator.domainobjects.ClassicalB)1 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 ClassicalBFactory (de.prob.scripting.ClassicalBFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1