Returns an independently positioned view into the token stream,
initialized with identical state to this Input
.
Returns the one-based column number of the current lookahead token, relative to the current line in the stream.
Returns the current lookahead token, if this Input
is in the
cont state.
Returns an object that identifies the token stream, or null
if the
stream is unidentified.
Returns an Input
equivalent to this Input
, but logically identified by
the given–possibly null
–id
. The caller's reference to this
Input}
should be replaced by the returned Input}
.
Returns true
when a lookahead token is immediately available.
i.e. this Input
is in the cont state.
Returns true
when no lookahead token is currently available, and
no additional input will ever become available. i.e. this Input
is in
the done state.
Returns true
when no lookahead token is currently available, but
additional input may be available at some point in the future. i.e. this
Input
is in the empty state.
Returns true
when no lookahead token is currently available due to
an error with the token stream. i.e. this Input
is in the error
state.
When true
, trap()
will return the input error
Returns true
if this is a partial Input
will that enter
the empty
state after it consumes the last available input token.
Returns a partial Input
equivalent to this Input
, if
isPart
is true
; returns a final Input
equivalent
to this Input
if isPart
is false
. The caller's reference
to this
Input
should be replaced by the returned Input
Returns the one-based line number of the current lookahead token, relative to the start of the stream.
Returns the position of the current lookahead token, relative to the start of the stream.
Returns an Input
equivalent to this Input
, but logically positioned at
the given mark
. The physical position in the input stream is not
modified. The caller's reference to this
Input
should be replaced by
the returned Input
.
Returns the byte offset of the current lookahead token, relative to the start of the stream.
Returns the InputSettings
used to configure the behavior of input
consumers that read from this Input
.
Returns a clone of this Input
with the given settings
.
Advances to the next token, if this Input
is in the cont state.
Returns the input error. Only guaranteed to return an error when in the _ error_ state
Returns an Input
reader in the done state, with the given settings
,
at the mark
position of a token stream logically identified by id
.
Returns an Input
reader in the empty state, with the given settings
,
at the mark
position of a token stream logically identified by id
.
Returns an Input
in the error state, with the given settings
,
at the mark
position of a token stream logically identified by id
.
Non-blocking token stream reader, with single token lookahead.
Input
enables incremental, interruptible parsing of network protocols and data formats.Input tokens
Input tokens are modeled as primitive numbers, commonly representing Unicode code points, or raw octets; each
Input
implementation specifies the semantic type of its tokens. The head method peeks at the lookahead token, without consuming it, and the step method advances the input to the next token.Input states
An
Input
reader is always in one of three states: cont_inue, _empty, or done. The cont state indicates that a lookahead token is immediately available; the empty state indicates that no additional tokens are available at this time, but that the stream may logically resume at some point in the future; and the done state indicates that the stream has terminated. isCont returnstrue
when in the cont state; isEmpty returnstrue
when in the empty state; and isDone returnstrue
when in the done state.Non-blocking behavior
Input
readers never block. AnInput
reader that would otherwise block awaiting additional input instead enters the empty state, signaling the input consumer to back off processing the input, but to remain prepared to process additional input in the future. AnInput
reader enters the done state when it encounters the final end of its input, signaling the input consumer to stop processing. Input.empty returns anInput
reader in the empty state. Input.done returns anInput
reader in the done state.Position tracking
The logical position of the lookahead token is made available via the mark method, with optimized callouts for the byte offset, one-based line number, and one-based column in the current line. The id method returns a diagnostic identifier for the token stream.
Cloning
An
Input
reader may be cloned to provide an indepently mutable position into a shared token stream. Not allInput
implementations support cloning.InputSettings
Parser