From eb3fb65c9b967de7d64d3833e9c137563a925936 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 16 Aug 2022 23:45:25 -0400 Subject: [PATCH] Changed object initialization values to be a map --- parser/tree-tostring.go | 27 ++++++++++++--------------- parser/tree.go | 18 +++++++++--------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index f598807..74e7753 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -78,23 +78,21 @@ func (declaration *Declaration) ToString () (output string) { return } -func (attribute *ObjectAttribute) ToString ( +func (attributes *ObjectAttributes) ToString ( indent int, - breakLine bool, ) ( output string, ) { - if breakLine { - output += doIndent(indent) + for name, value := range attributes.attributes { + output += doIndent(indent, ".", name, " ") + if value.kind == ArgumentKindObjectAttributes { + output += "\n" + output += value.ToString(indent + 1, true) + } else { + output += value.ToString(0, false) + "\n" + } } - output += ", " + attribute.name - if breakLine { - output += "\n" + attribute.value.ToString(indent + 1, true) - } else { - output += " " + attribute.value.ToString(0, false) - } - return } @@ -142,12 +140,11 @@ func (argument *Argument) ToString (indent int, breakLine bool) (output string) indent, breakLine)) - case ArgumentKindObjectAttribute: + case ArgumentKindObjectAttributes: + // this should only appear in contexts where breakLine is true output += doIndent ( indent, - argument.value.(*ObjectAttribute).ToString ( - indent, - breakLine)) + argument.value.(*ObjectAttributes).ToString (indent)) case ArgumentKindIdentifier: output += doIndent ( diff --git a/parser/tree.go b/parser/tree.go index 7919bde..76b7187 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -60,12 +60,11 @@ type Declaration struct { what Type } -// ObjectAttribute represents a notation to initialize object attributes. It -// contains a name, and the value that the attribute should be initialized to. -type ObjectAttribute struct { - location file.Location - name string - value Argument +// ObjectAttributes represents a list of object member initialization +// attributes. +type ObjectAttributes struct { + location file.Location + attributes map[string] Argument } // Phrase represents a function call or operator. In ARF they are the same @@ -93,8 +92,9 @@ const ( // {name 23} ArgumentKindSubscript - // , name value - ArgumentKindObjectAttribute + // .name value + // but like, a lot of them + ArgumentKindObjectAttributes // name.name // name.name.name @@ -103,7 +103,7 @@ const ( // name:Type // name:{Type} - // name:{Type ...} + // name:{Type ..} // name:{Type 23} // etc... ArgumentKindDeclaration