Module

location

Source location tracking for error messages and debugging.

Provides SourceLocation dataclass for tracking positions in source text. Used throughout Patitas for error messages, AST nodes, and debugging.

Thread Safety:

SourceLocation is frozen (immutable) and safe to share across threads.

Classes

SourceLocation 10
Source location for error messages and debugging. Tracks both position in source and optionally th…

Source location for error messages and debugging.

Tracks both position in source and optionally the source file path for multi-file documentation builds.

All positions are 1-indexed (lineno and col_offset start at 1).

Thread Safety: Frozen dataclass ensures immutability for safe sharing.

Attributes

Name Type Description
lineno int

Starting line number (1-indexed)

col_offset int

Starting column offset (1-indexed)

offset int
end_offset int
end_lineno int | None

Ending line number (optional)

end_col_offset int | None

Ending column offset (optional)

source_file str | None

Source file path (optional, for multi-file builds)

Methods

span_to 1 SourceLocation
Create a new location spanning from this location to end.
def span_to(self, end: SourceLocation) -> SourceLocation
Parameters
Name Type Description
end

Ending location

Returns
SourceLocation New SourceLocation with this start and end's end positions
unknown 0 SourceLocation
Create an unknown/placeholder location. Use for AST nodes created syntheticall…
classmethod
def unknown(cls) -> SourceLocation

Create an unknown/placeholder location.

Use for AST nodes created synthetically or when location is unavailable.

Returns
SourceLocation
Internal Methods 1
__str__ 0 str
Format location for error messages.
def __str__(self) -> str
Returns
str Formatted string like "file.md:10:5" or "10:5"