use of de.prob.prolog.term.PrologTerm 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.term.PrologTerm in project probparsers by bendisposto.
the class AbstractTest method check.
protected void check(final String input, final PrologTerm expectedTerm) throws LtlParseException {
final PrologTerm term = parse(input);
Assert.assertEquals(expectedTerm, term);
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class PrologGeneratorTest method testGlobally.
@Test
public void testGlobally() throws Exception {
final PrologTerm expected = new CompoundPrologTerm("globally", TERM_TRUE);
check("G true ", expected);
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class PrologGeneratorTest method testSince.
@Test
public void testSince() throws Exception {
final PrologTerm expected = new CompoundPrologTerm("since", TERM_FALSE, TERM_TRUE);
check("false S true ", expected);
}
use of de.prob.prolog.term.PrologTerm in project probparsers by bendisposto.
the class PrologGeneratorTest method testYesterday.
@Test
public void testYesterday() throws Exception {
final PrologTerm expected = new CompoundPrologTerm("yesterday", TERM_TRUE);
check("Y true ", expected);
}
Aggregations