Class InputAbstract

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]] returns true when in the cont state; [[isEmpty]] returns true when in the empty state; and [[isDone]] returns true when in the done state.

Non-blocking behavior

Input readers never block. An Input 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. An Input reader enters the done state when it encounters the final end of its input, signaling the input consumer to stop processing. [[Input.empty]] returns an Input reader in the empty state. [[Input.done]] returns an Input 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 [[clone cloned]] to provide an indepently mutable position into a shared token stream. Not all Input implementations support cloning.

See

  • [[InputSettings]]
  • [[Parser]]

Hierarchy

Constructors

Properties

column: number

The one-based column number of the current lookahead token, relative to the current line in the stream.

id: string

An informative identifier for this token stream, or undefined if this stream is unidentified.

line: number

The one-based line number of the current lookahead token, relative to the start of the stream.

mark: Mark

The position of the current lookahead token, relative to the start of the stream.

offset: number

The byte offset of the current lookahead token, relative to the start of the stream.

settings: InputSettings

The InputSettings used to configure the behavior of input consumers that read from this Input.

Methods

  • Returns a partial Input equivalent to this Input, if part is true; returns a final Input equivalent to this Input if part is false. The caller's reference to this Input should be replaced by the returned Input

    Parameters

    • part: boolean

    Returns Input

  • Returns an independently positioned view into the token stream, initialized with identical state to this Input.

    Returns Input

    Throws

    Error if this Input reader cannot be cloned.

  • Returns the current lookahead token, if this Input is in the cont state.

    Returns number

    Throws

    [[InputException]] if this Input is not in the cont state.

  • Returns true when a [[head lookahead]] token is immediately available. i.e. this Input is in the cont state.

    Returns boolean

  • 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 boolean

  • 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 boolean

  • 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 boolean

  • Returns true if this is a partial Input will that enter the empty state after it consumes the last available input token.

    Returns boolean

  • Sets the position of this Input to the given mark. Rewinds to the start of this Input, if mark is undefined.

    Parameters

    • Optional mark: Mark

    Returns Input

    Throws

    [[InputException]] if this Input does not support seeking, or is unable to reposition to the mark.

  • Advances to the next token, if this Input is in the cont state.

    Returns Input

    Throws

    Error if this Input is not in the cont state.

  • Returns the input error when in the error state

    Returns Error

    Throws

    InputException if the Input is not the _error_state

  • Returns an Input equivalent to this Input, but logically identified by the given–possibly undefinedid. The caller's reference to this Input should be replaced by the returned Input.

    Parameters

    • id: string

    Returns Input

  • 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.

    Parameters

    Returns Input

  • Returns a clone of this Input with the given settings.

    Parameters

    Returns Input

    Throws

    Error if this Input reader cannot be cloned.

  • Returns an Input reader in the done state.

    Returns Input

  • Returns an Input reader in the empty state.

    Returns Input

  • Returns an Input in the error state that traps the given error.

    Parameters

    • error: Error

    Returns Input

Generated using TypeDoc