|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unkrig.commons.text.scanner.AbstractScanner<TT>
de.unkrig.commons.text.scanner.StatefulScanner<TT,S>
TT - Enumerates the scanner-specific token typesS - Enumerates the scanner-specific non-default statespublic class StatefulScanner<TT extends java.lang.Enum<TT>,S extends java.lang.Enum<S>>
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, and also how the scanner changes state. Initially the scanner is in
the default state. The non-default states are defined by the S type parameter.
For an example usage, see JavaScanner.
| 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 | |
|---|---|
StatefulScanner(java.lang.Class<S> states)
|
|
| Method Summary | |
|---|---|
void |
addRule(S state,
java.lang.String regex,
TT tokenType)
Adds a rule that applies iff the scanner is in the the given state. |
void |
addRule(S state,
java.lang.String regex,
TT tokenType,
S nextState)
Adds a rule that applies iff the scanner is in the the given state. |
void |
addRule(java.lang.String regex,
TT tokenType)
Adds a rule that applies iff the scanner is in the "default state". |
void |
addRule(java.lang.String regex,
TT tokenType,
S nextState)
Adds a rule that applies iff the scanner is in the "default state". |
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 |
|---|
public StatefulScanner(java.lang.Class<S> states)
| Method Detail |
|---|
public void addRule(java.lang.String regex,
TT tokenType)
Pattern
public void addRule(java.lang.String regex,
TT tokenType,
S nextState)
nextState - The new current state after the rule has matchedPattern
public void addRule(@Nullable
S state,
java.lang.String regex,
TT tokenType)
state. The scanner returns to the default
state after the rule has matched.
state - null means "any state"Pattern
public void addRule(@Nullable
S state,
java.lang.String regex,
TT tokenType,
S nextState)
state.
state - null means "any state"nextState - The new current state after the rule has matchedPattern
@Nullable
public AbstractScanner.Token<TT> produce()
throws ScanException
AbstractScannerAbstractScanner.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.
produce in interface ProducerWhichThrows<AbstractScanner.Token<TT extends java.lang.Enum<TT>>,ScanException>produce in class AbstractScanner<TT extends java.lang.Enum<TT>>null iff the input string is exhausted
ScanException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||