Add region lookup and structural edits, and reject regions Build can't write

Instrument.Source returns the flattened region and header behind a typed
region. AddRegion, RemoveRegion and MoveRegion edit the document and read
the instrument again, restoring the document if a region would read
differently. NewRegion returns a region with the format's defaults, and
Build refuses a region that can't be read back as it is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 01:19:40 +00:00
co-authored by Claude Sonnet 5.5
parent 535856ba77
commit 49fd867283
8 changed files with 571 additions and 5 deletions
+4 -1
View File
@@ -49,6 +49,9 @@ type Flat struct {
// Headers counts, by lowercase name, the headers that aren't <control>,
// <curve>, <global>, <master>, <group> or <region>.
Headers map[string]int
// doc is the document that was flattened.
doc *Document
}
// level is how far down the header hierarchy a header is, where the opcodes of
@@ -105,7 +108,7 @@ type flattener struct {
// opcodes of its own. Comments are dropped, and an include that wasn't read is
// skipped.
func (d *Document) Flatten() *Flat {
f := &flattener{flat: &Flat{Control: Opcodes{}, Headers: map[string]int{}}}
f := &flattener{flat: &Flat{Control: Opcodes{}, Headers: map[string]int{}, doc: d}}
for i := range f.levels {
f.levels[i] = Opcodes{}
}