Keep = signs in opcode values

An opcode's value now ends at whitespace followed by the next opcode, so
sample=A=440.wav is one value.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 18:18:40 +00:00
co-authored by Claude Sonnet 5.5
parent cf54471778
commit a5376118f9
2 changed files with 28 additions and 3 deletions
+4 -3
View File
@@ -16,9 +16,10 @@ var (
// includeRE reads an #include's quoted path.
includeRE = regexp.MustCompile(`^#include[ \t]+"([^"\r\n]*)"`)
// breakRE finds where an opcode's value ends: at a header, the next
// opcode, a comment, a directive after whitespace, or the end of the line,
// so that a value can hold spaces, as a sample's path can.
breakRE = regexp.MustCompile(`<[A-Za-z_]+>|[A-Za-z0-9_$]+=|//|/\*|\s#(?:define|include)\b|\n`)
// opcode after whitespace, a comment, a directive after whitespace, or the
// end of the line, so that a value can hold spaces and = signs, as a
// sample's path can.
breakRE = regexp.MustCompile(`<[A-Za-z_]+>|\s[A-Za-z0-9_$]+=|//|/\*|\s#(?:define|include)\b|\n`)
)
// byteOrderMark is the UTF-8 mark some editors put at the start of a file. It
+24
View File
@@ -285,3 +285,27 @@ func TestBuildVariablesWithAbsoluteSamples(t *testing.T) {
}
}
}
// TestEqualsInValue checks that a value may hold =, and that the next opcode
// starts only after whitespace.
func TestEqualsInValue(t *testing.T) {
for text, want := range map[string][]string{
"<region> sample=A=440.wav lokey=1": {"sample=A=440.wav", "lokey=1"},
"<region> sample=a b=c.wav": {"sample=a", "b=c.wav"},
"<region>sample=x.wav\n lokey=1\thikey=2": {"sample=x.wav", "lokey=1", "hikey=2"},
"label_cc1=Volume=Loud // note": {"label_cc1=Volume=Loud"},
// Without whitespace, what follows is part of the value.
"lokey=1hikey=2": {"lokey=1hikey=2"},
} {
doc := mustParse(t, text, nil)
var got []string
for _, n := range doc.Root.Nodes {
if n.Kind == KindOpcode {
got = append(got, n.Name+"="+n.Value)
}
}
if !reflect.DeepEqual(got, want) || doc.String() != text {
t.Errorf("%q: opcodes %q, want %q", text, got, want)
}
}
}