Parser can now ToString data sections properly

This commit is contained in:
Sasha Koshka 2022-08-16 16:37:20 -04:00
parent 5c23c59c92
commit 5e2d8c9955
1 changed files with 14 additions and 4 deletions

View File

@ -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
}