laser.regularlanguage.regularexpression.util
Class REPrinter<L extends LabelInterface>

java.lang.Object
  extended by laser.regularlanguage.regularexpression.AbstractREVisitor<L>
      extended by laser.regularlanguage.regularexpression.util.REPrinter<L>
Type Parameters:
L - The type of Label associated with the REs.
All Implemented Interfaces:
REConstants, REVisitor<L>

public class REPrinter<L extends LabelInterface>
extends AbstractREVisitor<L>
implements REConstants

The REPrinter class prints out the given RE to the specified Writer. The output can be parsed by the REParser.

NOTE:

1. Figure out a strategy for adding line separators

Author:
Heather M. Conboy (laser-software@cs.umass.edu)
See Also:
REParser

Field Summary
static java.lang.String ALPHABET_FOOTER
          The alphabet footer
static java.lang.String ALPHABET_HEADER
          The alphabet header
static java.lang.String ALPHABET_SEPARATOR
          The alphabet separator
static java.lang.String DESCRIPTION_HEADER
          The description header
static java.lang.String NAME_AND_DESCRIPTION_SEPARATOR
          The name and description separator
static java.lang.String NAME_HEADER
          The name header
protected  java.io.PrintWriter out_
          The PrintWriter to use as output
 
Fields inherited from class laser.regularlanguage.regularexpression.AbstractREVisitor
result
 
Fields inherited from interface laser.regularlanguage.regularexpression.REConstants
CHOICE, COMMA, COMMENT_PREFIX, CONCATENATION, DOT, EMPTY, EPSILON, EXPONENT, KLEENE_PLUS, KLEENE_STAR, LBRACE, LBRACKET, LPAREN, NOT, OPTION, RANGE, RBRACE, RBRACKET, RPAREN
 
Constructor Summary
REPrinter(java.io.Writer out)
          Creates a new REPrinter.
 
Method Summary
 void caseChoiceNode(ChoiceNode<L> node, java.lang.Object context)
          Prints out the given ChoiceNode.
 void caseClassSetNode(ClassSetNode<L> node, java.lang.Object context)
          Prints out the given ClassSet.
 void caseConcatenationNode(ConcatenationNode<L> node, java.lang.Object context)
          Prints out the given ConcatenationNode.
 void caseDotNode(DotNode<L> node, java.lang.Object context)
          Prints out the given DotNode.
 void caseEmptyNode(EmptyNode<L> node, java.lang.Object context)
          Prints out the given EmptyNode.
 void caseEpsilonNode(EpsilonNode<L> node, java.lang.Object context)
          Allows this REVisitor to process the given EpsilonNode.
 void caseExponentNode(ExponentNode<L> node, java.lang.Object context)
          Prints out the given ExponentNode.
 void caseKleenePlusNode(KleenePlusNode<L> node, java.lang.Object context)
          Prints out the given KleenePlusNode.
 void caseKleeneStarNode(KleeneStarNode<L> node, java.lang.Object context)
          Prints out the given KleeneStarNode.
 void caseLabelNode(LabelNode<L> node, java.lang.Object context)
          Prints out the given LabelNode.
 void caseNotClassSetNode(NotClassSetNode<L> node, java.lang.Object context)
          Prints out the given NotClassSet.
 void caseOptionNode(OptionNode<L> node, java.lang.Object context)
          Prints out the given OptionNode.
protected  void checkPreconditions(RE<L> theRE)
          Checks that the preconditions are met.
protected  void internalPrint(BinaryTreeNode<L> node, java.lang.String op)
          Prints out the given BinaryTreeNode to the specified Writer.
protected  void internalPrint(TreeNode<L> node)
          Prints out the given TreeNode to the specified Writer.
protected  void internalPrint(UnaryTreeNode<L> node, java.lang.String op)
          Prints out the given UnaryTreeNode to the specified Writer.
protected  void internalPrintAlphabet(AlphabetInterface<L> alphabet)
          Prints out the given alphabet to the specified Writer.
protected  void internalPrintDescription(java.lang.StringBuffer description)
          Prints out the given description to the specified Writer.
protected  void internalPrintLabel(L label)
          Prints out the given label to the specified Writer.
protected  void internalPrintName(java.lang.String name)
          Prints out the given name to the specified Writer.
 void print(RE<L> theRE)
          Prints out the given RE to the specified Writer.
 void print(TreeNode<L> node)
          Prints out the given TreeNode to the specified Writer.
 
Methods inherited from class laser.regularlanguage.regularexpression.AbstractREVisitor
defaultCase, getResult, setResult
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_HEADER

public static final java.lang.String NAME_HEADER
The name header

See Also:
Constant Field Values

DESCRIPTION_HEADER

public static final java.lang.String DESCRIPTION_HEADER
The description header

See Also:
Constant Field Values

NAME_AND_DESCRIPTION_SEPARATOR

public static final java.lang.String NAME_AND_DESCRIPTION_SEPARATOR
The name and description separator

See Also:
Constant Field Values

ALPHABET_HEADER

public static final java.lang.String ALPHABET_HEADER
The alphabet header

See Also:
Constant Field Values

ALPHABET_SEPARATOR

public static final java.lang.String ALPHABET_SEPARATOR
The alphabet separator

See Also:
Constant Field Values

ALPHABET_FOOTER

public static final java.lang.String ALPHABET_FOOTER
The alphabet footer

See Also:
Constant Field Values

out_

protected final java.io.PrintWriter out_
The PrintWriter to use as output

Constructor Detail

REPrinter

public REPrinter(java.io.Writer out)
Creates a new REPrinter.

