Classes
NullFormatter
5
▼
Formatter that yields raw token values without any styling.
Thread-safe: immutable dataclass with …
NullFormatter
5
▼
Formatter that yields raw token values without any styling.
Thread-safe: immutable dataclass with no shared state.
This is the simplest possible formatter — it just concatenates token values without any transformation.
Example:
>>> from rosettes import get_lexer
>>> from rosettes.formatters import NullFormatter
>>> lexer = get_lexer("python")
>>> formatter = NullFormatter()
>>> output = formatter.format_string(lexer.tokenize("x = 1"))
>>> output
'x = 1'
Use Cases:
- Benchmarking lexer performance
- Testing tokenization correctness
- Fallback when output format is unsupported
Methods
name
0
str
▼
property
name
0
str
▼
def name(self) -> str
Returns
str
format
2
Iterator[str]
▼
Format tokens by yielding their raw values.
format
2
Iterator[str]
▼
def format(self, tokens: Iterator[Token], config: FormatConfig | None = None) -> Iterator[str]
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
Iterator[str]
format_fast
2
Iterator[str]
▼
Fast formatting — just yield raw values.
format_fast
2
Iterator[str]
▼
def format_fast(self, tokens: Iterator[tuple[TokenType, str]], config: FormatConfig | None = None) -> Iterator[str]
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
Iterator[str]
format_string
2
str
▼
Format tokens and return as a single string.
format_string
2
str
▼
def format_string(self, tokens: Iterator[Token], config: FormatConfig | None = None) -> str
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
str
format_string_fast
2
str
▼
Fast format and return as a single string.
format_string_fast
2
str
▼
def format_string_fast(self, tokens: Iterator[tuple[TokenType, str]], config: FormatConfig | None = None) -> str
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
str