TT
- Enumerates the scanner-specific token typesS
- Enumerates the scanner-specific non-default statespublic class StatefulScanner<TT extends Enum<TT>,S extends Enum<S>> extends AbstractScanner<TT>
Token
s 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.Token
s, 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
.
Modifier and Type | Class and Description |
---|---|
class |
StatefulScanner.Rule |
AbstractScanner.Token<TT extends Enum<TT>>
Modifier and Type | Field and Description |
---|---|
EnumSet<S> |
ANY_STATE
Special value for some method parameters.
|
S |
REMAIN
Special value for some method parameters; indicates that the current state should remain when the
rule applies.
|
cs, offset, previousTokenOffset
Constructor and Description |
---|
StatefulScanner(Class<S> states) |
StatefulScanner(StatefulScanner<TT,S> that)
Clones the configuration of the other scanner, but has a separate state.
|
Modifier and Type | Method and Description |
---|---|
StatefulScanner.Rule |
addRule(EnumSet<S> states,
String regex,
TT tokenType)
Adds a rule that applies iff states
== ANY_STATE , or the scanner is in one of the
given non-default states, or the states contain null and the scanner is in the
default state. |
StatefulScanner.Rule |
addRule(EnumSet<S> states,
String regex,
TT tokenType,
S nextState)
Deprecated.
Use
ss.addRule(states, regex, tokenType).goTo(nextState) instead |
StatefulScanner.Rule |
addRule(S state,
String regex,
TT tokenType)
Adds a rule that applies iff the scanner is in the given non-default state.
|
StatefulScanner.Rule |
addRule(S state,
String regex,
TT tokenType,
S nextState)
Deprecated.
Use
addRule(state, regex, tokenType).goTo(nextState) |
StatefulScanner.Rule |
addRule(String regex,
TT tokenType)
Adds a rule that applies iff the scanner is in the "default state".
|
StatefulScanner.Rule |
addRule(String regex,
TT tokenType,
S nextState)
Deprecated.
Use
ss.addRule(regex, tokenType).goTo(nextState) instead. |
S |
getCurrentState() |
AbstractScanner.Token<TT> |
produce()
Before
StringScanner.setInput(CharSequence) is called, this method returns null . |
void |
setCurrentState(S newState) |
getOffset, getPreviousTokenOffset, setInput, suppress, suppress, toString
@Nullable public final EnumSet<S extends Enum<S>> ANY_STATE
@Nullable public final S extends Enum<S> REMAIN
addRule(EnumSet, String, Enum, Enum)
public StatefulScanner(StatefulScanner<TT,S> that)
public StatefulScanner.Rule addRule(String regex, TT tokenType)
Pattern
public StatefulScanner.Rule addRule(S state, String regex, TT tokenType)
state
- null
means "any state"Pattern
public StatefulScanner.Rule addRule(@Nullable EnumSet<S> states, String regex, TT tokenType)
==
ANY_STATE
, or the scanner is in one of the
given non-default states, or the states contain null
and the scanner is in the
default state. The scanner returns to the default state after the rule has matched.Pattern
@Nullable public S getCurrentState()
null
for the default statepublic void setCurrentState(@Nullable S newState)
newState
- The new state of this scanner; null
for the default state@Nullable public AbstractScanner.Token<TT> produce() throws ScanException
StringScanner
StringScanner.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
@Deprecated public StatefulScanner.Rule addRule(String regex, TT tokenType, S nextState)
ss.addRule(regex, tokenType).goTo(nextState)
instead.@Deprecated public StatefulScanner.Rule addRule(S state, String regex, TT tokenType, @Nullable S nextState)
addRule(state, regex, tokenType).goTo(nextState)
@Deprecated public StatefulScanner.Rule addRule(@Nullable EnumSet<S> states, String regex, TT tokenType, @Nullable S nextState)
ss.addRule(states, regex, tokenType).goTo(nextState)
insteadCopyright © 2018 Arno Unkrig. All rights reserved.