Buffer all input tokens but do on-demand fetching of new tokens from lexer. Useful when the parser or lexer has to set context/mode info before proper lexing of future tokens. The ST template parser needs this, for example, because it has to constantly flip back and forth between inside/output templates. E.g., <names:{hi, <it>}> has to parse names as part of an expression but "hi, <it>" as a nested template.

You can't use this stream if you pass whitespace or other off-channel tokens to the parser. The stream can't ignore off-channel tokens. (UnbufferedTokenStream is the same way.)

This is not a subclass of UnbufferedTokenStream because I don't want to confuse small moving window of tokens it uses for the full buffer.

Hierarchy

Implements

Index

Constructors

constructor

Properties

Protected _p

_p: number = -1

The index into the tokens list of the current token (next token to consume). tokens[p] should be LT(1). p=-1 indicates need to initialize with first token. The ctor doesn't get a token. First call to LT(1) or whatever gets the first token and sets p=0;

_tokens

_tokens: List<IToken> = new List<IToken>(100)

Record every single token pulled from the source so we can reproduce chunks of it later. The buffer in LookaheadStream overlaps sometimes as its moving window moves through the input. This list captures everything so we can access complete input text.

maxLookBehind

maxLookBehind: number = Number.MAX_VALUE

range

range: number = 0

How deep have we gone?

Accessors

count

  • get count(): number
  • Returns number

index

  • get index(): number
  • Returns number

lastRealToken

lastToken

sourceName

  • get sourceName(): string
  • Returns string

tokenSource

Methods

consume

  • consume(): void
  • Move the input pointer to the next incoming token. The stream must become active with LT(1) available. consume() simply moves the input pointer so that LT(1) points at the next input symbol. Consume at least one token.

    Walk past any token not on the channel the parser is listening to.

    Returns void

Protected fetch

  • fetch(n: number): void
  • add n elements to buffer

    Parameters

    • n: number

    Returns void

fill

  • fill(): void
  • Returns void

get

getTokens

  • Given a start and stop index, return a List of all tokens in the token type BitSet. Return null if no tokens were found. This method looks at both on and off channel tokens.

    Parameters

    • start: number
    • stop: number
    • types: BitSet

    Returns List<IToken>

implements

  • implements(): any[]
  • Returns any[]

la

  • la(i: number): number
  • Parameters

    • i: number

    Returns number

Protected lb

  • Parameters

    • k: number

    Returns IToken

lt

mark

  • mark(): number

release

  • release(marker: number): void

reset

  • reset(): void
  • Returns void

rewind

  • rewind(marker?: number): void
  • Parameters

    • Default value marker: number = this._lastMarker

    Returns void

seek

  • seek(index: number): void

Protected setup

  • setup(): void
  • Returns void

Protected sync

  • sync(i: number): void
  • Make sure index i in tokens has a token.

    Parameters

    • i: number

    Returns void

toString

  • toString(): string
  • Returns string

toString2

  • toString2(start: number, stop: number): string
  • Parameters

    • start: number
    • stop: number

    Returns string

Generated using TypeDoc