Made ToString for type notations actually work properly

This commit is contained in:
Sasha Koshka 2022-09-16 18:16:51 -04:00
parent 925f55788f
commit a6af1d5121

View File

@ -66,32 +66,43 @@ func (identifier Identifier) ToString () (output string) {
return return
} }
func (values ObjectDefaultValues) ToString (indent int) (output string) { func (values ObjectDefaultValues) ToString (
indent int,
breakLine bool,
) (
output string,
) {
output += doIndent(indent, "(\n") output += doIndent(indent, "(\n")
for name, value := range values { for name, value := range values {
output += doIndent ( output += doIndent (
indent, indent,
name + ":" + value.ToString(indent, true)) name + ":" + value.ToString(indent, false))
output += "\n"
} }
output += doIndent(indent, ")\n") output += doIndent(indent, ")")
return return
} }
func (values ArrayDefaultValues) ToString (indent int) (output string) { func (values ArrayDefaultValues) ToString (
indent int,
breakLine bool,
) (
output string,
) {
output += doIndent(indent, "<\n") output += doIndent(indent, "<\n")
for _, value := range values { for _, value := range values {
output += doIndent(indent, value.ToString(indent, true)) output += value.ToString(indent, breakLine)
} }
output += doIndent(indent, ">\n") output += doIndent(indent, ">")
return return
} }
func (what Type) ToString (indent int) (output string) { func (what Type) ToString (indent int, breakLine bool) (output string) {
if what.kind == TypeKindBasic { if what.kind == TypeKindBasic {
output += what.name.ToString() output += what.name.ToString()
} else { } else {
output += "{" output += "{"
output += what.points.ToString(indent) output += what.points.ToString(indent, breakLine)
if what.kind == TypeKindVariableArray { if what.kind == TypeKindVariableArray {
output += " .." output += " .."
@ -123,13 +134,13 @@ func (what Type) ToString (indent int) (output string) {
defaultValueKind == ArgumentKindObjectDefaultValues || defaultValueKind == ArgumentKindObjectDefaultValues ||
defaultValueKind == ArgumentKindArrayDefaultValues defaultValueKind == ArgumentKindArrayDefaultValues
if isComplexDefaultValue { if isComplexDefaultValue && breakLine{
output += ":\n" output += ":\n"
output += what.defaultValue.ToString(indent, true) output += what.defaultValue.ToString(indent + 1, breakLine)
} else { } else {
output += ":<" output += ":<"
output += what.defaultValue.ToString(indent, false) output += what.defaultValue.ToString(indent, false)
output += ">\n" output += ">"
} }
} }
return return