use of de.prob.prolog.output.PrologTermOutput in project probparsers by bendisposto.
the class RulesProject method printPrologOutput.
public int printPrologOutput(final PrintStream out, final PrintStream err) {
if (!this.bExceptionList.isEmpty()) {
BCompoundException comp = new BCompoundException(bExceptionList);
PrologExceptionPrinter.printException(err, comp, parsingBehaviour.isUseIndention(), false);
return -2;
} else {
final IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(out), false);
printProjectAsPrologTerm(pout);
pout.flush();
return 0;
}
}
use of de.prob.prolog.output.PrologTermOutput 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.PrologTermOutput 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.PrologTermOutput 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.PrologTermOutput in project prob2 by bendisposto.
the class Api method eventb_save.
/**
* Save an EventB {@link StateSpace} to the given file.
*
* @param s the {@link StateSpace} to save, whose model must be an EventB model
* @param path the path of the file to save to
*/
public void eventb_save(final StateSpace s, final String path) throws IOException, ModelTranslationError {
final EventBModelTranslator translator = new EventBModelTranslator((EventBModel) s.getModel(), s.getMainComponent());
try (final FileOutputStream fos = new FileOutputStream(path)) {
final PrologTermOutput pto = new PrologTermOutput(fos, false);
pto.openTerm("package");
translator.printProlog(pto);
pto.closeTerm();
pto.fullstop();
pto.flush();
}
}
Aggregations