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

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

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

Wraps a symbol which will be processed only if it matches the current token.


Constructor Summary
Optional(Symbol<P> symbol)
          Creates an instance for the specified symbol.
 
Method Summary
protected  void doProcess(TokenIterator iterator, P processor)
          Processes the wrapped symbol if it matches the current token of the specified iterator.
 MatchingResult matches(Token token)
          Returns MatchingResult.OK.
 
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, toString, wait, wait, wait
 

Constructor Detail

Optional

public Optional(Symbol<P> symbol)
Creates an instance for the specified symbol.

Method Detail

matches

public MatchingResult matches(Token token)
Returns MatchingResult.OK.

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

doProcess

protected final void doProcess(TokenIterator iterator,
                               P processor)
                        throws ParsingException
Processes the wrapped symbol if it matches the current token of the specified iterator.

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