# match_registry

URL: /patitas/api/parsing/inline/match_registry/
Section: inline
Description: Match registry for emphasis delimiter tracking.

Decouples match state from token objects, enabling immutable tokens.
This is a prerequisite for using NamedTuples as inline tokens.

Thread Safety:
MatchRegistry instances are single-use per _parse_inline() call.
All state is instance-local; no shared mutable state.

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/parsing/inline/match_registry/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Finline%2Fmatch_registry%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Finline%2Fmatch_registry%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Finline%2Fmatch_registry%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Finline%2Fmatch_registry%2Findex.txt)

Module

#
`parsing.inline.match_registry`

Match registry for emphasis delimiter tracking.

Decouples match state from token objects, enabling immutable tokens.
This is a prerequisite for using NamedTuples as inline tokens.

Thread Safety:

MatchRegistry instances are single-use per _parse_inline() call.
All state is instance-local; no shared mutable state.

2Classes

## Classes

`DelimiterMatch`

3

▼

Record of a matched opener-closer pair.

Record of a matched opener-closer pair.

#### Attributes

Name
Type
Description

`opener_idx`

`int`

Index of the opener token in the token list.

`closer_idx`

`int`

Index of the closer token in the token list.

`match_count`

`int`

Number of delimiters matched (1 for emphasis, 2 for strong).

`MatchRegistry`

10

▼

External tracking for delimiter matches.

Decouples match state from token objects, enabling immuta…

External tracking for delimiter matches.

Decouples match state from token objects, enabling immutable tokens.
All delimiter matching state is tracked here instead of mutating tokens.

Usage:

```
registry = MatchRegistry()
registry.record_match(opener_idx=0, closer_idx=5, count=2)
if registry.is_active(3):
        ...
```

Complexity:

- record_match(): O(1)

- is_active(): O(1)

- deactivate(): O(1)

- remaining_count(): O(1)

- get_matches_for_opener(): O(1) amortized

#### Attributes

Name
Type
Description

`matches`

`list[DelimiterMatch (/patitas/api/parsing/inline/match_registry/#DelimiterMatch)]`

—

`consumed`

`dict[int, int]`

—

`deactivated`

`set[int]`

—

`_opener_matches_cache`

`dict[int, list[DelimiterMatch (/patitas/api/parsing/inline/match_registry/#DelimiterMatch)]]`

—

#### Methods

`record_match`

3

▼

Record a delimiter match.

`def record_match(self, opener_idx: int, closer_idx: int, count: int) -> None`

##### Parameters

Name
Type
Description

`opener_idx`
`—`

Index of the opening delimiter token.

`closer_idx`
`—`

Index of the closing delimiter token.

`count`
`—`

Number of delimiters matched (1 or 2).

`is_active`

1

`bool`

▼

Check if delimiter at idx is still active.

`def is_active(self, idx: int) -> bool`

##### Parameters

Name
Type
Description

`idx`
`—`

Token index to check.

##### Returns

`bool`

True if the delimiter is still active (not deactivated).

`deactivate`

1

▼

Mark delimiter as inactive.

`def deactivate(self, idx: int) -> None`

##### Parameters

Name
Type
Description

`idx`
`—`

Token index to deactivate.

`remaining_count`

2

`int`

▼

Get remaining delimiter count after matches.

`def remaining_count(self, idx: int, original_count: int) -> int`

##### Parameters

Name
Type
Description

`idx`
`—`

Token index to check.

`original_count`
`—`

Original delimiter count for this token.

##### Returns

`int`

Number of remaining unused delimiters.

`get_match_for_opener`

1

`DelimiterMatch (/patitas/api/parsing/inline/match_registry/#DelimiterMatch) | None`

▼

Get first match record where idx is the opener.

For nested emphasis (***text**…

`def get_match_for_opener(self, idx: int) -> DelimiterMatch | None`

Get first match record where idx is the opener.

For nested emphasis (text), use get_matches_for_opener() instead.

##### Parameters

Name
Type
Description

`idx`
`—`

Token index to check.

##### Returns

`DelimiterMatch (/patitas/api/parsing/inline/match_registry/#DelimiterMatch) | None`

First DelimiterMatch if this token is an opener, None otherwise.

`get_matches_for_opener`

1

`list[DelimiterMatch (/patitas/api/parsing/inline/match_registry/#DelimiterMatch)]`

▼

Get all match records where idx is the opener.

Used for nested emphasis (e.g.,…

`def get_matches_for_opener(self, idx: int) -> list[DelimiterMatch]`

Get all match records where idx is the opener.

Used for nested emphasis (e.g., text has 2 matches: strong and emphasis).

##### Parameters

Name
Type
Description

`idx`
`—`

Token index to check.

##### Returns

`list[DelimiterMatch (/patitas/api/parsing/inline/match_registry/#DelimiterMatch)]`

List of DelimiterMatch records, empty if not an opener.
