Classes
TokenType
0
▼
Token types produced by the lexer.
Organized by category for clarity:
- Document structure (EOF, B…
TokenType
0
▼
Token types produced by the lexer.
Organized by category for clarity:
- Document structure (EOF, BLANK_LINE)
- Block elements (headings, code blocks, quotes, lists)
- Inline elements (text, emphasis, links, images)
- Directives and roles
Token
15
▼
A token produced by the lexer.
Tokens are the atomic units passed from lexer to parser.
Each token…
Token
15
▼
A token produced by the lexer.
Tokens are the atomic units passed from lexer to parser. Each token has a type, string value, and source location (lazy).
Performance:
SourceLocation is created lazily on first access to.location.
This avoids allocation overhead for tokens whose location is never read.
Thread Safety: Frozen dataclass ensures immutability for safe sharing. The lazy cache uses idempotent write (safe for concurrent access).
Attributes
| Name | Type | Description |
|---|---|---|
type |
TokenType
|
The token type (from TokenType enum) |
value |
str
|
The raw string value from source |
_lineno |
int
|
Start line number (1-indexed) |
_col |
int
|
Start column offset (1-indexed) |
_start_offset |
int
|
Absolute start position in source |
_end_offset |
int
|
Absolute end position in source |
line_indent |
int
|
Pre-computed indent level of the line (spaces, tabs expand to 4). Set by lexer at token creation; -1 if not computed. |
_end_lineno |
int | None
|
End line number (for multi-line tokens) |
_end_col |
int | None
|
End column offset |
_source_file |
str | None
|
Optional source file path |
_location_cache |
SourceLocation | None
|
— |
Methods
location
0
SourceLocation
▼
Get source location (lazily created and cached).
property
location
0
SourceLocation
▼
def location(self) -> SourceLocation
Returns
SourceLocation
SourceLocation object for this token.
lineno
0
int
▼
Line number (convenience accessor).
property
lineno
0
int
▼
def lineno(self) -> int
Returns
int
col
0
int
▼
Column offset (convenience accessor).
property
col
0
int
▼
def col(self) -> int
Returns
int
Internal Methods 1 ▼
__repr__
0
str
▼
Compact repr for debugging.
__repr__
0
str
▼
def __repr__(self) -> str
Returns
str