From 5e2d8c995508e256dd735095399dccdc8722a621 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 16 Aug 2022 16:37:20 -0400 Subject: [PATCH] Parser can now ToString data sections properly --- parser/tree-tostring.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index a46da08..6ce75ec 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -30,7 +30,7 @@ func (tree *SyntaxTree) ToString (indent int) (output string) { output += doIndent(indent, "---\n") for _, require := range tree.dataSections { - output += require.ToString(1) + output += require.ToString(indent) } return } @@ -165,6 +165,8 @@ func (argument *Argument) ToString (indent int, breakLine bool) (output string) case ArgumentKindOperator: // TODO } + + if breakLine { output += "\n" } return } @@ -176,8 +178,16 @@ func (section *DataSection) ToString (indent int) (output string) { section.name, ":", section.what.ToString()) - // TODO: print out initialization values. if there is only one of them, - // keep it on the same line. if there are more than one, give each its - // own line. + if len(section.value) == 0 { + output += "\n" + } else if len(section.value) == 1 { + output += " " + section.value[0].ToString(0, false) + output += "\n" + } else { + output += "\n" + for _, argument := range(section.value) { + output += argument.ToString(indent + 1, true) + } + } return }