Class CodeWriterSExpPrinter

java.lang.Object
edu.cornell.cs.cs4120.util.CodeWriterSExpPrinter
All Implemented Interfaces:
SExpPrinter, AutoCloseable

public class CodeWriterSExpPrinter extends Object implements SExpPrinter
An SExpPrinter implementation designed to print ASTs through a provided CodeWriter.
  • Constructor Details

    • CodeWriterSExpPrinter

      public CodeWriterSExpPrinter(polyglot.util.CodeWriter writer)
      Constructs a new SExpPrinter instance that prints programs using the given CodeWriter.
      Parameters:
      writer - the CodeWriter to print to
    • CodeWriterSExpPrinter

      public CodeWriterSExpPrinter(PrintWriter w)
      Constructs a new SExpPrinter instance that prints programs using the given writer. Output is kept to 80 columns if possible.
      Parameters:
      w - the writer to write to
    • CodeWriterSExpPrinter

      @Deprecated public CodeWriterSExpPrinter(OutputStream o)
      Deprecated.
      Constructs a new SExpPrinter instance that prints programs using the given stream. Output is kept to 80 columns if possible. Deprecated: use the previous constructor instead.
      Parameters:
      o - the output stream to print to
  • Method Details

    • printAtom

      public void printAtom(String atom)
      Description copied from interface: SExpPrinter
      Prints an atom.
      Specified by:
      printAtom in interface SExpPrinter
      Parameters:
      atom - the atom to print
    • startList

      public void startList()
      Description copied from interface: SExpPrinter
      Prints the open parenthesis of an S-expression list.
      Specified by:
      startList in interface SExpPrinter
    • startUnifiedList

      public void startUnifiedList()
      Description copied from interface: SExpPrinter
      Prints the open parenthesis of an S-expression list, and requires that if a line break is required to separate any two elements of this list, then all elements of this list must be separated by a line break (optional operation).
      Specified by:
      startUnifiedList in interface SExpPrinter
    • startEveryList

      protected void startEveryList(boolean unified)
    • endList

      public void endList()
      Description copied from interface: SExpPrinter
      Prints the close parenthesis of an S-expression list.
      Specified by:
      endList in interface SExpPrinter
    • startElement

      protected void startElement()
    • flush

      public void flush()
      Description copied from interface: SExpPrinter
      Flushes all formatted text to the underlying writer. This method should be called when printing is complete.
      Specified by:
      flush in interface SExpPrinter
    • close

      public void close()
      Description copied from interface: SExpPrinter
      Flushes and closes both this printer and any underlying output stream to which it is attached. It is an error to perform any subsequent operations on the same printer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SExpPrinter