Search in sources :

Example 6 with PrettyPrinter

use of de.be4.classicalb.core.parser.util.PrettyPrinter in project probparsers by bendisposto.

the class RulesUtil method getRulesMachineAsBMachine.

public static String getRulesMachineAsBMachine(File file) {
    RulesProject rulesProject = new RulesProject();
    rulesProject.parseProject(file);
    rulesProject.checkAndTranslateProject();
    List<IModel> bModels = rulesProject.getBModels();
    List<BException> bExceptionList = rulesProject.getBExceptionList();
    if (!bExceptionList.isEmpty()) {
        throw new RuntimeException(bExceptionList.get(0));
    }
    IModel model = bModels.get(bModels.size() - 2);
    PrettyPrinter pp = new PrettyPrinter();
    model.getStart().apply(pp);
    return pp.getPrettyPrint();
}
Also used : PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 7 with PrettyPrinter

use of de.be4.classicalb.core.parser.util.PrettyPrinter in project probparsers by bendisposto.

the class PrettyPredicatePrinterTest method testExpression.

@Test
public void testExpression() throws Exception {
    Start parse = BParser.parse(PREFIX + theString);
    PrettyPrinter prettyprinter = new PrettyPrinter();
    parse.apply(prettyprinter);
    String prettyPrint = prettyprinter.getPrettyPrint();
    Start parse2 = BParser.parse(PREFIX + prettyPrint);
    PrettyPrinter prettyprinter2 = new PrettyPrinter();
    parse2.apply(prettyprinter2);
    assertEquals(Ast2String.getTreeAsString(parse), Ast2String.getTreeAsString(parse2));
    assertEquals(prettyPrint, prettyprinter2.getPrettyPrint());
}
Also used : PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) Start(de.be4.classicalb.core.parser.node.Start) Ast2String(util.Ast2String) Test(org.junit.Test)

Example 8 with PrettyPrinter

use of de.be4.classicalb.core.parser.util.PrettyPrinter in project prob2 by bendisposto.

the class ClassicalB method prettyprint.

private static String prettyprint(final Node predicate) {
    final PrettyPrinter prettyPrinter = new PrettyPrinter();
    predicate.apply(prettyPrinter);
    return prettyPrinter.getPrettyPrint();
}
Also used : PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter)

Aggregations

PrettyPrinter (de.be4.classicalb.core.parser.util.PrettyPrinter)8 Start (de.be4.classicalb.core.parser.node.Start)4 BException (de.be4.classicalb.core.parser.exceptions.BException)3 Test (org.junit.Test)3 Ast2String (util.Ast2String)2 BParser (de.be4.classicalb.core.parser.BParser)1 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)1 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1