use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class LtlConsoleParser method main.
public static void main(final String[] args) {
ConsoleOptions options = new ConsoleOptions();
options.addOption(CLI_LANG, "set language for atomic propositions, etc. (e.g. none, B)", 1);
options.addOption(CLI_OUT, "set output file, use stdout if omitted", 1);
options.addOption(CLI_LTL, "use LTL (default)");
options.addOption(CLI_CTL, "use CTL instead of LTL");
options.setIntro("usage: LtlConsoleParser [options] <LTL file>\n\n" + "If the file is omitted, stdin is used\n" + "Available options are:");
options.addOption(CLI_HELP, "print this message");
options.parseOptions(args);
if (options.isOptionSet(CLI_HELP)) {
options.printUsage(System.out);
return;
}
String[] params = options.getRemainingOptions();
if (params.length > 1) {
options.printUsage(System.out);
System.exit(-1);
return;
}
if (options.isOptionSet(CLI_LTL) && options.isOptionSet(CLI_CTL)) {
System.err.println("Incopatible options -ltl and -ctl given.");
System.exit(-1);
return;
}
final Mode mode = options.isOptionSet(CLI_CTL) ? Mode.CTL : Mode.LTL;
// please note: createOutputStream might call System.exit()
final OutputStream out = createOutputStream(options);
final String lang = options.isOptionSet(CLI_LANG) ? options.getOptions(CLI_LANG)[0] : null;
final ProBParserBase extParser = getExtensionParser(lang);
final IPrologTermOutput pto = new PrologTermOutput(out, false);
final String input = createInputStream(params, pto);
if (input != null) {
final String[] formulas = input.split("###");
final TemporalLogicParser<?> parser = createParser(extParser, mode);
pto.openList();
for (final String formula : formulas) {
try {
final PrologTerm term = parser.generatePrologTerm(formula, null);
pto.openTerm("ltl").printTerm(term).closeTerm();
} catch (LtlParseException e) {
pto.openTerm("syntax_error").printAtom(e.getLocalizedMessage()).closeTerm();
}
}
pto.closeList();
}
pto.fullstop();
pto.flush();
if (options.isOptionSet(CLI_OUT)) {
try {
out.close();
} catch (IOException e) {
// ignore
}
}
}
use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class ASTPrologTest 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();
System.out.println(swriter.toString());
return swriter.toString();
}
use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class ASTPrologTest method testFreeType.
@Test
public void testFreeType() throws BCompoundException {
final AConstructorFreetypeConstructor multi = new AConstructorFreetypeConstructor(new TIdentifierLiteral("multi"), new APowSubsetExpression(new AIntegerSetExpression()));
final AConstructorFreetypeConstructor single = new AConstructorFreetypeConstructor(new TIdentifierLiteral("single"), new AIntegerSetExpression());
final AFreetype freetype = new AFreetype(new TIdentifierLiteral("T"), Arrays.<PFreetypeConstructor>asList(multi, single));
AFreetypesMachineClause clause = new AFreetypesMachineClause(Arrays.<PFreetype>asList(freetype));
final StringWriter swriter = new StringWriter();
NodeIdAssignment nodeids = new NodeIdAssignment();
clause.apply(nodeids);
IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(swriter), false);
PositionPrinter pprinter = new ClassicalPositionPrinter(nodeids);
ASTProlog prolog = new ASTProlog(pout, pprinter);
clause.apply(prolog);
String code = swriter.toString();
assertFalse(code.isEmpty());
assertEquals("freetypes(0,[freetype(1,'T',[constructor(2,multi,pow_subset(3,integer_set(4))),constructor(5,single,integer_set(6))])])", code);
}
use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.
the class RulesParseUnit method printPrologOutput.
public void printPrologOutput(final PrintStream out, final PrintStream err) {
if (this.bCompoundException != null) {
this.printExceptionAsProlog(err);
} else {
final IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(out), false);
this.printAsProlog(pout, new NodeIdAssignment());
pout.flush();
}
}
use of de.prob.prolog.output.IPrologTermOutput 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;
}
}
Aggregations