Module

parsing.inline.core

Core inline parsing for Patitas parser.

Provides the main inline tokenization and AST building logic.

Thread Safety:

All methods are stateless or use instance-local state only. Safe for concurrent use when each parser instance is used by one thread.

Classes

InlineParsingCoreMixin 9
Core inline parsing methods. Required Host Attributes: - _math_enabled: bool - _strikethro…

Core inline parsing methods.

Required Host Attributes:

  • _math_enabled: bool
  • _strikethrough_enabled: bool
  • _footnotes_enabled: bool
  • _link_refs: dict[str, tuple[str, str]]

Required Host Methods (from other mixins):

  • _is_left_flanking(before, after, delim) -> bool
  • _is_right_flanking(before, after, delim) -> bool
  • _is_punctuation(char) -> bool
  • _process_emphasis(tokens, registry) -> MatchRegistry
  • _try_parse_footnote_ref(text, pos, location) -> tuple | None
  • _try_parse_link(text, pos, location) -> tuple | None
  • _try_parse_image(text, pos, location) -> tuple | None
  • _try_parse_autolink(text, pos, location) -> tuple | None
  • _try_parse_html_inline(text, pos, location) -> tuple | None
  • _try_parse_role(text, pos, location) -> tuple | None
  • _try_parse_math(text, pos, location) -> tuple | None

Attributes

Name Type Description
_math_enabled bool
_strikethrough_enabled bool
_footnotes_enabled bool
_link_refs dict[str, tuple[str, str]]

Methods

Internal Methods 5
_parse_inline 2 tuple[Inline, ...]
Parse inline content using CommonMark delimiter stack algorithm. This implemen…
def _parse_inline(self, text: str, location: SourceLocation) -> tuple[Inline, ...]

Parse inline content using CommonMark delimiter stack algorithm.

This implements the proper flanking delimiter rules for emphasis/strong. See: https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis

Parameters
Name Type Description
text
location
Returns
tuple[Inline, ...]
_tokenize_inline 2 list[InlineToken]
Tokenize inline content into typed token objects. Returns list of InlineToken …
def _tokenize_inline(self, text: str, location: SourceLocation) -> list[InlineToken]

Tokenize inline content into typed token objects.

Returns list of InlineToken NamedTuples for type safety and performance.

Parameters
Name Type Description
text
location
Returns
list[InlineToken]
_find_code_span_close 3 int
Find closing backticks for code span.
def _find_code_span_close(self, text: str, start: int, backtick_count: int) -> int
Parameters
Name Type Description
text
start
backtick_count
Returns
int
_try_parse_entity 2 tuple[str, int] | None
Try to parse an HTML entity reference at position. CommonMark 6.2: Entity and …
def _try_parse_entity(self, text: str, pos: int) -> tuple[str, int] | None

Try to parse an HTML entity reference at position.

CommonMark 6.2: Entity and numeric character references.

Supports:

  • Named entities: &   © etc.
  • Decimal: &#digits; (1-7 digits, value <= 0x10FFFF)
  • Hexadecimal: &#xhex; or &#Xhex; (1-6 hex digits)
Parameters
Name Type Description
text
pos
Returns
tuple[str, int] | None Tuple of (decoded_char, new_position) if valid, None otherwise.
_build_inline_ast 4 tuple[Inline, ...]
Build AST from processed tokens using match registry. Uses pattern matching fo…
def _build_inline_ast(self, tokens: list[InlineToken], registry: MatchRegistry, location: SourceLocation, base_idx: int = 0) -> tuple[Inline, ...]

Build AST from processed tokens using match registry.

Uses pattern matching for type-safe token dispatch.

Parameters
Name Type Description
tokens

List of InlineToken NamedTuples from _tokenize_inline().

registry

MatchRegistry containing delimiter matches.

location

Source location for node creation.

base_idx

Offset to add to local indices when looking up registry. Used for recursive calls on token slices.

Default:0
Returns
tuple[Inline, ...] Tuple of Inline nodes.