Classes
Parser
3
▼
Recursive descent parser for Markdown.
Consumes tokens from Lexer and builds typed AST.
A…
Parser
3
▼
Recursive descent parser for Markdown.
Consumes tokens from Lexer and builds typed AST.
Architecture:
Uses mixin inheritance to separate concerns while maintaining
a single entry point. Each mixin handles one aspect of the grammar:
-
TokenNavigationMixin: Token stream access, advance, peek -
InlineParsingMixin: Emphasis, links, code spans, etc. -
BlockParsingMixin: Lists, tables, code blocks, directives, etc.Usage:
>> parser = Parser("# Hello
World")
>> ast = parser.parse() >> ast[0]
Heading(level=1, children=(Text(content='Hello'),), ...)Thread Safety:
Parser instances are single-use and not thread-safe. Create one perparse operation. The resulting AST is immutable and thread-safe.
Methods
parse
0
Sequence[Block]
▼
Parse source into AST blocks.
**Thread Safety:**
Returns immutable AST (frozen…
parse
0
Sequence[Block]
▼
def parse(self) -> Sequence[Block]
Parse source into AST blocks.
Thread Safety: Returns immutable AST (frozen dataclasses).
Returns
Sequence[Block]
Sequence of Block nodes
Internal Methods 2 ▼
__init__
2
▼
Initialize parser with source text.
__init__
2
▼
def __init__(self, source: str, source_file: str | None = None) -> None
Parameters
| Name | Type | Description |
|---|---|---|
source |
— |
Markdown source text |
source_file |
— |
Optional source file path for error messages Default:None
|
_parse_nested_content
2
tuple[Block, ...]
▼
Parse nested content as blocks (for block quotes, list items).
Creates a sub-p…
_parse_nested_content
2
tuple[Block, ...]
▼
def _parse_nested_content(self, content: str, location) -> tuple[Block, ...]
Parse nested content as blocks (for block quotes, list items).
Creates a sub-parser to handle nested block-level content while preserving plugin settings and link reference definitions.
Parameters
| Name | Type | Description |
|---|---|---|
content |
— |
The markdown content to parse as blocks |
location |
— |
Source location for error reporting |
Returns
tuple[Block, ...]
Tuple of Block nodes