Module

parsing.protocols

Protocols defining the parser mixin contracts.

These protocols formalize the implicit contracts between parser mixins. Each mixin documents "Required Host Attributes/Methods" in its docstring; this module turns those requirements into type-checkable Protocol classes.

Usage:

Mixin methods that call across mixin boundaries can annotate `self`
as the protocol they require::

    def _parse_block(self: ParserHost) -> Block | None:
        token = self._current  # type-checked via ParserHost
        ...

Type checkers (ty) will verify that the concrete Parser class
satisfies all protocol requirements at composition time.

Thread Safety:

Protocols are purely structural — no runtime overhead.

Classes

TokenNavHost 4
Contract for token stream navigation. Provided by: TokenNavigationMixin Required by: BlockParsingC…

Contract for token stream navigation.

Provided by: TokenNavigationMixin Required by: BlockParsingCoreMixin, ListParsingMixin, InlineParsingCoreMixin

Attributes

Name Type Description
_tokens Sequence[Token]
_pos int
_current Token | None
_source str
InlineParsingHost 0
Contract for inline content parsing. Provided by: InlineParsingMixin (composed from core + emphasi…

Contract for inline content parsing.

Provided by: InlineParsingMixin (composed from core + emphasis + links + special) Required by: BlockParsingCoreMixin, ListParsingMixin

BlockParsingHost 0
Contract for block-level parsing. Provided by: BlockParsingMixin (composed from core + list + tabl…

Contract for block-level parsing.

Provided by: BlockParsingMixin (composed from core + list + table + directive + footnote) Required by: ListParsingMixin (calls _parse_block for nested content)

ParserHost 3
Full parser contract combining all mixin requirements. The concrete Parser class must satisfy this…

Full parser contract combining all mixin requirements.

The concrete Parser class must satisfy this protocol. Any class that composes TokenNavigationMixin + InlineParsingMixin + BlockParsingMixin and provides the required instance attributes will satisfy this protocol.

Required instance attributes (set in init): _source: str — original source text _tokens: Sequence[Token] — token stream from Lexer _pos: int — current position in token stream _current: Token | None — current token (or None at end) _containers: ContainerStack — nesting context tracker _link_refs: dict[str, tuple[str, str]] — link reference definitions _allow_setext_headings: bool — setext heading control

Attributes

Name Type Description
_containers ContainerStack
_link_refs dict[str, tuple[str, str]]
_allow_setext_headings bool