Classes
LexerSpec
3
▼
Specification for lazy-loading a lexer.
Used internally by the registry to defer module imports un…
LexerSpec
3
▼
Specification for lazy-loading a lexer.
Used internally by the registry to defer module imports until first use.
This keepsimport rosettesfast (~5ms) even with 50+ language support.
Attributes
| Name | Type | Description |
|---|---|---|
module |
str
|
Full module path (e.g., 'rosettes.lexers.python_sm'). |
class_name |
str
|
Name of the lexer class in the module. |
aliases |
tuple[str, ...]
|
Alternative names for lookup (e.g., 'py' for 'python'). |
Functions
_normalize_name
1
str
▼
Normalize a language name to its canonical form. O(1) lookup.
_normalize_name
1
str
▼
def _normalize_name(name: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
name |
str |
Language name or alias. |
Returns
str
get_lexer
1
StateMachineLexer
▼
Get a lexer instance by name or alias.
All lexers are hand-written state machi…
get_lexer
1
StateMachineLexer
▼
def get_lexer(name: str) -> StateMachineLexer
Get a lexer instance by name or alias.
All lexers are hand-written state machines with O(n) guaranteed performance and zero ReDoS vulnerability.
Uses functools.cache for thread-safe memoization. Lexers are loaded lazily on first access.
Parameters
| Name | Type | Description |
|---|---|---|
name |
str |
Language name or alias (e.g., 'python', 'py', 'js'). |
Returns
StateMachineLexer
_get_lexer_by_canonical
1
StateMachineLexer
▼
Internal cached loader - keyed by canonical name.
_get_lexer_by_canonical
1
StateMachineLexer
▼
def _get_lexer_by_canonical(canonical: str) -> StateMachineLexer
Parameters
| Name | Type | Description |
|---|---|---|
canonical |
str |
Returns
StateMachineLexer
list_languages
0
list[str]
▼
List all supported language names. O(1).
list_languages
0
list[str]
▼
def list_languages() -> list[str]
Returns
list[str]
supports_language
1
bool
▼
Check if a language is supported.
supports_language
1
bool
▼
def supports_language(name: str) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
name |
str |
Language name or alias. |
Returns
bool