xtc.parser
Class PrettyPrinter

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.PrettyPrinter
Direct Known Subclasses:
HtmlPrinter

public class PrettyPrinter
extends Visitor

The grammar pretty printer.

Version:
$Revision: 1.117 $
Author:
Robert Grimm

Field Summary
protected  AST ast
          The type operations.
protected  boolean isTopLevel
          Flag for whether the choice is top-level.
protected  boolean newline
          Flag for whether the last element ended in a newline.
protected  boolean parenChoice
          Flag for whether the next ordered choice needs to be parenthesized.
protected  boolean parenSequence
          Flag for whether the next sequence element needs to be parenthesized.
protected  Printer printer
          The printer for this pretty printer.
protected  boolean verbose
          The flag for whether this pretty printer is verbose.
 
Constructor Summary
protected PrettyPrinter(AST ast, boolean verbose)
          Create a new pretty printer.
  PrettyPrinter(Printer printer, AST ast, boolean verbose)
          Create a new pretty printer.
 
Method Summary
protected  void enter(Production p)
          Enter the specified production.
protected  void exit(Production p)
          Exit the specified production.
 void flush()
          Flush the underlying printer.
protected  void format(boolean isToken, java.lang.String text)
          Format the specified statically known text value.
protected  boolean isPrefix(Element e)
          Determine whether the specified element represents a prefix operator.
protected  void print(Action a, boolean caret)
          Print the specified action.
protected  void print(java.util.List<Sequence> alternatives, java.lang.String mark)
          Print the specified alternatives.
protected  void print(ModuleDependency dep, java.lang.String name)
          Print the specified module dependency.
protected  void print(java.lang.String s)
          Print the specified action string.
protected  void printActions(Module m)
          Print the specified module's header, body, and footer actions.
protected  void printDocumentation(Module m)
          Print the specified module documentation comment.
protected  void printModule(Module m)
          Print the specified module's declaration.
protected  void printOption(Module m)
          Print the specified module's options.
protected  int regexEscapes()
          Get the flags for escaping regex strings.
protected  int stringEscapes()
          Get the flags for escaping regular strings.
 void visit(Action a)
          Print the specified action.
 void visit(ActionBaseValue v)
          Print the specified action base value.
 void visit(AlternativeAddition p)
          Print the specified alternative addition.
 void visit(AlternativeRemoval p)
          Print the specified alternative removal.
 void visit(AnyChar a)
          Print the specified any character element.
 void visit(Attribute a)
          Print the specified attribute.
 void visit(Binding b)
          Print the specified binding.
 void visit(BindingValue v)
          Print the specified binding value.
 void visit(CharCase c)
          Print the specified character case.
 void visit(CharClass c)
          Print the specified character class.
 void visit(CharLiteral l)
          Print the specified character literal.
 void visit(CharRange r)
          Print the specified character range.
 void visit(CharSwitch s)
          Print the specified character switch.
 void visit(EmptyListValue v)
          Print the specified empty list value.
 void visit(FollowedBy p)
          Print the specified followed-by element.
 void visit(FullProduction p)
          Print the specified full production.
 void visit(GenericActionValue v)
          Print the specified generic action value.
 void visit(GenericNodeValue v)
          Print the specified generic node value.
 void visit(GenericRecursionValue v)
          Print the specified generic recursion value.
 void visit(Grammar g)
          Print the specified grammar.
 void visit(Module m)
          Print the specified module.
 void visit(ModuleImport imp)
          Print the specified module import.
 void visit(ModuleInstantiation ins)
          Print the specified module instantiation.
 void visit(ModuleList list)
          Print the specified module list.
 void visit(ModuleModification mod)
          Print the specified module modification.
 void visit(ModuleName name)
          Print the specified module name.
 void visit(NodeMarker m)
          Print the specified node marker.
 void visit(NonTerminal nt)
          Print the specified nonterminal.
 void visit(NotFollowedBy p)
          Print the specified not-followed-by element.
 void visit(NullLiteral l)
          Print the specified null literal.
 void visit(NullValue v)
          Print the specified null value.
 void visit(Option o)
          Print the specified option.
 void visit(OrderedChoice c)
          Print the specified ordered choice.
 void visit(ParserAction pa)
          Print the specified parser action.
 void visit(ParseTreeNode n)
          Print the specified parse tree node.
 void visit(ProductionOverride p)
          Print the specified production override.
 void visit(ProperListValue v)
          Print the specified proper list value.
 void visit(Repetition r)
          Print the specified repetition.
 void visit(SemanticPredicate p)
          Print the specified semantic predicate.
 void visit(Sequence s)
          Print the specified sequence.
 void visit(SequenceName n)
          Print the specified sequence name.
 void visit(StringLiteral l)
          Print the specified string literal.
 void visit(StringMatch m)
          Print the specified string match.
 void visit(StringValue v)
          Print the specified string value.
 void visit(TokenValue v)
          Print the specified token value.
 void visit(VoidedElement v)
          Print the specified voided element.
 
Methods inherited from class xtc.tree.Visitor
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printer

protected Printer printer
The printer for this pretty printer.


ast

protected final AST ast
The type operations.


verbose

protected final boolean verbose
The flag for whether this pretty printer is verbose.


newline

protected boolean newline
Flag for whether the last element ended in a newline.


parenChoice

protected boolean parenChoice
Flag for whether the next ordered choice needs to be parenthesized.


parenSequence

protected boolean parenSequence
Flag for whether the next sequence element needs to be parenthesized.


isTopLevel

protected boolean isTopLevel
Flag for whether the choice is top-level.

Constructor Detail

PrettyPrinter

