Added basic ToString method to TypeSection

This commit is contained in:
Sasha Koshka 2022-08-18 17:45:34 -04:00
parent 5c2a7aeb07
commit 9fd3fb1263
2 changed files with 26 additions and 3 deletions

View File

@ -46,6 +46,11 @@ func (tree *SyntaxTree) ToString (indent int) (output string) {
output += doIndent(indent, "---\n")
typeSectionKeys := sortMapKeysAlphabetically(tree.typeSections)
for _, name := range typeSectionKeys {
output += tree.typeSections[name].ToString(indent)
}
dataSectionKeys := sortMapKeysAlphabetically(tree.dataSections)
for _, name := range dataSectionKeys {
output += tree.dataSections[name].ToString(indent)
@ -246,3 +251,20 @@ func (section *DataSection) ToString (indent int) (output string) {
}
return
}
func (section *TypeSection) ToString (indent int) (output string) {
output += doIndent (
indent,
"type ",
section.permission.ToString(), " ",
section.name, ":",
section.what.ToString())
if section.defaultValue.value == nil {
// TODO: print out members
} else {
output += " " + section.defaultValue.ToString(0, false)
output += "\n"
}
return
}

View File

@ -176,8 +176,9 @@ type TypeSection struct {
location file.Location
name string
what Type
permission types.Permission
what Type
permission types.Permission
defaultValue Argument
// this should be 1 dimensional for now.
members map[string] TypeMember
members map[string] TypeMember
}