Pentiment.Spannable protocol (pentiment v0.1.5)
Protocol for converting values to spans.
This protocol allows any type to be used as a span source. Built-in implementations are provided for:
Pentiment.Span.ByteandPentiment.Span.Positionstructs (identity)- Tuples in common formats (see below)
- Ranges for byte spans
Tuple Formats
The following tuple formats are supported:
{start, length}- Byte offset span (2-tuple of integers){line, column}- Single-point position span (when both are positive){start_line, start_col, end_line, end_col}- Position range (4-tuple)
Note: {start, length} and {line, column} are ambiguous for 2-tuples.
By default, 2-tuples are interpreted as byte spans. Use Pentiment.Span.position/2
explicitly for line/column positions, or implement this protocol for your own types.
Custom Implementations
You can implement this protocol for your own types:
defimpl Pentiment.Spannable, for: MyApp.Token do
def to_span(%MyApp.Token{line: l, col: c, length: len}) do
Pentiment.Span.position(l, c, l, c + len)
end
end
Summary
Functions
Converts the value to a Pentiment.Span.t().
Types
@type t() :: term()
All the types that implement this protocol.
Functions
@spec to_span(t()) :: Pentiment.Span.t()
Converts the value to a Pentiment.Span.t().
Returns a Pentiment.Span.Byte or Pentiment.Span.Position struct.