Interface Input<D,T>
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type
- All Superinterfaces:
Comparable<Input<D,T>>
For actual, finite input the token sequence should be extended by a
potentially infinite repetition of distinguished end tokens
(typically of a reserved type EOF) carrying no further information.
-
Method Summary
Modifier and TypeMethodDescriptiondefault intCompare two inputs for temporal order.consume()Returns a new input that is advanced by one token.voidforce()Ensures that this input has at least one stored lookahead token.longgetIndex()Returns the number of tokens that have been consumed from this input.Returns an object that identifies the token source.booleanChecks whether one or more lookahead tokens have been generated ahead.booleanisStart()Checks whether this input is at the start and has not yet consumed any tokens.lookahead(int k) Returns the token that lies a given number of steps ahead.Returns the most recently consumed token.static <D,T> Input <D, T> Returns a parser input state lazily backed by a generator.transitionBy(Update<SimpleMessage<D>> effect) Returns an output specifying the given effect and this input as the remainder.
-
Method Details
-
lookahead
Returns the token that lies a given number of steps ahead.Numbering starts from zero;
k = 0selects the next token.- Parameters:
k- the number of steps to look ahead- Returns:
- the token that lies
ksteps ahead from this state. - Throws:
IllegalArgumentException- ifk < 0.
-
hasLookahead
boolean hasLookahead()Checks whether one or more lookahead tokens have been generated ahead.Modifications to the token source do only take effect immediately if this method returns
false.- Returns:
trueif one or more lookahead tokens have been generated ahead;falseif this input is fully synchronous with the token source- See Also:
-
isStart
boolean isStart()Checks whether this input is at the start and has not yet consumed any tokens.The method
lookbehind()may only be called if this method returnsfalse.- Returns:
trueif this input is at the start;falseif some tokens have already been consumed- See Also:
-
lookbehind
Returns the most recently consumed token.- Returns:
- the most recently consumed token
- Throws:
IllegalStateException- if this state points to the start of the token sequence- See Also:
-
consume
Returns a new input that is advanced by one token.- Returns:
- an input state pointing one step ahead in the token sequence
-
transitionBy
Returns an output specifying the given effect and this input as the remainder.- Parameters:
effect- the effect of parsing- Returns:
- an output specifying
effect, andthisas the remainder - Throws:
NullPointerException- ifeffectis null
-
getSourceIdentifier
Object getSourceIdentifier()Returns an object that identifies the token source.The resulting object should be used only in equality comparisons, to determine whether two inputs are snapshots of the consumption of the same source.
- Returns:
- an object that identifies the token source
-
getIndex
long getIndex()Returns the number of tokens that have been consumed from this input.- Returns:
- the number of tokens that have been consumed
-
compareTo
Compare two inputs for temporal order.Inputs are compared by the number of consumed tokens, if they have the same token source. Otherwise, they are incomparable.
- Specified by:
compareToin interfaceComparable<D>- Parameters:
other- the other input to compare to- Returns:
- an integer that represents the comparison of the respective number of consumed tokens
- Throws:
NullPointerException- ifotheris nullIllegalArgumentException- ifthisandotherhave different token sources- See Also:
-
force
void force()Ensures that this input has at least one stored lookahead token.If there is no lookahead token, the token source is queried. Otherwise, nothing happens.
- See Also:
-
of
Returns a parser input state lazily backed by a generator.The returned input state represent the potentially infinite sequence of tokens obtained by successive invocations of the method
Supplier.get()of the given generator.The sequence is created lazily; new tokens are demanded only when required by
lookahead(int)orconsume(). Thus concurrent shared use of the generator may result in nondeterministic behavior.The implementation is thread-safe: concurrent shared uses of the resulting
Inputobject observe consistent token sequences. However, the underlying supplier is per definition not thread-safe, and must not be used concurrently.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
gen- a functional object that generates tokens on demand- Returns:
- an input state lazily backed by the given generator.
-