Class AstWriter


  • public class AstWriter
    extends Object
    Context for writing an AST out as a string.
    • Field Detail

      • 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.

        Overrides:
        toString in class Object
      • withParenthesize

        public AstWriter withParenthesize​(boolean parenthesize)
        Returns a writer that wraps everything in parentheses.
      • append

        public AstWriter append​(String s)
        Appends a string to the output.
      • id

        public AstWriter id​(String s)
        Appends an identifier to the output.
      • id

        public AstWriter id​(String s,
                            int i)
        Appends a ordinal-qualified-identifier to the output.

        Prints "v" for id("v", 0), "v#1" for id("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.
      • append

        public AstWriter append​(AstNode node,
                                int left,
                                int right)
        Appends a parse tree node.
      • 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 start,
                                   String sep,
                                   String end)
        Appends a list of parse tree nodes separated by sep, 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 by sep, and also with prefix and suffix: start node0 sep node1 ... sep nodeN end.