Classes
RosettesDelegate
2
▼
LexerDelegate implementation using rosettes.
Thread-safe: All state is local to method calls.
Desi…
RosettesDelegate
2
▼
LexerDelegate implementation using rosettes.
Thread-safe: All state is local to method calls. Designed for Python 3.14t free-threading.
This class bridges markdown parsers (like Patitas) to Rosettes syntax highlighting, enabling zero-copy lexer handoff.
Methods
tokenize_range
4
Iterator[Token]
▼
Tokenize a range of source code using rosettes state-machine lexer.
This is th…
tokenize_range
4
Iterator[Token]
▼
def tokenize_range(self, source: str, start: int, end: int, language: str) -> Iterator[Token]
Tokenize a range of source code using rosettes state-machine lexer.
This is the core ZCLH method: the source string is passed by reference, and only the (start, end) range is tokenized. No substring allocation.
Performance: O(end - start) guaranteed. Zero allocations for code content. The lexer reads characters directly from source[start:end].
Parameters
| Name | Type | Description |
|---|---|---|
source |
— |
The complete source string (not just the code block). |
start |
— |
Starting index of the code block in source. |
end |
— |
Ending index (exclusive) of the code block. |
language |
— |
Language name or alias (e.g., 'python', 'js'). |
Returns
Iterator[Token]
supports_language
1
bool
▼
Check if rosettes supports the given language.
Use this before calling tokeniz…
supports_language
1
bool
▼
def supports_language(self, language: str) -> bool
Check if rosettes supports the given language.
Use this before calling tokenize_range() to handle unsupported languages gracefully (e.g., fall back to plain text).
Parameters
| Name | Type | Description |
|---|---|---|
language |
— |
Language name or alias to check. |
Returns
bool
True if the language is supported, False otherwise.