Documentation
¶
Overview ¶
Package textedit provides byte spans and edits for source-preserving transformations.
Spans refer to the original source buffer. Apply checks edit bounds and overlap before producing replacement bytes, and Position maps byte offsets to line and column diagnostics. Language-specific parsing and edit intent belong to callers.
Index ¶
- Constants
- func Apply(src []byte, edits []Edit) ([]byte, error)
- func Changed(n, m int, same func(i, j int) bool) (gone, come []int)
- func Match(n, m int, same func(i, j int) bool) (from []int, within bool)
- func Position(src []byte, offset int) (line, col int)
- func Unmatched(n int, from []int) []int
- type Edit
- type EditError
- type EditErrorType
- type Span
Constants ¶
const MatchBudget = 4_000_000
MatchBudget is the most cells Match's table may take between two sequences' common ends: 4,000,000 int32s, 16 MB. Past it, the middle is all changed, which callers read as a change to hold for, never as sameness.
Variables ¶
This section is empty.
Functions ¶
func Changed ¶ added in v0.9.0
Changed are what a Match of a's n and b's m elements leaves unpaired: gone, the indices of a that b keeps none of, and come, the indices of b that keep none of a. The one reading of a line comparison's two sides, where Portfiles' and CMake files' comparisons each derived it.
func Match ¶ added in v0.7.0
Match pairs two sequences' elements, a's n and b's m, by a longest common subsequence after their common start and end, same saying whether a[i] and b[j] are equal: from[j] is the index in a that b[j] keeps, or -1 for one b adds or alters. Where the middle's table would pass MatchBudget, every element of it is unmatched and within is false: the comparison's memory stays bounded, its answer "changed" (Codex's review of 8e314b96, finding 5, where a license comparison took 51 MB for a 25 KB pair). It's the one way the comparisons of lines and words match, each mapping the pairs to its own answer.
Types ¶
type EditError ¶
type EditError struct {
Type EditErrorType
Edit Edit
}
type EditErrorType ¶
type EditErrorType int
const ( ReversedSpan EditErrorType = iota OutOfBounds Overlap )
func (EditErrorType) String ¶
func (t EditErrorType) String() string