A skeleton output formatter for your language grammar. Using the
add() method along with force(), indent(), and outdent(), you can
easily specify how this visitor will format the given syntax tree.
See the JTB documentation for more details.
Pass your syntax tree to this visitor, and then to the TreeDumper
visitor in order to "pretty print" your tree.
Constructor Summary
public
TreeFormatter() The default constructor assumes an indentation amount of 3 spaces
and no line-wrap.
public
TreeFormatter(int indentAmt, int wrapWidth) This constructor accepts an indent amount and a line width which is
used to wrap long lines.
Method Summary
protected void
add(FormatCommand cmd) Use this method to add FormatCommands to the command queue to be
executed when the next token in the tree is visited.
protected FormatCommand
force() A Force command inserts a line break and indents the next line to
the current indentation level.
processList(NodeListInterface n) Accepts a NodeListInterface object and performs an optional format
command between each node in the list (but not after the last node).
visit(NodeToken n) Executes the commands waiting in the command queue, then inserts the
proper location information into the current NodeToken.
If there are any special tokens preceding this token, they will be
given the current location information.
The default constructor assumes an indentation amount of 3 spaces
and no line-wrap. You may alternately use the other constructor to
specify your own indentation amount and line width.
TreeFormatter
public TreeFormatter(int indentAmt, int wrapWidth)(Code)
This constructor accepts an indent amount and a line width which is
used to wrap long lines. If a token's beginColumn value is greater
than the specified wrapWidth, it will be moved to the next line and
indented one extra level. To turn off line-wrapping, specify a
wrapWidth of 0.
Parameters: indentAmt - Amount of spaces per indentation level. Parameters: wrapWidth - Wrap lines longer than wrapWidth. 0 for no wrap.
Executes the commands waiting in the command queue, then inserts the
proper location information into the current NodeToken.
If there are any special tokens preceding this token, they will be
given the current location information. The token will follow on
the next line, at the proper indentation level. If this is not the
behavior you want from special tokens, feel free to modify this
method.