Search in sources :

Example 6 with IPrologTermOutput

use of de.prob.prolog.output.IPrologTermOutput 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 7 with IPrologTermOutput

use of de.prob.prolog.output.IPrologTermOutput 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 8 with IPrologTermOutput

use of de.prob.prolog.output.IPrologTermOutput 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 9 with IPrologTermOutput

use of de.prob.prolog.output.IPrologTermOutput in project prob2 by bendisposto.

the class CheckBooleanPropertyCommandTest method testWriteCommand.

@Test
public void testWriteCommand() {
    CheckBooleanPropertyCommand cmd = new CheckBooleanPropertyCommand("A_DINGO_ATE_MY_BABY", "root");
    IPrologTermOutput pto = mock(IPrologTermOutput.class);
    cmd.writeCommand(pto);
    verify(pto).openTerm("state_property");
    verify(pto).printVariable(anyString());
    verify(pto).printAtomOrNumber("root");
    verify(pto).printAtom("A_DINGO_ATE_MY_BABY");
}
Also used : CheckBooleanPropertyCommand(de.prob.animator.command.CheckBooleanPropertyCommand) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) Test(org.junit.Test)

Example 10 with IPrologTermOutput

use of de.prob.prolog.output.IPrologTermOutput in project probparsers by bendisposto.

the class UnitPragmaTest 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)

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