net.sf.parcinj
Interface Symbol<P extends Processor>

All Known Implementing Classes:
AbstractSymbol, Alternative, NonTerminalSymbol, OneOrMore, Optional, Sequence, SequenceOfSeparatedSymbols, TerminalSymbol, TerminalSymbolByText, TerminalSymbolByType, ZeroOrMore

public interface Symbol<P extends Processor>

Interface of classes representing a symbol. A fluent interface API is supported by the methods followedBy(Symbol), oneOrMoreTimes(), optional(), or(Symbol), zeroOrMoreTimes(), and zeroOrMoreTimesSeparatedBy(Symbol).

Implementations should extend AbstractSymbol to fulfill the contract of process(TokenIterator, Processor). AbstractSymbol also implements the methods of the fluent interface API.


Method Summary
 Symbol<P> followedBy(Symbol<P> symbol)
          Returns a symbol which assumes this symbol followed by the specified symbol.
 MatchingResult matches(Token token)
          Returns true if the specified token matches.
 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 more tokens consumed from the specified iterator by using the specified processor.
 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.
 

Method Detail

matches

MatchingResult matches(Token token)
Returns true if the specified token matches.

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

process

void process(TokenIterator iterator,
             P processor)
             throws ParsingException
Processes zero or more tokens consumed from the specified iterator by using the specified processor.

Implementation have to call matches(Token) first with iterator.currentToken() as argument. If the matching result isn't successful a ParsingException has to be thrown which contains the failure reason.

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.

optional

Symbol<P> optional()
Returns a symbol which allows this symbol to be optional.


zeroOrMoreTimes

Symbol<P> zeroOrMoreTimes()
Returns a symbol which allows this symbol to appear zero or more times.


oneOrMoreTimes

Symbol<P> oneOrMoreTimes()
Returns a symbol which allows this symbol to appear one or more times.


zeroOrMoreTimesSeparatedBy

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


or

Symbol<P> or(Symbol<P> symbol)
Returns a symbol which allows this symbol or the specified symbol to appear.


followedBy

Symbol<P> followedBy(Symbol<P> symbol)
Returns a symbol which assumes this symbol followed by the specified symbol.