I already made MontiCore generate the PrettyPrinter classes with the options explained in Configure pom.xml to generate PrettyPrinters for MontiCore Languages .
How can I generate the formatted text output of my MontiArcAutomaton (Type: ASTEmbeddedAutomaton) ?
After asking the MontiCore team, the following solution turned out be a good approach: I wrote a helper class for pretty printing the embedded automaton ASTNode (see Listing 1). This helper class can be used eg with the following code line:
System.out.println(PrettyPrintFactory.getInstance().printNode(autMoore));
Listing 1:
import mc.ast.ASTCNode;
import mc.ast.PrettyPrinter;
import mc.helper.IndentPrinter;
import mc.maautomaton._prettyprint.MontiArcAutomatonConcretePrettyPrinter;
/**
* Prints the AST-Content to a file
**/
public class PrettyPrintFactory {
private static PrettyPrintFactory instance;
private PrettyPrinter pretty;
public static PrettyPrintFactory getInstance() {
if (instance == null) {
instance = new PrettyPrintFactory();
}
return instance;
}
private PrettyPrintFactory() {
pretty = new PrettyPrinter();
pretty.addConcretePrettyPrinter(new MontiArcAutomatonConcretePrettyPrinter());
}
/** prints the syntax of the astNode to a String */
public String printNode(ASTCNode astNode) {
IndentPrinter ip = new IndentPrinter();
pretty.prettyPrint(astNode, ip);
return ip.getContent();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.