protected PrettyPrinter(AST ast,
                        boolean verbose)
Create a new pretty printer. Any subclass using this constructor must explicit set the printer field and register this visitor with the set printer.

Parameters:
ast - The type operations.
verbose - The verbose flag.

PrettyPrinter

public PrettyPrinter(Printer printer,
                     AST ast,
                     boolean verbose)
Create a new pretty printer.

Parameters:
printer - The printer.
ast - The type operations.
verbose - The verbose flag.
Method Detail

stringEscapes

protected int stringEscapes()
Get the flags for escaping regular strings.

Returns:
The flags for escaping strings.

regexEscapes

protected int regexEscapes()
Get the flags for escaping regex strings.

Returns:
The flags for escaping regex strings.

isPrefix

protected boolean isPrefix(Element e)
Determine whether the specified element represents a prefix operator.

Parameters:
e - The element.
Returns:
true if the specified element represents a prefix operator.

flush

public void flush()
Flush the underlying printer.


visit

public void visit(Attribute a)
Print the specified attribute.


visit

public void visit(Grammar g)
Print the specified grammar.


printDocumentation

protected void printDocumentation(Module m)
Print the specified module documentation comment.

Parameters:
m - The module.

printModule

protected void printModule(Module m)
Print the specified module's declaration.

Parameters:
m - The module.

printActions

protected void printActions(Module m)
Print the specified module's header, body, and footer actions.

Parameters:
m - The module.

printOption

protected void printOption(Module m)
Print the specified module's options.

Parameters:
m - The module.

visit

public void visit(Module m)
Print the specified module.


print

protected void print(ModuleDependency dep,
                     java.lang.String name)
Print the specified module dependency.

Parameters:
dep - The dependency.
name - The corresponding name.

visit

public void visit(ModuleImport imp)
Print the specified module import.


visit

public void visit(ModuleInstantiation ins)
Print the specified module instantiation.


visit

public void visit(ModuleModification mod)
Print the specified module modification.


visit

public void visit(ModuleList list)
Print the specified module list.


visit

public void visit(ModuleName name)
Print the specified module name.


enter

protected void enter(Production p)
Enter the specified production. This method prints a comment for productions folded from duplicates. It then prints the specified production's attributes, type, and name. Finally, it sets parenChoice and parenSequence to false.

Parameters:
p - The production.

exit

protected void exit(Production p)
Exit the specified production. The default implementation prints a new line.

Parameters:
p - The production.

visit

public void visit(AlternativeAddition p)
Print the specified alternative addition.


visit

public void visit(AlternativeRemoval p)
Print the specified alternative removal.


visit

public void visit(ProductionOverride p)
Print the specified production override.


visit

public void visit(FullProduction p)
Print the specified full production.


print

protected void print(java.util.List<Sequence> alternatives,
                     java.lang.String mark)
Print the specified alternatives.

Parameters:
alternatives - The ordered list of alternatives.
mark - The mark.

visit

public void visit(OrderedChoice c)
Print the specified ordered choice.


visit

public void visit(Repetition r)
Print the specified repetition.


visit

public void visit(Option o)
Print the specified option.


visit

public void visit(SequenceName n)
Print the specified sequence name.


visit

public void visit(Sequence s)
Print the specified sequence.


visit

public void visit(FollowedBy p)
Print the specified followed-by element.


visit

public void visit(NotFollowedBy p)
Print the specified not-followed-by element.


visit

public void visit(SemanticPredicate p)
Print the specified semantic predicate.


visit

public void visit(VoidedElement v)
Print the specified voided element.


visit

public void visit(Binding b)
Print the specified binding.


visit

public void visit(StringMatch m)
Print the specified string match.


visit

public void visit(NonTerminal nt)
Print the specified nonterminal.


visit

public void visit(StringLiteral l)
Print the specified string literal.


visit

public void visit(AnyChar a)
Print the specified any character element.


visit

public void visit(CharLiteral l)
Print the specified character literal.


visit

public void visit(CharRange r)
Print the specified character range.


visit

public void visit(CharClass c)
Print the specified character class.


visit

public void visit(CharCase c)
Print the specified character case.


visit

public void visit(CharSwitch s)
Print the specified character switch.


print

protected void print(java.lang.String s)
Print the specified action string.

Parameters:
s - The string.

print

protected void print(Action a,
                     boolean caret)
Print the specified action.

Parameters:
a - The action to print.
caret - Flag for whether to prefix the action with a caret.

visit

public void visit(NodeMarker m)
Print the specified node marker.


visit

public void visit(Action a)
Print the specified action.


visit

public void visit(ParserAction pa)
Print the specified parser action.


visit

public void visit(ParseTreeNode n)
Print the specified parse tree node.


visit

public void visit(NullLiteral l)
Print the specified null literal.


visit

public void visit(NullValue v)
Print the specified null value.


format

protected void format(boolean isToken,
                      java.lang.String text)
Format the specified statically known text value.

Parameters:
isToken - Flag for whether the value is a token.
text - The text.

visit

public void visit(StringValue v)
Print the specified string value.


visit

public void visit(TokenValue v)
Print the specified token value.


visit

public void visit(BindingValue v)
Print the specified binding value.


visit

public void visit(EmptyListValue v)
Print the specified empty list value.


visit

public void visit(ProperListValue v)
Print the specified proper list value.


visit

public void visit(ActionBaseValue v)
Print the specified action base value.


visit

public void visit(GenericNodeValue v)
Print the specified generic node value.


visit

public void visit(GenericActionValue v)
Print the specified generic action value.


visit

public void visit(GenericRecursionValue v)
Print the specified generic recursion value.



Copyright © 2012. All Rights Reserved.