Navigation
Synopsis Transform an AbstractSyntaxTree into a formatted string.
Description A pretty printer formats the source code of programs. Alternative names are formatter or beautifier. Pretty printers differ in the inputs they accept:
  • The source text itself.
  • A ParseTree that corresponds to the source text. This variant is also called unparser.
  • An AbstractSyntaxTree that corresponds to the source text.
Pretty printers also differ in flexibility. They differ in:
  • The source language(s) they can accept.
  • The adaptability of the formatting rules.
Examples The program fragment
if(x > 10) { System.err.println("x > 10"); } else { System.err.println("x <= 10"); }
can be pretty printed in many different ways. Here are two variants examples:
if(x > 10) { 
   System.err.println("x > 10"); 
} else { 
   System.err.println("x <= 10"); 
}
if( x > 10 )
{ 
  System.err.println("x > 10"); 
} else 
{ 
   System.err.println("x <= 10"); 
}
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.