Search in sources :

Example 1 with IPrologTermOutput

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
        }
    }
}
Also used : PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ProBParserBase(de.prob.parserbase.ProBParserBase) PrologTerm(de.prob.prolog.term.PrologTerm) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) LtlParseException(de.be4.ltl.core.parser.LtlParseException)

Example 2 with IPrologTermOutput

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();
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) StringWriter(java.io.StringWriter) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter) ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter)

Example 3 with IPrologTermOutput

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);
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter) ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) AIntegerSetExpression(de.be4.classicalb.core.parser.node.AIntegerSetExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) StringWriter(java.io.StringWriter) AConstructorFreetypeConstructor(de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AFreetypesMachineClause(de.be4.classicalb.core.parser.node.AFreetypesMachineClause) AFreetype(de.be4.classicalb.core.parser.node.AFreetype) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with IPrologTermOutput

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();
    }
}
Also used : PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter)

Example 5 with IPrologTermOutput

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;
    }
}
Also used : PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter)

Aggregations

IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)12 PrologTermOutput (de.prob.prolog.output.PrologTermOutput)11 PrintWriter (java.io.PrintWriter)6 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)5 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)4 PositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter)4 StringWriter (java.io.StringWriter)4 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2 BParser (de.be4.classicalb.core.parser.BParser)1 BException (de.be4.classicalb.core.parser.exceptions.BException)1 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)1 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)1 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)1 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)1 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)1 AConstructorFreetypeConstructor (de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor)1