Parameters:
out - The Writer to use as output (non-null)
Method Detail

print

public void print(RE<L> theRE)
           throws java.io.IOException,
                  REException
Prints out the given RE to the specified Writer.

PRECONDITIONS:

Throws:
java.io.IOException - if an I/O error occurred while printing the RE
REException - if a Visitor error occurs

checkPreconditions

protected void checkPreconditions(RE<L> theRE)
Checks that the preconditions are met.

Parameters:
theRE - The RE to be checked

print

public void print(TreeNode<L> node)
           throws java.io.IOException,
                  REVisitorException
Prints out the given TreeNode to the specified Writer.

Parameters:
node - The node to be printed
Throws:
java.io.IOException - if an I/O error occurred while printing the RE
REVisitorException - if an error occurs

internalPrint

protected void internalPrint(TreeNode<L> node)
                      throws REVisitorException
Prints out the given TreeNode to the specified Writer.

Parameters:
node - The node to be printed
Throws:
REVisitorException - if an error occurs

internalPrint

protected void internalPrint(UnaryTreeNode<L> node,
                             java.lang.String op)
                      throws REVisitorException
Prints out the given UnaryTreeNode to the specified Writer.

Parameters:
node - The node to be printed
op - The string representation of the operator
Throws:
REVisitorException - if an error occurs

internalPrint

protected void internalPrint(BinaryTreeNode<L> node,
                             java.lang.String op)
                      throws REVisitorException
Prints out the given BinaryTreeNode to the specified Writer.

Parameters:
node - The node to be printed
op - The string representation of the operator
Throws:
REVisitorException - if an error occurs

internalPrintName

protected void internalPrintName(java.lang.String name)
Prints out the given name to the specified Writer.

Parameters:
name - The name to be printed

internalPrintDescription

protected void internalPrintDescription(java.lang.StringBuffer description)
Prints out the given description to the specified Writer.

Parameters:
description - The description to be printed

internalPrintAlphabet

protected void internalPrintAlphabet(AlphabetInterface<L> alphabet)
Prints out the given alphabet to the specified Writer.

Parameters:
alphabet - The alphabet to be printed

internalPrintLabel

protected void internalPrintLabel(L label)
Prints out the given label to the specified Writer.

Parameters:
label - The label to be printed

caseChoiceNode

public void caseChoiceNode(ChoiceNode<L> node,
                           java.lang.Object context)
                    throws REVisitorException
Prints out the given ChoiceNode.

Specified by:
caseChoiceNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseChoiceNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ChoiceNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseClassSetNode

public void caseClassSetNode(ClassSetNode<L> node,
                             java.lang.Object context)
                      throws REVisitorException
Prints out the given ClassSet.

NOTE: This is a base case.

Specified by:
caseClassSetNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseClassSetNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ClassSetNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseConcatenationNode

public void caseConcatenationNode(ConcatenationNode<L> node,
                                  java.lang.Object context)
                           throws REVisitorException
Prints out the given ConcatenationNode.

Specified by:
caseConcatenationNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseConcatenationNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ConcatenationNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseDotNode

public void caseDotNode(DotNode<L> node,
                        java.lang.Object context)
                 throws REVisitorException
Prints out the given DotNode.

NOTE: This is a base case.

Specified by:
caseDotNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseDotNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The DotNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseEmptyNode

public void caseEmptyNode(EmptyNode<L> node,
                          java.lang.Object context)
Prints out the given EmptyNode.

NOTE: This is a base case.

Specified by:
caseEmptyNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseEmptyNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The EmptyNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseEpsilonNode

public void caseEpsilonNode(EpsilonNode<L> node,
                            java.lang.Object context)
                     throws REVisitorException
Allows this REVisitor to process the given EpsilonNode.

NOTE: This is a base case.

Specified by:
caseEpsilonNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseEpsilonNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The EpsilonNode to be processed
context - The calling context
Throws:
REVisitorException - if an error occurs

caseExponentNode

public void caseExponentNode(ExponentNode<L> node,
                             java.lang.Object context)
                      throws REVisitorException
Prints out the given ExponentNode.

Specified by:
caseExponentNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseExponentNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ExponentNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseKleenePlusNode

public void caseKleenePlusNode(KleenePlusNode<L> node,
                               java.lang.Object context)
                        throws REVisitorException
Prints out the given KleenePlusNode.

Specified by:
caseKleenePlusNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseKleenePlusNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The KleenePlusNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseKleeneStarNode

public void caseKleeneStarNode(KleeneStarNode<L> node,
                               java.lang.Object context)
                        throws REVisitorException
Prints out the given KleeneStarNode.

Specified by:
caseKleeneStarNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseKleeneStarNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The KleeneStarNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseLabelNode

public void caseLabelNode(LabelNode<L> node,
                          java.lang.Object context)
                   throws REVisitorException
Prints out the given LabelNode.

NOTE: This is a base case.

Specified by:
caseLabelNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseLabelNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The LabelNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseNotClassSetNode

public void caseNotClassSetNode(NotClassSetNode<L> node,
                                java.lang.Object context)
                         throws REVisitorException
Prints out the given NotClassSet.

Specified by:
caseNotClassSetNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseNotClassSetNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The NotClassSetNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseOptionNode

public void caseOptionNode(OptionNode<L> node,
                           java.lang.Object context)
                    throws REVisitorException
Prints out the given OptionNode.

Specified by:
caseOptionNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseOptionNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The OptionNode to be printed
context - This is currently not being used
Throws:
REVisitorException - if an error occurs