Package autumn.lang.compiler
Class AutumnPrettyPrinter
java.lang.Object
autumn.lang.compiler.AutumnPrettyPrinter
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 Summary
ConstructorsConstructorDescriptionConstructor.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic PrintStream
createStreamASCII
(StringBuilder builder) This method creates a PrintStream that prints to a StringBuilder using ASCII.static List<IConstruct>
nodesOf
(IConstruct node) This method linearizes the nodes in a given abstract-syntax-tree.void
print
(IConstruct node) This method prints an abstract-syntax-tree node to the underlying stream.stream()
This method retrieves the stream that is being printed to.
-
Constructor Details
-
AutumnPrettyPrinter
public AutumnPrettyPrinter()Constructor.Equivalent:
AutumnPrettyPrinter(System.out)
-
AutumnPrettyPrinter
Constructor.- Parameters:
out
- is the stream to print to.
-
-
Method Details
-
stream
This method retrieves the stream that is being printed to.- Returns:
- the aforedescribed stream.
-
print
public void print(IConstruct node) throws UnprintableNodeException, IncompleteNodeException, RepeatedNodeException 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
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
This method linearizes the nodes in a given abstract-syntax-tree.- Parameters:
node
- is the root of the AST.- Returns:
- the aforedescribed immutable list.
-