Package edu.cornell.cs.cs4120.util
Class CodeWriterSExpPrinter
java.lang.Object
edu.cornell.cs.cs4120.util.CodeWriterSExpPrinter
- All Implemented Interfaces:
SExpPrinter
,java.lang.AutoCloseable
public class CodeWriterSExpPrinter extends java.lang.Object implements SExpPrinter
An SExpPrinter implementation designed to print ASTs through a
provided
CodeWriter
.-
Constructor Summary
Constructors Constructor Description CodeWriterSExpPrinter(java.io.OutputStream o)
Deprecated.CodeWriterSExpPrinter(java.io.PrintWriter w)
Constructs a new SExpPrinter instance that prints programs using the given writer.CodeWriterSExpPrinter(polyglot.util.CodeWriter writer)
Constructs a new SExpPrinter instance that prints programs using the givenCodeWriter
. -
Method Summary
Modifier and Type Method Description void
close()
Flushes and closes both this printer and any underlying output stream to which it is attached.void
endList()
Prints the close parenthesis of an S-expression list.void
flush()
Flushes all formatted text to the underlying writer.void
printAtom(java.lang.String atom)
Prints an atom.protected void
startElement()
protected void
startEveryList(boolean unified)
void
startList()
Prints the open parenthesis of an S-expression list.void
startUnifiedList()
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).
-
Constructor Details
-
CodeWriterSExpPrinter
public CodeWriterSExpPrinter(polyglot.util.CodeWriter writer)Constructs a new SExpPrinter instance that prints programs using the givenCodeWriter
.- Parameters:
writer
- theCodeWriter
to print to
-
CodeWriterSExpPrinter
public CodeWriterSExpPrinter(java.io.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(java.io.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(java.lang.String atom)Description copied from interface:SExpPrinter
Prints an atom.- Specified by:
printAtom
in interfaceSExpPrinter
- 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 interfaceSExpPrinter
-
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 interfaceSExpPrinter
-
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 interfaceSExpPrinter
-
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 interfaceSExpPrinter
-
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceSExpPrinter
-