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:
@@ -2,14 +2,16 @@ package sfz
|
||||
|
||||
import "strings"
|
||||
|
||||
// defines are the variables defined so far, by name with their $.
|
||||
// defines are the variables defined so far, by name with their $, with their
|
||||
// values as they stand after the variables in them are replaced.
|
||||
type defines map[string]string
|
||||
|
||||
// set gives a variable the value, which has its own variables replaced
|
||||
// set gives a variable a value, which has had its own variables replaced
|
||||
// already.
|
||||
func (d defines) set(name, value string) { d[name] = strings.TrimSpace(value) }
|
||||
|
||||
// define reads a #define node, replacing the variables in its value.
|
||||
// define sets the variable of a #define node, replacing the variables in its
|
||||
// value.
|
||||
func (d defines) define(n *Node) { d.set(n.Name, substitute(d, n.Value)) }
|
||||
|
||||
// undefined returns the variables in text that haven't been defined.
|
||||
@@ -23,29 +25,30 @@ func (d defines) undefined(text string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// visitor reads a document's nodes as [walk] meets them.
|
||||
// visitor is what [walk] tells about the nodes of a document, in order.
|
||||
type visitor interface {
|
||||
// define is called for a #define before its variable is set.
|
||||
// define is called for a #define, before its variable is set.
|
||||
define(f *File, n *Node)
|
||||
// include is called for an #include before the file it read is walked.
|
||||
// include is called for an #include, before the file it read is walked.
|
||||
include(f *File, n *Node)
|
||||
// variables is called for an opcode or text node that uses variables,
|
||||
// before what it makes is read.
|
||||
// before the headers, opcodes and text that it makes are told of.
|
||||
variables(f *File, n *Node)
|
||||
// header is called for a header. Variable is whether a variable's value
|
||||
// made it, in which case n is the node that uses the variable.
|
||||
// header is called for a header. Variable is whether the value of a
|
||||
// variable made it, in which case n is the node that uses the variable.
|
||||
header(f *File, n *Node, name string, variable bool)
|
||||
// opcode is called for an opcode. Variable is as for header.
|
||||
// opcode is called for an opcode. Variable is as for header, and n is
|
||||
// likewise the node that uses the variable.
|
||||
opcode(f *File, n *Node, name, value string, variable bool)
|
||||
// text is called for text that isn't an opcode or header, which n is or
|
||||
// holds.
|
||||
// text is called for text that isn't an opcode or a header, which is n or
|
||||
// is made by n.
|
||||
text(f *File, n *Node, raw string)
|
||||
}
|
||||
|
||||
// walk reads the nodes of a file in order, and of the files it includes where
|
||||
// they stand, with the variables as they are at each node. Text that uses a
|
||||
// variable is read again with the variable replaced, as the value can hold
|
||||
// opcodes and headers.
|
||||
// walk tells v of the nodes of a file in order, and of the files it includes
|
||||
// where the includes stand, with defs holding the variables as they are at each
|
||||
// node. A node that uses a variable is lexed again with its variables replaced,
|
||||
// because a value can hold opcodes and headers.
|
||||
func walk(f *File, defs defines, v visitor) {
|
||||
for _, n := range f.Nodes {
|
||||
switch n.Kind {
|
||||
|
||||
Reference in New Issue
Block a user