net.sf.parcinj
Class NonTerminalSymbol<P extends Processor>

java.lang.Object
  extended by net.sf.parcinj.AbstractSymbol<P>
      extended by net.sf.parcinj.NonTerminalSymbol<P>
All Implemented Interfaces:
Symbol<P>

public class NonTerminalSymbol<P extends Processor>
extends AbstractSymbol<P>

Named wrapper of a Symbol. The name will appear in the message text of a ParsingException. Matching is delegated to the wrapped symbol. doProcess(TokenIterator, Processor) is delegated to Symbol.process(TokenIterator, Processor). There are hooks methods invoked before (preProcess(Processor)) and after (postProcess(Processor)).

The wrapped symbol will be set by definedBy(Symbol). An IllegalStateException is thrown during parsing if the wrapped symbol hasn't been set.


Constructor Summary
NonTerminalSymbol(java.lang.String name)
          Creates an instance with the specified name.
 
Method Summary
 void definedBy(Symbol<P> symbol)
          Sets the wrapped symbol.
protected  void doProcess(TokenIterator iterator, P processor)
          Processes tokens taken from the specified iterator without initial matching check.
 MatchingResult matches(Token token)
          Returns true if the specified token matches.
protected  void postProcess(P processor)
          Invoke processing at the specified processor after the wrapped symbol has been processed.
protected  void preProcess(P processor)
          Invoke processing at the specified processor before the wrapped symbol will be processed.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.parcinj.AbstractSymbol
followedBy, oneOrMoreTimes, optional, or, process, zeroOrMoreTimes, zeroOrMoreTimesSeparatedBy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NonTerminalSymbol

public NonTerminalSymbol(java.lang.String name)
Creates an instance with the specified name.

Method Detail

definedBy

public final void definedBy(Symbol<P> symbol)
Sets the wrapped symbol.


matches

public final MatchingResult matches(Token token)
Description copied from interface: Symbol
Returns true if the specified token matches.

Parameters:
token - Token to be checked. Will be null if beyond last token.

doProcess

protected final void doProcess(TokenIterator iterator,
                               P processor)
                        throws ParsingException
Description copied from class: AbstractSymbol
Processes tokens taken from the specified iterator without initial matching check.

Specified by:
doProcess in class AbstractSymbol<P extends Processor>
processor - Processor who does the actual processing.
Throws:
ParsingException - if a parsing error occurs.

preProcess

protected void preProcess(P processor)
Invoke processing at the specified processor before the wrapped symbol will be processed. Default implementation does nothing.


postProcess

protected void postProcess(P processor)
Invoke processing at the specified processor after the wrapped symbol has been processed. Default implementation does nothing.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object