Updated ToString methods to match new tree structure
This commit is contained in:
parent
222c47ced9
commit
fc1568aece
@ -253,39 +253,64 @@ func (section *DataSection) ToString (indent int) (output string) {
|
||||
}
|
||||
|
||||
func (section *TypeSection) ToString (indent int) (output string) {
|
||||
output += section.root.ToString(indent, true)
|
||||
return
|
||||
}
|
||||
|
||||
func (node TypeNode) ToString (indent int, isRoot bool) (output string) {
|
||||
output += doIndent(indent)
|
||||
if isRoot {
|
||||
output += "type "
|
||||
}
|
||||
|
||||
output += node.permission.ToString() + " "
|
||||
output += node.name + ":"
|
||||
output += node.what.ToString()
|
||||
output += doIndent (
|
||||
indent,
|
||||
"type ",
|
||||
section.permission.ToString(), " ",
|
||||
section.name, ":",
|
||||
section.inherits.ToString())
|
||||
|
||||
isComplexInitialization :=
|
||||
node.defaultValue.kind == ArgumentKindObjectInitializationValues ||
|
||||
node.defaultValue.kind == ArgumentKindArrayInitializationValues
|
||||
section.defaultValue.kind == ArgumentKindObjectInitializationValues ||
|
||||
section.defaultValue.kind == ArgumentKindArrayInitializationValues
|
||||
|
||||
if node.defaultValue.value == nil {
|
||||
if section.defaultValue.value == nil {
|
||||
output += "\n"
|
||||
if len(node.children) > 0 {
|
||||
for _, name := range sortMapKeysAlphabetically(node.children) {
|
||||
child := node.children[name]
|
||||
output += child.ToString(indent + 1, false)
|
||||
}
|
||||
}
|
||||
} else if isComplexInitialization {
|
||||
output += "\n"
|
||||
output += node.defaultValue.ToString(indent + 1, true)
|
||||
output += section.defaultValue.ToString(indent + 1, true)
|
||||
} else {
|
||||
output += " " + node.defaultValue.ToString(0, false)
|
||||
output += " " + section.defaultValue.ToString(0, false)
|
||||
output += "\n"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (member *ObjtMember) ToString (indent int) (output string) {
|
||||
output += doIndent(indent)
|
||||
|
||||
output += member.permission.ToString() + " "
|
||||
output += member.name + ":"
|
||||
output += member.what.ToString()
|
||||
|
||||
isComplexInitialization :=
|
||||
member.defaultValue.kind == ArgumentKindObjectInitializationValues ||
|
||||
member.defaultValue.kind == ArgumentKindArrayInitializationValues
|
||||
|
||||
if member.defaultValue.value == nil {
|
||||
output += "\n"
|
||||
} else if isComplexInitialization {
|
||||
output += "\n"
|
||||
output += member.defaultValue.ToString(indent + 1, true)
|
||||
} else {
|
||||
output += " " + member.defaultValue.ToString(0, false)
|
||||
output += "\n"
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (section *ObjtSection) ToString (indent int) (output string) {
|
||||
output += doIndent (
|
||||
indent,
|
||||
"objt ",
|
||||
section.permission.ToString(), " ",
|
||||
section.name, ":",
|
||||
section.inherits.ToString(), "\n")
|
||||
|
||||
for _, member := range section.members {
|
||||
output += member.ToString(indent + 1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -166,21 +166,11 @@ type TypeSection struct {
|
||||
location file.Location
|
||||
name string
|
||||
|
||||
what Type
|
||||
inherits Type
|
||||
permission types.Permission
|
||||
defaultValue Argument
|
||||
}
|
||||
|
||||
// ObjtSection represents an object type definition
|
||||
type ObjtSection struct {
|
||||
location file.Location
|
||||
name string
|
||||
|
||||
what Type
|
||||
permission types.Permission
|
||||
children map[string] ObjtMember
|
||||
}
|
||||
|
||||
// ObjtMember represents a part of an object type definition.
|
||||
type ObjtMember struct {
|
||||
location file.Location
|
||||
@ -190,3 +180,13 @@ type ObjtMember struct {
|
||||
permission types.Permission
|
||||
defaultValue Argument
|
||||
}
|
||||
|
||||
// ObjtSection represents an object type definition
|
||||
type ObjtSection struct {
|
||||
location file.Location
|
||||
name string
|
||||
|
||||
inherits Type
|
||||
permission types.Permission
|
||||
members map[string] ObjtMember
|
||||
}
|
||||
|
Reference in New Issue
Block a user