pdf-lite - v1.0.1
    Preparing search index...

    Class IncrementalParser<I, O>Abstract

    Abstract base class for incremental parsers that can process input as it becomes available. Supports buffering, lookahead, and backtracking for complex parsing scenarios.

    Type Parameters

    • I

      The input item type

    • O

      The output item type

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    buffer: I[] = []

    Buffer holding input items

    bufferIndex: number = 0

    Current position in the buffer

    eof: boolean = false

    Whether end of file has been signaled

    inputOffset: number = 0

    Current position in the input stream

    outputOffset: number = 0

    Number of outputs generated

    Methods

    • Override to customize when to compact the buffer By default, compacts when more than 1000 items have been consumed

      Returns boolean

      boolean indicating whether to compact the buffer

    • Consumes and validates the next item against an expected type or value.

      Type Parameters

      • T

        The expected item type

      Parameters

      • itemType: T | (new (...args: any[]) => T)

        Constructor or value to match against

      Returns T

      The consumed item cast to the expected type

      Error if the item doesn't match the expected type/value

    • Consumes and returns the next item from the buffer.

      Returns I

      The next item

      NoMoreTokensError if more input is needed and EOF not signaled

      EofReachedError if at EOF and no more items available

    • Tries multiple parsing functions and returns the first successful result. Automatically backtracks on failure.

      Parameters

      • ...fn: (() => O)[]

        Array of parsing functions to try

      Returns O

      The result from the first successful parsing function

      NoMoreTokensError if any function needs more input

      Error if all parsing functions fail

    • Peeks at an item in the buffer without consuming it.

      Parameters

      • ahead: number = 0

        Number of positions to look ahead (default: 0)

      Returns I | null

      The item at the peek position, or null if at EOF

      NoMoreTokensError if more input is needed and EOF not signaled