Module

parsing.ultra_fast

Ultra-fast parser for simple documents.

Handles documents with only PARAGRAPH_LINE and BLANK_LINE tokens. Bypasses all block-level decision logic for maximum speed.

This covers 47.5% of CommonMark test cases and likely 60-80% of real-world documents (prose, comments, simple READMEs).

Functions

parse_ultra_simple 2 tuple[Block, ...]
Parse document with only paragraphs and blank lines. Ultra-fast path: No block…
def parse_ultra_simple(tokens: list[Token], parse_inline_fn: Callable[[str, SourceLocation], tuple[Inline, ...]]) -> tuple[Block, ...]

Parse document with only paragraphs and blank lines.

Ultra-fast path: No block-level decisions, no container tracking, no indentation analysis. Just split on blank lines and parse inline.

Parameters
Name Type Description
tokens list[Token]

Token list (must contain only PARAGRAPH_LINE, BLANK_LINE, EOF)

parse_inline_fn Callable[[str, SourceLocation], tuple[Inline, ...]]

Function to parse inline content

Returns
tuple[Block, ...]
can_use_ultra_fast 2 bool
Check if document qualifies for ultra-fast path. O(n) check, but very cheap pe…
def can_use_ultra_fast(tokens: list[Token], *, tables_enabled: bool = False) -> bool

Check if document qualifies for ultra-fast path.

O(n) check, but very cheap per-token (just type comparison).

Parameters
Name Type Description
tokens list[Token]

Token list from lexer

tables_enabled bool

Whether GFM table parsing is enabled. When True, any paragraph line containing a pipe is treated as a potential table and disqualifies the document (GFM tables need not have outer pipes, so thestartswith("|")heuristic alone is insufficient).

Default:False
Returns
bool