From c4101dcd330dab1c79e7ee37ff82d5912e5ca173 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 27 Sep 2022 14:17:03 -0400 Subject: [PATCH] More tree changes --- parser/accessors.go | 12 ------------ parser/node-traits.go | 31 +++++++++++++++++++++---------- parser/tree.go | 11 ++++++++++- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/parser/accessors.go b/parser/accessors.go index 1801312..fcb7957 100644 --- a/parser/accessors.go +++ b/parser/accessors.go @@ -169,18 +169,6 @@ func (phrase Phrase) Kind () (kind PhraseKind) { return } -// ArgumentsLength returns the amount of arguments in the phrase. -func (phrase Phrase) ArgumentsLength () (length int) { - length = len(phrase.arguments) - return -} - -// Argument returns the argument at index. -func (phrase Phrase) Argument (index int) (argument Argument) { - argument = phrase.arguments[index] - return -} - // ReturneesLength returns the amount of things the phrase returns to. func (phrase Phrase) ReturneesLength () (length int) { length = len(phrase.returnees) diff --git a/parser/node-traits.go b/parser/node-traits.go index 2ec0da6..6feeb0d 100644 --- a/parser/node-traits.go +++ b/parser/node-traits.go @@ -43,7 +43,7 @@ type typeable struct { // Type returns the type of the node. func (trait typeable) Type () (what Type) { - what = trait.what + what = trait.what return } @@ -60,17 +60,28 @@ func (trait permissionable) Permission () (permission types.Permission) { // valuable allows a node to have an argument value. type valuable struct { + value Argument +} + +// Value returns the value argument of the node. +func (trait valuable) Value () (value Argument) { + value = trait.value + return +} + +// multiValuable allows a node to have several argument values. +type multiValuable struct { values []Argument } -// Length returns the amount of default values in the node. -func (node valuable) Length () (length int) { - length = len(node.values) - return -} - -// Value returns the default value at the specified index. -func (node valuable) Value (index int) (value Argument) { - value = node.values[index] +// Value returns the value at index. +func (trait multiValuable) Value (index int) (value Argument) { + value = trait.values[index] + return +} + +// Length returns the amount of values in the mode. +func (trait multiValuable) Length () (length int) { + length = len(trait.values) return } diff --git a/parser/tree.go b/parser/tree.go index bb9147b..af89a49 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -82,6 +82,12 @@ type Declaration struct { typeable } +// List represents an array or object literal. +type List struct { + locatable + multiValuable +} + // ArgumentKind specifies the type of thing the value of an argument should be // cast to. type ArgumentKind int @@ -94,6 +100,9 @@ const ( // etc... ArgumentKindPhrase + // (argument argument argument) + ArgumentKindList + // {name} ArgumentKindDereference @@ -221,8 +230,8 @@ const ( type Phrase struct { location file.Location command Argument - arguments []Argument returnees []Argument + multiValuable kind PhraseKind