Skip to content

vllm.parser.engine.incremental_lexer

Incremental text lexer that converts text chunks into terminal tokens, with prefix-match buffering for ambiguous boundaries.

Classes:

  • IncrementalLexer –

    Converts streaming text into terminal tokens.

  • LexerShape –

    Immutable pre-computed data derived from terminal definitions.

IncrementalLexer

Converts streaming text into terminal tokens.

The key feature is prefix-match buffering: when the text in the buffer could be the start of a multi-character terminal (e.g. "<tool_" that could become "<tool_call>"), the lexer holds the text rather than emitting it. When the next chunk arrives, it either completes the terminal or flushes the buffered text as content.

Terminals are tried in priority order (literals first, then by descending priority, then by pattern length).

LexerShape

Immutable pre-computed data derived from terminal definitions.

Created once per ParserEngineConfig and shared across all IncrementalLexer instances that use the same config.