patch

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package patch composes immutable byte edits while retaining original-source correspondence. It assigns no YAML, comment or graph meaning to a footprint.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLimit    = errors.NewSentinel("yamldoc.patch.limit", "source patch resource limit exceeded")
	ErrTable    = errors.NewSentinel("yamldoc.patch.table", "invalid source patch table")
	ErrMismatch = errors.NewSentinel("yamldoc.patch.mismatch", "candidate bytes do not match the declared source patch plan")
)
View Source
var ErrReuse = errors.NewSentinel("yamldoc.patch.reuse", "source rewrite repeats retained bytes")

Functions

func New

func New(original []byte, limits Limits) (*Table, Stats, error)

Types

type Correspondence

type Correspondence struct{ Original, Output source.Span }

type Fault

type Fault struct {
	Output, Original source.Span
	HasOriginal      bool
}

func (*Fault) Error

func (*Fault) Error() string

func (*Fault) Unwrap

func (*Fault) Unwrap() error

type Limits

type Limits struct{ Bytes, Pieces, Work int }

type Mark

type Mark struct {
	// contains filtered or unexported fields
}

Mark identifies a nonempty byte occurrence in one source lineage. It follows retained pieces, including inserted bytes, without treating equal copied bytes as the same occurrence. It carries no YAML, comment ownership or view lifetime. A mark may retain the backing storage of generated bytes that it references.

type Part

type Part struct {
	// contains filtered or unexported fields
}

Part selects bytes to retain from the current table or new bytes to insert. Constructors store input until synchronous Rewrite admission copies new bytes.

func Insert

func Insert(bytes []byte) Part

func Retain

func Retain(span source.Span) Part

type Stats

type Stats struct{ Work, BytesCopied, Pieces int }

type Table

type Table struct {
	// contains filtered or unexported fields
}

func (*Table) Correspondence

func (t *Table) Correspondence(limits Limits) ([]Correspondence, Stats, error)

func (*Table) Len

func (t *Table) Len() int

func (*Table) Locate

func (t *Table) Locate(mark Mark, limits Limits) (source.Span, bool, Stats, error)

func (*Table) OriginalSpan

func (t *Table) OriginalSpan(span source.Span, limits Limits) (source.Span, bool, Stats, error)

OriginalSpan maps a contiguous retained source occurrence into the current output. Equal replacement bytes are not proof that the original survived.

func (*Table) Preserved

func (t *Table) Preserved(span source.Span, limits Limits) (bool, Stats, error)

Preserved requires one contiguous original piece to cover the entire span. Merely retaining its bytes on both sides of an insertion is insufficient.

func (*Table) Render

func (t *Table) Render(limits Limits) ([]byte, Stats, error)

func (*Table) Replace

func (t *Table) Replace(span source.Span, replacement []byte, limits Limits) (*Table, Stats, error)

func (*Table) Rewrite

func (t *Table) Rewrite(span source.Span, parts []Part, limits Limits) (*Table, Stats, error)

Rewrite replaces a current source window with ordered parts. Retained spans must lie inside that window and may not overlap: relocation preserves identity, while explicit byte insertion creates a new occurrence even for equal bytes. Bytes outside the window are retained automatically. No YAML meaning is assigned.

func (*Table) Track

func (t *Table) Track(span source.Span, limits Limits) (Mark, Stats, error)

func (*Table) Verify

func (t *Table) Verify(candidate []byte, limits Limits) (Stats, error)

Verify checks both untouched correspondence and explicitly inserted bytes. It does not parse YAML or claim semantic correctness of the replacement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL