Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Input

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 cloned to provide an indepently mutable position into a shared token stream. Not all Input implementations support cloning.

see

InputSettings

see

Parser

Hierarchy

Index

Methods

Abstract clone

column

  • column(): number

Abstract head

  • head(): number

Abstract id

  • id(): unknown | null
  • id(id: unknown | null): Input
  • Returns an object that identifies the token stream, or null if the stream is unidentified.

    Returns unknown | null

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

    Parameters

    • id: unknown | null

    Returns Input

Abstract isCont

  • isCont(): boolean

Abstract isDone

  • isDone(): 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

Abstract isEmpty

  • isEmpty(): 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

Abstract isError

  • isError(): 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

Abstract isPart

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

    Returns boolean

  • 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

    Parameters

    • isPart: boolean

    Returns Input

line

  • line(): number

Abstract mark

offset

  • offset(): number

Abstract seek

Abstract settings

Abstract step

trap

  • trap(): Error
  • Returns the input error. Only guaranteed to return an error when in the _ error_ state

    throws

    InputException if the Input is not the _error_state

    Returns Error

Static done

  • Returns an Input reader in the done state, with the given settings, at the mark position of a token stream logically identified by id.

    Parameters

    • Default value id: unknown | null = null
    • Default value mark: Mark = Mark.zero()
    • Default value settings: InputSettings = InputSettings.standard()

    Returns Input

Static empty

  • Returns an Input reader in the empty state, with the given settings, at the mark position of a token stream logically identified by id.

    Parameters

    • Default value id: unknown | null = null
    • Default value mark: Mark = Mark.zero()
    • Default value settings: InputSettings = InputSettings.standard()

    Returns Input

Static error

  • Returns an Input in the error state, with the given settings, at the mark position of a token stream logically identified by id.

    Parameters

    • error: Error
    • Default value id: unknown | null = null
    • Default value mark: Mark = Mark.zero()
    • Default value settings: InputSettings = InputSettings.standard()

    Returns Input