de.unkrig.commons.text.scanner
Class StatelessScanner<TT extends java.lang.Enum<TT>>

java.lang.Object
  extended by de.unkrig.commons.text.scanner.AbstractScanner<TT>
      extended by de.unkrig.commons.text.scanner.StatelessScanner<TT>
Type Parameters:
TT - Enumerates the scanner-specific token types
All Implemented Interfaces:
ProducerWhichThrows<AbstractScanner.Token<TT>,ScanException>, StringScanner<TT>

public class StatelessScanner<TT extends java.lang.Enum<TT>>
extends AbstractScanner<TT>

A scanner that produces AbstractScanner.Tokens. Before produce() is called, the scanner must be configured by invoking its addRule(String, Enum) methods. These define how character sequences are converted into AbstractScanner.Tokens.

For an example usage, see the source code of Scanner


Nested Class Summary
 
Nested classes/interfaces inherited from class de.unkrig.commons.text.scanner.AbstractScanner
AbstractScanner.Token<TT extends java.lang.Enum<TT>>
 
Field Summary
 
Fields inherited from class de.unkrig.commons.text.scanner.AbstractScanner
cs, offset, previousTokenOffset
 
Constructor Summary
StatelessScanner()
           
 
Method Summary
 void addRule(java.lang.String regex, TT tokenType)
          Adds a rule that produces the given tokenType if the next characters of the input match the given regex.
 AbstractScanner.Token<TT> produce()
          Before AbstractScanner.setInput(CharSequence) is called, this method returns null.
 
Methods inherited from class de.unkrig.commons.text.scanner.AbstractScanner
getOffset, getPreviousTokenOffset, setInput, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StatelessScanner

public StatelessScanner()
Method Detail

addRule

public void addRule(java.lang.String regex,
                    TT tokenType)
Adds a rule that produces the given tokenType if the next characters of the input match the given regex.


produce

@Nullable
public AbstractScanner.Token<TT> produce()
                                                             throws ScanException
Description copied from class: AbstractScanner
Before AbstractScanner.setInput(CharSequence) is called, this method returns null. After AbstractScanner.setInput(CharSequence) was called, this method breaks the input char character sequence up into tokens and returns them one by one. When the input char sequence is exhausted, null is returned until AbstractScanner.setInput(CharSequence) is called again.

Specified by:
produce in interface ProducerWhichThrows<AbstractScanner.Token<TT extends java.lang.Enum<TT>>,ScanException>
Specified by:
produce in class AbstractScanner<TT extends java.lang.Enum<TT>>
Returns:
null iff the input string is exhausted
Throws:
ScanException