Class AutumnPrettyPrinter

java.lang.Object
autumn.lang.compiler.AutumnPrettyPrinter

public final class AutumnPrettyPrinter extends Object
An instance of this class can pretty-print an abstract-syntax-tree.

Note: The output of this pretty-printer is version-specific.

Author:
Mackenzie High
  • Constructor Details

    • AutumnPrettyPrinter

      public AutumnPrettyPrinter()
      Constructor.

      Equivalent: AutumnPrettyPrinter(System.out)

    • AutumnPrettyPrinter

      public AutumnPrettyPrinter(PrintStream out)
      Constructor.
      Parameters:
      out - is the stream to print to.
  • Method Details

    • stream

      public PrintStream stream()
      This method retrieves the stream that is being printed to.
      Returns:
      the aforedescribed stream.
    • print

      This method prints an abstract-syntax-tree node to the underlying stream.
      Parameters:
      node - is the AST node to print, which may be the root of an entire tree.
      Throws:
      UnprintableNodeException - if the AST contains a node that is unprintable.
      IncompleteNodeException - if the AST is incomplete.
      RepeatedNodeException - if the AST contains the same node more than once.
    • createStreamASCII

      public static PrintStream createStreamASCII(StringBuilder builder)
      This method creates a PrintStream that prints to a StringBuilder using ASCII.

      Note: The returned stream throws an IOException, when non-ASCII encoded text is encountered.

      Note: The returned stream cannot be used to print null characters (i.e. ASCII(0)).

      Parameters:
      builder - is the builder to print ASCII encoded characters to.
      Returns:
      the aforedescribed stream.
    • nodesOf

      public static List<IConstruct> nodesOf(IConstruct node)
      This method linearizes the nodes in a given abstract-syntax-tree.
      Parameters:
      node - is the root of the AST.
      Returns:
      the aforedescribed immutable list.