Source text addressed by byte offset, and the edit tree a metamutant is rendered from (design notes §10.3, §10.4).
Positions in mutants are {line, column}, 1-based, columns counted in codepoints (as
Juggernaut.Diff counts them); offset/2 turns one into a byte offset.
An edit covers the bytes from..to (end exclusive) of the source:
{:wrap, from, to, prefix, suffix, owner}: the original bytes, with the edits inside them applied, between two lists of chunks;{:replace, from, to, chunks}: the chunks instead of the bytes; edits inside are dropped;{:region, from, to, owner}: the bytes with the edits inside applied, owned byowner.
Edits must nest or be disjoint. Rendering gives chunks, {text, owner}, where the
owner says which switches a piece of output belongs to: nil (code as written),
{:group, switches} (code a site or a lifted function wraps) or {:branch, switches} (one mutant's code). spans/1 places the chunks in the output by line and
column, and blame/2 names the switches responsible for a compile diagnostic there.
Summary
Functions
The switches a diagnostic at position ({line, column} or a line) blames: the owner
of the chunk there, or for a bare line every branch on it (else every group). Empty
when the position is in code as written.
Indexes source by line.
The byte offset of {line, column}, or :error outside the text.
The owner of the chunk at {line, column}, or nil (code as written, or a bare line).
The bytes of range (a mutant location), or :error.
Renders from..to of text with edits (which must lie inside it) applied; gaps
belong to owner.
Renders the whole text with edits applied.
The bytes from..to (end exclusive).
Where each owned chunk lands in the output: start and end {line, column}.
The output text of chunks.
Types
@type edit() :: {:wrap, non_neg_integer(), non_neg_integer(), [chunk()], [chunk()], owner()} | {:replace, non_neg_integer(), non_neg_integer(), [chunk()]} | {:region, non_neg_integer(), non_neg_integer(), owner()}
@type owner() :: nil | {:group | :branch, [pos_integer()]}
@type position() :: {pos_integer(), pos_integer()}
Functions
@spec blame([span()], position() | pos_integer()) :: [pos_integer()]
The switches a diagnostic at position ({line, column} or a line) blames: the owner
of the chunk there, or for a bare line every branch on it (else every group). Empty
when the position is in code as written.
Indexes source by line.
@spec offset(t(), position()) :: {:ok, non_neg_integer()} | :error
The byte offset of {line, column}, or :error outside the text.
@spec owner_at([span()], position() | pos_integer()) :: owner()
The owner of the chunk at {line, column}, or nil (code as written, or a bare line).
@spec range_offsets(t(), %{start: position(), end: position()}) :: {:ok, {non_neg_integer(), non_neg_integer()}} | :error
The bytes of range (a mutant location), or :error.
@spec render(t(), [edit()], non_neg_integer(), non_neg_integer(), owner()) :: [ chunk() ]
Renders from..to of text with edits (which must lie inside it) applied; gaps
belong to owner.
Renders the whole text with edits applied.
@spec slice(t(), non_neg_integer(), non_neg_integer()) :: binary()
The bytes from..to (end exclusive).
Where each owned chunk lands in the output: start and end {line, column}.
The output text of chunks.