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 Details

    • b

      private final StringBuilder b
    • parenthesize

      private final boolean parenthesize
  • Constructor Details

    • AstWriter

      private AstWriter(StringBuilder b, boolean parenthesize)
    • AstWriter

      public AstWriter()
  • Method Details

    • 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.
    • 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").
    • 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 sep)
      Appends a list of parse tree nodes separated by sep.
    • 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.
    • appendLiteral

      public AstWriter appendLiteral(Comparable value)