Building Parsers with Java

sjm.examples.pretty
Class PrettyParser

java.lang.Object
  |
  +--sjm.examples.pretty.PrettyParser

public class PrettyParser
extends java.lang.Object

This class accepts a Parser object in its constructor. The constructor sets each assembler in the parser composite to be one of the "pretty" assemblers in this package. These assemblers build a tree of nodes from the ComponentNode hierarchy that is also in this package. The resulting tree effectively records the order in which the parse proceeds. Printing the tree results in a "pretty print" or a standard formatting of the parse. The tree indents composite nodes (sequences, alternations and repetitions) and prints terminals as they appeared in the input.


Field Summary
protected  Parser parser
           
 
Constructor Summary
PrettyParser(Parser parser)
          Construct a pretty parser whose assemblers create a "pretty print" of input text.
 
Method Summary
protected  java.util.Vector completeMatches(Assembly inAssembly)
           
 boolean getShowLabels()
          Returns true if this PrettyParser object will show labels for composite nodes.
 java.util.Vector parseTrees(Assembly inAssembly)
          Returns a collection of strings that show the order of a parse of the given assembly.
 void setShowLabels(boolean showLabels)
          Sets the boolean that determines if this PrettyParser object will show labels for composite nodes.
protected  java.lang.String treeString(ComponentNode node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected Parser parser
Constructor Detail

PrettyParser

public PrettyParser(Parser parser)
Construct a pretty parser whose assemblers create a "pretty print" of input text.
Method Detail

completeMatches

protected java.util.Vector completeMatches(Assembly inAssembly)

getShowLabels

public boolean getShowLabels()
Returns true if this PrettyParser object will show labels for composite nodes.
Returns:
true if this PrettyParser object will show labels for composite nodes.

parseTrees

public java.util.Vector parseTrees(Assembly inAssembly)
Returns a collection of strings that show the order of a parse of the given assembly.
Parameters:
Assembly - the assembly to parse
Returns:
a collection of strings that show the order of a parse of the given assembly

setShowLabels

public void setShowLabels(boolean showLabels)
Sets the boolean that determines if this PrettyParser object will show labels for composite nodes.
Parameters:
boolean - the boolean that determines if this PrettyParser object will show labels for composite nodes.

treeString

protected java.lang.String treeString(ComponentNode node)

by Steve Metsker