Classes
DelimiterMatch
3
▼
Record of a matched opener-closer pair.
DelimiterMatch
3
▼
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…
MatchRegistry
10
▼
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]
|
— |
consumed |
dict[int, int]
|
— |
deactivated |
set[int]
|
— |
_opener_matches_cache |
dict[int, list[DelimiterMatch]]
|
— |
Methods
record_match
3
▼
Record a delimiter match.
record_match
3
▼
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.
is_active
1
bool
▼
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.
deactivate
1
▼
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.
remaining_count
2
int
▼
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 | None
▼
Get first match record where idx is the opener.
For nested emphasis (***text**…
get_match_for_opener
1
DelimiterMatch | None
▼
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 | None
First DelimiterMatch if this token is an opener, None otherwise.
get_matches_for_opener
1
list[DelimiterMatch]
▼
Get all match records where idx is the opener.
Used for nested emphasis (e.g.,…
get_matches_for_opener
1
list[DelimiterMatch]
▼
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]
List of DelimiterMatch records, empty if not an opener.