From 8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Jul 2023 11:57:59 +0100 Subject: Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing --- json_array/write.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'json_array/write.go') diff --git a/json_array/write.go b/json_array/write.go index 4d202c4..aaa2851 100644 --- a/json_array/write.go +++ b/json_array/write.go @@ -7,7 +7,7 @@ import ( "encoding/json" ) -func assembleValue(atoms []walk.Atom) (interface{}, []walk.Atom) { +func assembleValue(atoms []walk.AtomOLD) (interface{}, []walk.AtomOLD) { if len(atoms) == 0 { panic("Missing JSON value in output") } @@ -89,21 +89,16 @@ func assembleValue(atoms []walk.Atom) (interface{}, []walk.Atom) { } } -func outputValue(atoms []walk.Atom, writer *bufio.Writer) { - if len(atoms) == 0 { - return - } - value, atoms := assembleValue(atoms) - if len(atoms) != 0 { - panic("Tried to output more than one JSON value") - } - bytes, err := json.MarshalIndent(value, "\t", "\t") - if err != nil { - panic("Error marshalling json into bytes") - } - _, err = writer.Write(bytes) - if err != nil { - panic("Error writing value") +func outputValue(values []interface{}, writer *bufio.Writer) { + for _, value := range values { + bytes, err := json.MarshalIndent(value, "\t", "\t") + if err != nil { + panic("Error marshalling json into bytes") + } + _, err = writer.Write(bytes) + if err != nil { + panic("Error writing value") + } } } -- cgit v1.2.3