Pentiment.Span.Position (pentiment v0.1.5)
A span defined by line and column positions.
This representation matches Elixir's AST metadata format, making it ideal for compile-time macros and DSLs. Lines are 1-indexed, columns are 1-indexed.
Fields
:start_line- The starting line number (1-indexed, required):start_column- The starting column number (1-indexed, optional, defaults to 1):end_line- The ending line number (optional, defaults to start_line):end_column- The ending column number (optional)
When end_line and end_column are nil, the span represents a single point.
Summary
Functions
Creates a new position span.
Returns true if this span represents a single point (no end position).
Returns the span as a range on a single line, or nil if it spans multiple lines.
Types
@type t() :: %Pentiment.Span.Position{ end_column: pos_integer() | nil, end_line: pos_integer() | nil, start_column: pos_integer(), start_line: pos_integer() }
Functions
@spec new(pos_integer(), pos_integer(), pos_integer() | nil, pos_integer() | nil) :: t()
Creates a new position span.
Examples
# Full range
iex> Pentiment.Span.Position.new(5, 10, 5, 20)
%Pentiment.Span.Position{start_line: 5, start_column: 10, end_line: 5, end_column: 20}
# Single point
iex> Pentiment.Span.Position.new(5, 10)
%Pentiment.Span.Position{start_line: 5, start_column: 10, end_line: nil, end_column: nil}
Returns true if this span represents a single point (no end position).
@spec single_line_range(t()) :: {pos_integer(), pos_integer(), pos_integer()} | nil
Returns the span as a range on a single line, or nil if it spans multiple lines.
Returns {line, start_col, end_col} if on a single line, nil otherwise.