refactor(go4k): Rename DeserializeAsm & SerializeAsm to ParseAsm & FormatAsm

Following the naming in strconv.
This commit is contained in:
Veikko Sariola 2020-12-07 11:14:46 +02:00
parent c75e54212b
commit fee637b02a
3 changed files with 10 additions and 10 deletions

View File

@ -8,7 +8,7 @@ import (
"strings"
)
func DeserializeAsm(asmcode string) (*Song, error) {
func ParseAsm(asmcode string) (*Song, error) {
paramReg, err := regexp.Compile(`(?:([a-zA-Z]\w*)\s*\(\s*([0-9]+)\s*\)|([0-9]+))`) // matches FOO(42), groups "FOO" and "42" OR just numbers
if err != nil {
return nil, fmt.Errorf("error compiling paramReg: %v", err)
@ -89,7 +89,7 @@ func DeserializeAsm(asmcode string) (*Song, error) {
return &song, nil
}
func SerializeAsm(song *Song) (string, error) {
func FormatAsm(song *Song) (string, error) {
paramorder := map[string][]string{
"add": []string{"stereo"},
"addp": []string{"stereo"},
@ -280,7 +280,7 @@ func SerializeAsm(song *Song) (string, error) {
return ret, nil
}
func ExportCHeader(song *Song, maxSamples int) string {
func CHeader(song *Song, maxSamples int) string {
template :=
`// auto-generated by Sointu, editing not recommended
#ifndef SU_RENDER_H

View File

@ -37,7 +37,7 @@ func TestAllAsmFiles(t *testing.T) {
if err != nil {
t.Fatalf("cannot read the .asm file: %v", filename)
}
song, err := go4k.DeserializeAsm(string(asmcode))
song, err := go4k.ParseAsm(string(asmcode))
if err != nil {
t.Fatalf("could not parse the .asm file: %v", err)
}
@ -100,15 +100,15 @@ func TestSerializingAllAsmFiles(t *testing.T) {
if err != nil {
t.Fatalf("cannot read the .asm file: %v", filename)
}
song, err := go4k.DeserializeAsm(string(asmcode)) // read the asm
song, err := go4k.ParseAsm(string(asmcode)) // read the asm
if err != nil {
t.Fatalf("could not parse the .asm file: %v", err)
}
str, err := go4k.SerializeAsm(song) // serialize again
str, err := go4k.FormatAsm(song) // serialize again
if err != nil {
t.Fatalf("Could not serialize asm file: %v", err)
}
song2, err := go4k.DeserializeAsm(str) // deserialize again. The rendered song should still give same results.
song2, err := go4k.ParseAsm(str) // deserialize again. The rendered song should still give same results.
if err != nil {
t.Fatalf("could not parse the serialized asm code: %v", err)
}

View File

@ -78,7 +78,7 @@ func main() {
}
var song go4k.Song
if err := json.Unmarshal(inputBytes, &song); err != nil {
song2, err2 := go4k.DeserializeAsm(string(inputBytes))
song2, err2 := go4k.ParseAsm(string(inputBytes))
if err2 != nil {
return fmt.Errorf("The song could not be parsed as .json (%v) nor .asm (%v)", err, err2)
}
@ -111,13 +111,13 @@ func main() {
maxSamples = len(buffer) / 2
}
header := go4k.ExportCHeader(&song, maxSamples)
header := go4k.CHeader(&song, maxSamples)
if err := output(".h", []byte(header)); err != nil {
return fmt.Errorf("Error outputting header file: %v", err)
}
}
if *asmOut {
asmCode, err := go4k.SerializeAsm(&song)
asmCode, err := go4k.FormatAsm(&song)
if err != nil {
return fmt.Errorf("Could not format the song as asm file: %v", err)
}