dk.brics.servletvalidator.grammar
Class GrammarPrettyPrinter

java.lang.Object
  extended by dk.brics.servletvalidator.grammar.AbstractGrammarEntityVisitor
      extended by dk.brics.servletvalidator.AbstractPrettyPrinter<NonTerminal>
          extended by dk.brics.servletvalidator.grammar.GrammarPrettyPrinter
All Implemented Interfaces:
GrammarEntityVisitor, PrettyPrinter
Direct Known Subclasses:
AnnotatedPrettyPrinter

public class GrammarPrettyPrinter
extends AbstractPrettyPrinter<NonTerminal>

A pretty printer will print a Grammar in a readable way (similar to how grammars are normally written in CS articles). ε terminals are printed as "¤" to make then visible in the output and terminals only containing a space character are printed as "_" for the same reason. NonTerminals are names from A through Z and when this naming scheme runs out the convention is to start over from A1 through Z1, A2 trough Z2 and so on an so forth. Nothing is done to separate the case where a Terminal prints a capital character C from the case where a NonTerminal is called C. If the same Pretty printer is reused, a nonterminal will have the same name when printed multiple times.


Field Summary
 
Fields inherited from class dk.brics.servletvalidator.grammar.AbstractGrammarEntityVisitor
marked
 
Constructor Summary
GrammarPrettyPrinter(Grammar g)
           
 
Method Summary
protected  String getEasyName(NonTerminal nonTerminal)
           
 String getName(AlphabetSymbol a)
           
 String getTerminalName(Terminal t)
           
 String print()
          Prints the grammar to a string.
protected  String productionHook(Production p)
           
 
Methods inherited from class dk.brics.servletvalidator.AbstractPrettyPrinter
escapeSymbol, getNextName
 
Methods inherited from class dk.brics.servletvalidator.grammar.AbstractGrammarEntityVisitor
apply, apply, apply, apply, getPath, in, in, in, isMarked, mark, out, out, out, print, shouldPrettyPrint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrammarPrettyPrinter

public GrammarPrettyPrinter(Grammar g)
Method Detail

getEasyName

protected String getEasyName(NonTerminal nonTerminal)
Overrides:
getEasyName in class AbstractPrettyPrinter<NonTerminal>

getName

public String getName(AlphabetSymbol a)

getTerminalName

public String getTerminalName(Terminal t)

print

public String print()
Prints the grammar to a string. Names of the nonterminals are cached so they have the same name when they are printed again.

Returns:

productionHook

protected String productionHook(Production p)


Copyright © 2008 Mathias Schwarz.