module
C0::Diff
Overview
C0DIFF parser and applier for atomic multi-file edits.
Format:
[FS]
- FS starts a new file block
- GS starts a new pattern section within a file
- US separates pattern units (anchor text ↔ replacement regions)
- SUB separates old text from new text within a replacement
- DLE escapes literal control codes
TODO Consider a "replace-all within bounded scope" mode.
Two unique sentinel anchors would define a region, and all
occurrences within that region would be replaced. Candidate
codes: SO/SI (0x0E/0x0F) — "Shift Out/In" to switch into
replace-all mode:
[GS]
- Is this too liberal? Should there be a max replacement count?
- Or is it better to generate one section per occurrence at a higher tool level, keeping the format strictly exact-match?
- Could also be useful for batch renames (variable/method renaming within a function scope).
Defined in:
c0/diff.crClass Method Summary
-
.apply(diff_buf : Bytes, files : Hash(String, String)) : Hash(String, String)
Apply a C0DIFF buffer to a hash of file contents.
-
.apply_files(diff_buf : Bytes, base_dir : String = ".") : Nil
Apply a C0DIFF buffer to files on disk.
-
.build(& : DiffBuilder -> ) : Bytes
Build a C0DIFF document.
-
.parse(buf : Bytes) : Array(FileEdit)
Parse a C0DIFF buffer into a list of file edits.
Class Method Detail
Apply a C0DIFF buffer to a hash of file contents. Returns the modified file contents. Raises on validation failure. All files are validated before any modifications (atomic semantics).
Apply a C0DIFF buffer to files on disk. Validates all files before writing any (atomic semantics).
Parse a C0DIFF buffer into a list of file edits.