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();
}
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);
}
}
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());
}
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());
}
Aggregations