Package net.hydromatic.morel.ast
Class AstWriter
- java.lang.Object
-
- net.hydromatic.morel.ast.AstWriter
-
public class AstWriter extends Object
Context for writing an AST out as a string.
-
-
Field Summary
Fields Modifier and Type Field Description private StringBuilderbprivate booleanparenthesize
-
Constructor Summary
Constructors Modifier Constructor Description AstWriter()privateAstWriter(StringBuilder b, boolean parenthesize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AstWriterappend(String s)Appends a string to the output.AstWriterappend(AstNode node, int left, int right)Appends a parse tree node.AstWriterappendAll(Iterable<? extends AstNode> nodes, int left, Op op, int right)Appends a list of parse tree nodes.AstWriterappendAll(Iterable<? extends AstNode> list, String sep)Appends a list of parse tree nodes separated bysep.AstWriterappendAll(Iterable<? extends AstNode> list, String start, String sep, String end)Appends a list of parse tree nodes separated bysep, and also with prefix and suffix:start node0 sep node1 ... sep nodeN end.AstWriterappendAll(Iterable<? extends AstNode> list, String start, String sep, String end, String empty)Appends a list of parse tree nodes separated bysep, and also with prefix and suffix:start node0 sep node1 ... sep nodeN end.AstWriterappendLiteral(Comparable value)AstWriterbinary(String left, AstNode a0, String mid, AstNode a1, int right)Appends a call to a binary operator (e.g.AstWriterbinary(String left, AstNode a0, String mid, AstNode a1, String right)Appends a call to a binary operator (e.g.AstWriterid(String s)Appends an identifier to the output.AstWriterid(String s, int i)Appends a ordinal-qualified-identifier to the output.AstWriterinfix(int left, AstNode a0, Op op, AstNode a1, int right)Appends a call to an infix operator.AstWriterprefix(int left, Op op, AstNode a, int right)Appends a call to an prefix operator.StringtoString()AstWriterwithParenthesize(boolean parenthesize)Returns a writer that wraps everything in parentheses.
-
-
-
Field Detail
-
b
private final StringBuilder b
-
parenthesize
private final boolean parenthesize
-
-
Constructor Detail
-
AstWriter
private AstWriter(StringBuilder b, boolean parenthesize)
-
AstWriter
public AstWriter()
-
-
Method Detail
-
toString
public String toString()
Returns the ML source code generated by this writer.
-
withParenthesize
public AstWriter withParenthesize(boolean parenthesize)
Returns a writer that wraps everything in parentheses.
-
id
public AstWriter id(String s, int i)
Appends a ordinal-qualified-identifier to the output.Prints "v" for
id("v", 0), "v#1" forid("v", 1), and so forth.
-
infix
public AstWriter infix(int left, AstNode a0, Op op, AstNode a1, int right)
Appends a call to an infix operator.
-
prefix
public AstWriter prefix(int left, Op op, AstNode a, int right)
Appends a call to an prefix operator.
-
binary
public AstWriter binary(String left, AstNode a0, String mid, AstNode a1, int right)
Appends a call to a binary operator (e.g. "val ... = ...").
-
binary
public AstWriter binary(String left, AstNode a0, String mid, AstNode a1, String right)
Appends a call to a binary operator (e.g. "let ... in ... end").
-
appendAll
public AstWriter appendAll(Iterable<? extends AstNode> nodes, int left, Op op, int right)
Appends a list of parse tree nodes.
-
appendAll
public AstWriter appendAll(Iterable<? extends AstNode> list, String sep)
Appends a list of parse tree nodes separated bysep.
-
appendAll
public AstWriter appendAll(Iterable<? extends AstNode> list, String start, String sep, String end)
Appends a list of parse tree nodes separated bysep, and also with prefix and suffix:start node0 sep node1 ... sep nodeN end.
-
appendAll
public AstWriter appendAll(Iterable<? extends AstNode> list, String start, String sep, String end, String empty)
Appends a list of parse tree nodes separated bysep, and also with prefix and suffix:start node0 sep node1 ... sep nodeN end.
-
appendLiteral
public AstWriter appendLiteral(Comparable value)
-
-