pub struct ProvenanceBuilder { /* private fields */ }Expand description
Builds a SourceInfo by tiling a decoded string’s content against
the source bytes it came from.
Construct with ProvenanceBuilder::in_file or
ProvenanceBuilder::in_parent, describe the decode with
verbatim and replacement
calls in content order, then call finish.
Implementations§
Source§impl ProvenanceBuilder
impl ProvenanceBuilder
Sourcepub fn in_file(file_id: FileId, anchor: usize) -> Self
pub fn in_file(file_id: FileId, anchor: usize) -> Self
Start a builder whose pieces are Original ranges directly in
file_id.
anchor is the scalar’s span start; finish() uses it when the
piece list ends up empty, since an empty piece list has no source
range to infer a position from.
Sourcepub fn in_parent(parent: SourceInfo, anchor: usize) -> Self
pub fn in_parent(parent: SourceInfo, anchor: usize) -> Self
Start a builder whose pieces are Substring ranges over parent.
parent may itself be a Concat (e.g. q2’s cell-options path
hands quarto_yaml::parse_with_parent a SourceInfo::concat(..)).
The builder never resolves absolute positions out of parent —
see finish — so this is safe regardless of what
shape parent is.
anchor is the scalar’s span start, in parent’s coordinate
space; see in_file for why it is needed.
Sourcepub fn verbatim(&mut self, src_range: Range<usize>)
pub fn verbatim(&mut self, src_range: Range<usize>)
Record src_range.len() source bytes decoding to that many
content bytes, unchanged.
This is a caller assertion: the builder takes byte-identity on
trust and never re-derives it from lengths. Adjacent verbatim
calls whose source ranges abut are merged; a replacement never
coalesces with anything, however convenient its length.
Sourcepub fn replacement(&mut self, src_range: Range<usize>, out_len: usize)
pub fn replacement(&mut self, src_range: Range<usize>, out_len: usize)
Record src_range.len() source bytes decoding to out_len
content bytes, where source and content are not asserted to be
byte-identical.
out_len == 0 is a deletion. An empty src_range with
out_len > 0 is synthesis: content with no corresponding source
byte (e.g. a chomped block scalar’s trailing newline at EOF).
Sourcepub fn finish(self) -> SourceInfo
pub fn finish(self) -> SourceInfo
Emit the tiled SourceInfo: Original/Substring if the piece
list collapsed to exactly one verbatim piece (or is empty), a
Concat otherwise.
This never calls resolve_byte_range — on the parent or on
anything derived from it — because in_parent’s parent may be a
Concat, for which that accessor returns None. Positions are
always built from the piece’s own src_range, never resolved.