diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index d469ed3..a26c6c9 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -56,6 +56,11 @@ func (tree *SyntaxTree) ToString (indent int) (output string) { output += tree.objtSections[name].ToString(indent) } + enumSectionKeys := sortMapKeysAlphabetically(tree.enumSections) + for _, name := range enumSectionKeys { + output += tree.enumSections[name].ToString(indent) + } + dataSectionKeys := sortMapKeysAlphabetically(tree.dataSections) for _, name := range dataSectionKeys { output += tree.dataSections[name].ToString(indent) @@ -319,3 +324,32 @@ func (section *ObjtSection) ToString (indent int) (output string) { return } +func (section *EnumSection) ToString (indent int) (output string) { + output += doIndent ( + indent, + "enum ", + section.permission.ToString(), " ", + section.name, ":", + section.what.ToString(), "\n") + + for _, name := range sortMapKeysAlphabetically(section.members) { + output += doIndent(indent, name, " ") + + member := section.members[name] + + isComplexInitialization := + member.kind == ArgumentKindObjectInitializationValues || + member.kind == ArgumentKindArrayInitializationValues + + if member.value == nil { + output += "\n" + } else if isComplexInitialization { + output += "\n" + output += member.ToString(indent + 1, true) + } else { + output += " " + member.ToString(0, false) + output += "\n" + } + } + return +} diff --git a/parser/tree.go b/parser/tree.go index c1b5e74..f5cf332 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -13,6 +13,7 @@ type SyntaxTree struct { requires []string typeSections map[string] *TypeSection objtSections map[string] *ObjtSection + enumSections map[string] *EnumSection dataSections map[string] *DataSection } @@ -191,3 +192,13 @@ type ObjtSection struct { permission types.Permission members map[string] ObjtMember } + +// EnumSection represents an enumerated type section. +type EnumSection struct { + location file.Location + name string + + what Type + permission types.Permission + members map[string] Argument +}