spiglet.visitor
Class TreeDumper

java.lang.Object
  extended by spiglet.visitor.DepthFirstVisitor
      extended by spiglet.visitor.TreeDumper
All Implemented Interfaces:
Visitor

public class TreeDumper
extends DepthFirstVisitor

Dumps the syntax tree to a Writer using the location information in each NodeToken.


Field Summary
protected  java.io.PrintWriter out
           
 
Constructor Summary
TreeDumper()
          The default constructor uses System.out as its output location.
TreeDumper(java.io.OutputStream o)
           
TreeDumper(java.io.Writer o)
           
 
Method Summary
 void flushWriter()
          Flushes the OutputStream or Writer that this TreeDumper is using.
 void printSpecials(boolean b)
          Allows you to specify whether or not to print special tokens.
 void resetPosition()
          Resets the position of the output "cursor" to the first line and column.
 void startAtNextToken()
          Starts the tree dumper on the line containing the next token visited.
 void visit(NodeToken n)
          Dumps the current NodeToken to the output stream being used.
 
Methods inherited from class spiglet.visitor.DepthFirstVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.PrintWriter out
Constructor Detail

TreeDumper

public TreeDumper()
The default constructor uses System.out as its output location. You may specify your own Writer or OutputStream using one of the other constructors.


TreeDumper

public TreeDumper(java.io.Writer o)

TreeDumper

public TreeDumper(java.io.OutputStream o)
Method Detail

flushWriter

public void flushWriter()
Flushes the OutputStream or Writer that this TreeDumper is using.


printSpecials

public void printSpecials(boolean b)
Allows you to specify whether or not to print special tokens.


startAtNextToken

public void startAtNextToken()
Starts the tree dumper on the line containing the next token visited. For example, if the next token begins on line 50 and the dumper is currently on line 1 of the file, it will set its current line to 50 and continue printing from there, as opposed to printing 49 blank lines and then printing the token.


resetPosition

public void resetPosition()
Resets the position of the output "cursor" to the first line and column. When using a dumper on a syntax tree more than once, you either need to call this method or startAtNextToken() between each dump.


visit

public void visit(NodeToken n)
Dumps the current NodeToken to the output stream being used.

Specified by:
visit in interface Visitor
Overrides:
visit in class DepthFirstVisitor
Throws:
java.lang.IllegalStateException - if the token position is invalid relative to the current position, i.e. its location places it before the previous token.