Search in sources :

Example 1 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(final String content) {
    RulesProject rulesProject = new RulesProject();
    rulesProject.parseRulesMachines(content, new String[] {});
    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 2 with PrettyPrinter

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

the class PrettyAssignmentPrinterTest 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();
    // System.out.println("org: " + theString);
    // System.out.println("pp: " + prettyPrint);
    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) Test(org.junit.Test)

Example 3 with PrettyPrinter

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

the class Helpers method getPrettyPrint.

public static String getPrettyPrint(final String testMachine) {
    final BParser parser = new BParser("testcase");
    Start startNode;
    try {
        startNode = parser.parse(testMachine, false);
    } catch (BCompoundException e) {
        throw new RuntimeException(e);
    }
    PrettyPrinter pp = new PrettyPrinter();
    startNode.apply(pp);
    return pp.getPrettyPrint();
}
Also used : PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) Start(de.be4.classicalb.core.parser.node.Start) BParser(de.be4.classicalb.core.parser.BParser) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 4 with PrettyPrinter

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

the class PrettyPrinterTest 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();
    System.out.println(prettyPrint);
    Start parse2 = BParser.parse(PREFIX + prettyPrint);
    PrettyPrinter prettyprinter2 = new PrettyPrinter();
    parse2.apply(prettyprinter2);
    System.out.println(prettyprinter2.getPrettyPrint());
    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 5 with PrettyPrinter

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

the class RulesUtil method getRulesProjectAsPrologTerm.

public static String getRulesProjectAsPrologTerm(final String content) {
    RulesProject rulesProject = new RulesProject();
    ParsingBehaviour pb = new ParsingBehaviour();
    pb.setAddLineNumbers(false);
    rulesProject.setParsingBehaviour(pb);
    rulesProject.parseRulesMachines(content, new String[] {});
    rulesProject.checkAndTranslateProject();
    List<IModel> bModels = rulesProject.getBModels();
    List<BException> bExceptionList = rulesProject.getBExceptionList();
    if (bExceptionList.isEmpty()) {
        IModel model = bModels.get(bModels.size() - 2);
        PrettyPrinter pp = new PrettyPrinter();
        model.getStart().apply(pp);
        System.out.println(pp.getPrettyPrint());
    }
    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();
        }
    };
    rulesProject.printPrologOutput(new PrintStream(output), new PrintStream(output));
    return output.toString();
}
Also used : PrintStream(java.io.PrintStream) PrettyPrinter(de.be4.classicalb.core.parser.util.PrettyPrinter) OutputStream(java.io.OutputStream) BException(de.be4.classicalb.core.parser.exceptions.BException) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour)

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