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

java.lang.Object
  extended by net.sf.parcinj.AbstractSymbol<P>
All Implemented Interfaces:
Symbol<P>
Direct Known Subclasses:
Alternative, NonTerminalSymbol, OneOrMore, Optional, Sequence, SequenceOfSeparatedSymbols, TerminalSymbol, ZeroOrMore

public abstract class AbstractSymbol<P extends Processor>
extends java.lang.Object
implements Symbol<P>

Abstract super class which implements Symbol.process(TokenIterator, Processor) according to the contract. Subclasses have to implement Symbol.matches(Token) and doProcess(TokenIterator, Processor).

In addition the methods of the fluent interface API are implemented.

It is recommended to extend this class when introducing a new Symbol.


Constructor Summary
AbstractSymbol()
           
 
Method Summary
protected abstract  void doProcess(TokenIterator iterator, P processor)
          Processes tokens taken from the specified iterator without initial matching check.
 Symbol<P> followedBy(Symbol<P> symbol)
          Returns a symbol which assumes this symbol followed by the specified symbol.
 Symbol<P> oneOrMoreTimes()
          Returns a symbol which allows this symbol to appear one or more times.
 Symbol<P> optional()
          Returns a symbol which allows this symbol to be optional.
 Symbol<P> or(Symbol<P> symbol)
          Returns a symbol which allows this symbol or the specified symbol to appear.
 void process(TokenIterator iterator, P processor)
          Processes zero or many tokens from the specified iterator.
 Symbol<P> zeroOrMoreTimes()
          Returns a symbol which allows this symbol to appear zero or more times.
 Symbol<P> zeroOrMoreTimesSeparatedBy(Symbol<P> delimiter)
          Returns a symbol which assumes this symbol to appear zero or more times separated by the specified delimiter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.parcinj.Symbol
matches
 

Constructor Detail

AbstractSymbol

public AbstractSymbol()
Method Detail

process

public final void process(TokenIterator iterator,
                          P processor)
                   throws ParsingException
Processes zero or many tokens from the specified iterator. First Symbol.matches(Token) is invoked for the current token. If it fails a ParsingException is thrown. Otherwise doProcess(TokenIterator, Processor) is invoked. All throwables (except ParsingException) thrown by this method are wrap by a ParsingException.

Specified by:
process in interface Symbol<P extends Processor>
Throws:
ParsingException - if the tokens delivered by the iterator are not as expected or processor throws an exception which should the cause of the thrown exception.

doProcess

protected abstract void doProcess(TokenIterator iterator,
                                  P processor)
                           throws ParsingException
Processes tokens taken from the specified iterator without initial matching check.

Parameters:
processor - Processor who does the actual processing.
Throws:
ParsingException - if a parsing error occurs.

optional

public Symbol<P> optional()
Description copied from interface: Symbol
Returns a symbol which allows this symbol to be optional.

Specified by:
optional in interface Symbol<P extends Processor>

zeroOrMoreTimes

public Symbol<P> zeroOrMoreTimes()
Description copied from interface: Symbol
Returns a symbol which allows this symbol to appear zero or more times.

Specified by:
zeroOrMoreTimes in interface Symbol<P extends Processor>

oneOrMoreTimes

public Symbol<P> oneOrMoreTimes()
Description copied from interface: Symbol
Returns a symbol which allows this symbol to appear one or more times.

Specified by:
oneOrMoreTimes in interface Symbol<P extends Processor>

zeroOrMoreTimesSeparatedBy

public Symbol<P> zeroOrMoreTimesSeparatedBy(Symbol<P> delimiter)
Description copied from interface: Symbol
Returns a symbol which assumes this symbol to appear zero or more times separated by the specified delimiter.

Specified by:
zeroOrMoreTimesSeparatedBy in interface Symbol<P extends Processor>

or

public Symbol<P> or(Symbol<P> symbol)
Description copied from interface: Symbol
Returns a symbol which allows this symbol or the specified symbol to appear.

Specified by:
or in interface Symbol<P extends Processor>

followedBy

public Symbol<P> followedBy(Symbol<P> symbol)
Description copied from interface: Symbol
Returns a symbol which assumes this symbol followed by the specified symbol.

Specified by:
followedBy in interface Symbol<P extends Processor>