Search in sources :

Example 6 with PrologTermOutput

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;
    }
}
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)

Example 7 with PrologTermOutput

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.");
    }
}
Also used : PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) BException(de.be4.classicalb.core.parser.exceptions.BException) BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) IOException(java.io.IOException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) BParseException(de.be4.classicalb.core.parser.exceptions.BParseException) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput)

Example 8 with PrologTermOutput

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

Example 9 with PrologTermOutput

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();
}
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 10 with PrologTermOutput

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();
    }
}
Also used : PrologTermOutput(de.prob.prolog.output.PrologTermOutput) FileOutputStream(java.io.FileOutputStream) EventBModelTranslator(de.prob.model.eventb.translate.EventBModelTranslator)

Aggregations

PrologTermOutput (de.prob.prolog.output.PrologTermOutput)14 IPrologTermOutput (de.prob.prolog.output.IPrologTermOutput)13 PrintWriter (java.io.PrintWriter)7 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)5 StringWriter (java.io.StringWriter)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 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 IOException (java.io.IOException)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