Pentiment.Span.Byte (pentiment v0.1.5)
A span defined by byte offset and length.
This representation is common in parsers (like nimble_parsec) where positions are tracked as byte offsets into the source text.
Fields
:start- The starting byte offset (0-indexed):length- The number of bytes in the span (minimum 1)
Summary
Functions
Creates a new byte span.
Resolves a byte span against source content, returning a Position span.
Types
@type t() :: %Pentiment.Span.Byte{length: pos_integer(), start: non_neg_integer()}
Functions
@spec new(non_neg_integer(), pos_integer()) :: t()
Creates a new byte span.
Examples
iex> Pentiment.Span.Byte.new(42, 10)
%Pentiment.Span.Byte{start: 42, length: 10}
@spec resolve(t(), Pentiment.Source.t() | nil) :: Pentiment.Span.Position.t()
Resolves a byte span against source content, returning a Position span.
Converts byte offsets to line/column positions using the source content. Returns a Position span covering the byte range, or falls back to a point span at line 1, column 1 if the source is nil or offsets are invalid.
Examples
iex> source = Pentiment.Source.from_string("test", "hello world")
iex> byte_span = Pentiment.Span.Byte.new(6, 5)
iex> Pentiment.Span.Byte.resolve(byte_span, source)
%Pentiment.Span.Position{start_line: 1, start_column: 7, end_line: 1, end_column: 12}