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