use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class PrologExceptionPrinter method printException.
public static void printException(final OutputStream out, final BCompoundException e, boolean useIndentation, boolean lineOneOff) {
IPrologTermOutput pto = new PrologTermOutput(out, useIndentation);
if (e.getBExceptions().size() > 1) {
pto.openTerm("compound_exception", true);
pto.openList();
BCompoundException comp = e;
for (Exception ex : comp.getBExceptions()) {
try {
printBException(pto, (BException) ex, useIndentation, lineOneOff);
} catch (ClassCastException e2) {
throw new IllegalStateException("Unexpected exception in compound exceptions:" + ex.getClass().getSimpleName());
}
}
pto.closeList();
pto.closeTerm();
pto.fullstop();
pto.flush();
return;
} else if (e.getBExceptions().size() == 1) {
// single BException
printBException(pto, e.getBExceptions().get(0), useIndentation, lineOneOff);
pto.fullstop();
pto.flush();
} else {
throw new IllegalStateException("Empty compoundException.");
}
}
use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class Helpers method getMachineAsPrologTerm.
public static String getMachineAsPrologTerm(String input) {
final BParser parser = new BParser("Test");
Start start;
try {
start = parser.parse(input, true);
} catch (BCompoundException e) {
throw new RuntimeException(e);
}
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
final IPrologTermOutput pout = new PrologTermOutput(output, false);
printAsProlog(start, pout);
return output.toString();
}
use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class PragmaTest method printAST.
private String printAST(final Node node) {
final StringWriter swriter = new StringWriter();
NodeIdAssignment nodeids = new NodeIdAssignment();
node.apply(nodeids);
IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(swriter), false);
PositionPrinter pprinter = new ClassicalPositionPrinter(nodeids);
ASTProlog prolog = new ASTProlog(pout, pprinter);
node.apply(prolog);
swriter.flush();
return swriter.toString();
}
use of de.prob.prolog.output.IPrologTermOutput in project prob2 by bendisposto.
the class CheckBooleanPropertyCommandTest method testWriteCommand.
@Test
public void testWriteCommand() {
CheckBooleanPropertyCommand cmd = new CheckBooleanPropertyCommand("A_DINGO_ATE_MY_BABY", "root");
IPrologTermOutput pto = mock(IPrologTermOutput.class);
cmd.writeCommand(pto);
verify(pto).openTerm("state_property");
verify(pto).printVariable(anyString());
verify(pto).printAtomOrNumber("root");
verify(pto).printAtom("A_DINGO_ATE_MY_BABY");
}
use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class UnitPragmaTest method printAST.
private String printAST(final Node node) {
final StringWriter swriter = new StringWriter();
NodeIdAssignment nodeids = new NodeIdAssignment();
node.apply(nodeids);
IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(swriter), false);
PositionPrinter pprinter = new ClassicalPositionPrinter(nodeids);
ASTProlog prolog = new ASTProlog(pout, pprinter);
node.apply(prolog);
swriter.flush();
return swriter.toString();
}
Aggregations