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>> extends AbstractScanner<TT>
Tokens from a character stream.
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.
AbstractScanner.Token<TT extends java.lang.Enum<TT>>cs, offset, previousTokenOffset| Constructor and Description |
|---|
StatefulScanner(java.lang.Class<S> states) |
| Modifier and Type | Method and Description |
|---|---|
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
StringScanner.setInput(CharSequence) is called, this method returns null. |
getOffset, getPreviousTokenOffset, setInput, toStringpublic StatefulScanner(java.lang.Class<S> states)
public void addRule(java.lang.String regex,
TT tokenType)
Patternpublic void addRule(java.lang.String regex,
TT tokenType,
S nextState)
nextState - The new current state after the rule has matchedPatternpublic 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"Patternpublic 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
StringScannerStringScanner.setInput(CharSequence) is called, this method returns null. After StringScanner.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 StringScanner.setInput(CharSequence) is called again.null iff the input string is exhaustedScanException