Search in sources :

Example 1 with PrologTermStringOutput

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

the class CliBParser method parseTemporalFormula.

private static void parseTemporalFormula(BufferedReader in, final TemporalLogicParser<?> parser) throws IOException {
    String theFormula;
    PrologTermStringOutput strOutput = new PrologTermStringOutput();
    theFormula = in.readLine();
    try {
        final PrologTerm term = parser.generatePrologTerm(theFormula, null);
        strOutput.openTerm("ltl").printTerm(term).closeTerm();
    } catch (LtlParseException e) {
        strOutput.openTerm("syntax_error").printAtom(e.getLocalizedMessage()).closeTerm();
    }
    strOutput.fullstop();
    // A Friendly Reminder: strOutput includes a newline!
    print(strOutput.toString());
}
Also used : PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) PrologTerm(de.prob.prolog.term.PrologTerm) LtlParseException(de.be4.ltl.core.parser.LtlParseException)

Example 2 with PrologTermStringOutput

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

the class CliBParser method parseFormula.

private static void parseFormula(String theFormula, IDefinitions context) {
    try {
        BParser parser = new BParser();
        parser.setDefinitions(context);
        Start start = parser.parse(theFormula, false);
        PrologTermStringOutput strOutput = new PrologTermStringOutput();
        NodeIdAssignment na = new NodeIdAssignment();
        start.apply(na);
        ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(na, -1, 0);
        ASTProlog printer = new ASTProlog(strOutput, pprinter);
        start.apply(printer);
        strOutput.fullstop();
        // A Friendly Reminder: strOutput includes a newline!
        String output = strOutput.toString();
        print(output);
    } catch (NullPointerException e) {
        // Not Parseable - Sadly, calling e.getLocalizedMessage() on the
        // NullPointerException returns NULL itself, thus triggering another
        // NullPointerException in the catch statement. Therefore we need a
        // second catch statement with a special case for the
        // NullPointerException instead of catching a general Exception
        // print("EXCEPTION NullPointerException" + System.lineSeparator());
        PrologTermStringOutput strOutput = new PrologTermStringOutput();
        strOutput.openTerm("exception").printAtom("NullPointerException").closeTerm();
        strOutput.fullstop();
        strOutput.flush();
        String output = strOutput.toString();
        print(output);
    } catch (BCompoundException e) {
        PrologExceptionPrinter.printException(socketOutputStream, e, false, true);
    }
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) Start(de.be4.classicalb.core.parser.node.Start) PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) BParser(de.be4.classicalb.core.parser.BParser) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 3 with PrologTermStringOutput

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

the class CliBParser method parseExtendedFormula.

private static void parseExtendedFormula(String theFormula, IDefinitions context) {
    try {
        BParser parser = new BParser();
        parser.setDefinitions(context);
        Start start = parser.eparse(theFormula, context);
        PrologTermStringOutput strOutput = new PrologTermStringOutput();
        NodeIdAssignment na = new NodeIdAssignment();
        start.apply(na);
        ClassicalPositionPrinter pprinter = new ClassicalPositionPrinter(na, -1, 0);
        ASTProlog printer = new ASTProlog(strOutput, pprinter);
        start.apply(printer);
        strOutput.fullstop();
        // A Friendly Reminder: strOutput includes a newline!
        print(strOutput.toString());
    } catch (NullPointerException e) {
        // Not Parseable - Sadly, calling e.getLocalizedMessage() on the
        // NullPointerException returns NULL itself, thus triggering another
        // NullPointerException in the catch statement. Therefore we need a
        // second catch statement with a special case for the
        // NullPointerException instead of catching a general Exception
        // print("EXCEPTION NullPointerException" + System.lineSeparator());
        PrologTermStringOutput strOutput = new PrologTermStringOutput();
        strOutput.openTerm("exception").printAtom("NullPointerException").closeTerm();
        strOutput.fullstop();
        strOutput.flush();
        print(strOutput.toString());
    } catch (BCompoundException e) {
        PrologExceptionPrinter.printException(socketOutputStream, e, false, true);
    } catch (LexerException e) {
        PrologTermStringOutput strOutput = new PrologTermStringOutput();
        strOutput.openTerm("exception").printAtom(e.getLocalizedMessage()).closeTerm();
        strOutput.fullstop();
        strOutput.flush();
        print(strOutput.toString());
    } catch (IOException e) {
        PrologExceptionPrinter.printException(socketOutputStream, e, theFormula, false, true);
    }
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) Start(de.be4.classicalb.core.parser.node.Start) PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) BParser(de.be4.classicalb.core.parser.BParser) IOException(java.io.IOException) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 4 with PrologTermStringOutput

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

the class ConsoleTest method testFormulaOutput.

@Test
public void testFormulaOutput() throws BCompoundException {
    Start start = BParser.parse("#FORMULA 1+1");
    PrologTermStringOutput strOutput = new PrologTermStringOutput();
    ASTProlog printer = new ASTProlog(strOutput, null);
    start.apply(printer);
    strOutput.fullstop();
    // A Friendly Reminder: strOutput includes a newline!
    String output = strOutput.toString().trim();
    assertEquals(output, "add(none,integer(none,1),integer(none,1)).");
}
Also used : ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) Start(de.be4.classicalb.core.parser.node.Start) PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) Test(org.junit.Test)

Example 5 with PrologTermStringOutput

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

the class CreateFreetypeTest method testManualFreetypeCreation.

@Test
public void testManualFreetypeCreation() {
    final PrologTermStringOutput pto = new PrologTermStringOutput();
    printProlog(pto);
    final String result = pto.toString();
    final String ftc1 = "constructor(none,myBool,bool_set(none))";
    final String ftc2 = "constructor(none,myInt,int_set(none))";
    final String ftc3 = "element(none,nothing)";
    final String freetypeStr = "freetype(none,ft,[" + ftc1 + "," + ftc2 + "," + ftc3 + "])";
    final String expectedPart = "freetypes(none,[" + freetypeStr + "])";
    Assert.assertTrue("Freetype contained", result.contains(expectedPart));
}
Also used : PrologTermStringOutput(de.prob.prolog.output.PrologTermStringOutput) Test(org.junit.Test)

Aggregations

PrologTermStringOutput (de.prob.prolog.output.PrologTermStringOutput)8 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)3 Start (de.be4.classicalb.core.parser.node.Start)3 Test (org.junit.Test)3 BParser (de.be4.classicalb.core.parser.BParser)2 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)2 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)2 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)2 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)1 LtlParseException (de.be4.ltl.core.parser.LtlParseException)1 IRawCommand (de.prob.animator.command.IRawCommand)1 CSP (de.prob.animator.domainobjects.CSP)1 EvaluationException (de.prob.animator.domainobjects.EvaluationException)1 Start (de.prob.core.sablecc.node.Start)1 PrologTerm (de.prob.prolog.term.PrologTerm)1 IOException (java.io.IOException)1