Rewrite the code comments for consistent tone and accuracy

Comments only: the tokens of every Go file are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 19:08:00 +00:00
co-authored by Claude Sonnet 5.5
parent 41f752e1c1
commit 158661eefe
27 changed files with 716 additions and 437 deletions
+40 -28
View File
@@ -1,12 +1,15 @@
// Package sfz reads, validates and writes SFZ instruments: text files that
// map samples to keys, velocities and playback settings. It handles SFZ v1 and
// v2 with the ARIA extensions as data. It doesn't play or load samples.
// Package sfz reads, validates, edits and writes SFZ instruments: text files
// that map samples to keys, velocities and playback settings. It handles SFZ v1
// and v2 with the ARIA extensions as data. It doesn't play instruments or load
// samples.
//
// A [Document] keeps a file exactly as written, including comments, spacing,
// unknown opcodes, and #define and #include directives, so that writing an
// unchanged document gives the same text back. [Document.Flatten] resolves
// directives and header inheritance into regions, and [Flat.Instrument] reads
// those into a typed model.
// unknown opcodes, and #define and #include directives, so that a document
// that hasn't been edited is written as the text it was read from.
// [Document.Flatten] resolves directives and header inheritance into regions,
// and [Flat.Instrument] reads those into a typed model. [Instrument.Apply]
// writes a change to a typed region back to the document as changes to the
// region's own opcodes.
package sfz
import (
@@ -16,14 +19,16 @@ import (
"strings"
)
// Errors that Parse and Flatten wrap.
// The errors that the package returns, directly or wrapped.
var (
// ErrInvalid is returned for text that can't be read as an instrument.
// ErrInvalid is returned for text that can't be read as an instrument, and
// for an edit or an output that can't be written as SFZ.
ErrInvalid = errors.New("invalid SFZ")
// ErrIncludeLoop is returned when a file includes itself, directly or not.
// ErrIncludeLoop is returned when a file includes itself, directly or
// through the files it includes.
ErrIncludeLoop = errors.New("include loop")
// ErrUnresolved is returned, with [IncludesFail], for an include that
// can't be read.
// ErrUnresolved is returned, with [IncludesFail], for an include that can't
// be read.
ErrUnresolved = errors.New("unresolved include")
)
@@ -68,17 +73,18 @@ func (k NodeKind) String() string {
return "text"
}
// Node is one piece of a file. The raw text of a file's nodes, in order, is
// the file's text.
// Node is one piece of a file. The raw text of a file's nodes, in order, is the
// file's text.
type Node struct {
// Kind is what the node holds, and so which of the other fields are set.
Kind NodeKind
// Raw is the node's text as written.
Raw string
// Name is a header's name without its brackets, as written, an opcode's
// name, or a define's variable name with its $.
// name, or a define's variable name with its $. Other nodes have none.
Name string
// Value is an opcode's or a define's value without surrounding
// whitespace, or an include's path as written.
// Value is an opcode's or a define's value without surrounding whitespace,
// or an include's path as written.
Value string
// Resolved is an include's path with its variables substituted, with
// forward slashes, relative to the folder of the main file.
@@ -86,20 +92,23 @@ type Node struct {
// File is the file an include reads, or nil if it wasn't read.
File *File
// line and col are where the node starts, from 1, with col in bytes, as of
// the last time the file's positions were worked out (see [File.Position]).
// the last time its file's positions were worked out (see [File.Position]).
line, col int
// idx is where the node was in its file's nodes the last time it was
// looked for, which stays close to where it is.
// idx is where the node was in its file's nodes the last time it was looked
// for. Edits move a node only a short way from there.
idx int
}
// File is one file of a document: the main file or an included one.
type File struct {
// Path is the file's path relative to the folder of the main file, with
// forward slashes. For a file read with [Parse] and no name, it is empty.
Path string
// forward slashes. For the main file of a document read with [Parse], which
// has no name, it is empty.
Path string
// Nodes are the file's nodes, in order.
Nodes []*Node
// dirty is whether edits have left the nodes' lines and columns out of date.
// dirty is whether edits have moved nodes since their lines and columns were
// last worked out.
dirty bool
}
@@ -117,7 +126,7 @@ func (f *File) String() string {
type Document struct {
// Root is the main file.
Root *File
// problems are those found while parsing.
// problems are the problems found while parsing.
problems []Problem
}
@@ -136,7 +145,8 @@ func (d *Document) WriteTo(w io.Writer) (int64, error) {
func (d *Document) String() string { return d.Root.String() }
// Files returns the main file and the files it includes, in the order they are
// read, each time they are included.
// read. A file that is included more than once is returned once for each time,
// as each is read with the variables defined at that point.
func (d *Document) Files() []*File {
var out []*File
var walk func(f *File)
@@ -176,15 +186,17 @@ func (s Severity) String() string {
return "error"
}
// Problem is something found in a document.
// Problem is something found in a document that its writer may want to fix.
type Problem struct {
// File is the path of the file, as in [File.Path].
File string
// Line and Col are where the problem is, from 1.
Line, Col int
Severity Severity
// Severity is how serious the problem is.
Severity Severity
// Code is a short stable name for the kind of problem, such as
// "include.unresolved".
Code string
Msg string
// Msg describes the problem for a person to read.
Msg string
}