From 7af575e865bd08df0ef11337479494e7cfda249c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 4 Sep 2022 22:27:06 -0400 Subject: [PATCH] Added TypeKindVariableArray --- parser/accessors.go | 4 ++-- parser/misc.go | 2 +- parser/tree-tostring.go | 9 +++------ parser/tree.go | 11 +++++------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/parser/accessors.go b/parser/accessors.go index 0781bec..3a207ce 100644 --- a/parser/accessors.go +++ b/parser/accessors.go @@ -67,8 +67,8 @@ func (what Type) Mutable () (mutable bool) { return } -// Length returns the length of the type if the type is an array. If the result -// is 0, this means the array has an undefined/variable length. +// Length returns the length of the type if the type is a fixed length array. +// Otherwise, it just returns zero. func (what Type) Length () (length uint64) { if what.kind == TypeKindArray { length = what.length diff --git a/parser/misc.go b/parser/misc.go index 0901cdc..121df15 100644 --- a/parser/misc.go +++ b/parser/misc.go @@ -34,7 +34,7 @@ func (parser *ParsingOperation) parseType () (what Type, err error) { err = parser.nextToken(lexer.TokenKindRBrace) if err != nil { return } } else if parser.token.Is(lexer.TokenKindElipsis) { - what.kind = TypeKindArray + what.kind = TypeKindVariableArray err = parser.nextToken(lexer.TokenKindRBrace) if err != nil { return } diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index ddc5ef2..78dd94c 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -74,12 +74,9 @@ func (what Type) ToString () (output string) { output += what.points.ToString() if what.kind == TypeKindArray { - output += " " - if what.length == 0 { - output += ".." - } else { - output += fmt.Sprint(what.length) - } + output += fmt.Sprint(" ", what.length) + } else if what.kind == TypeKindVariableArray { + output += " .." } output += "}" diff --git a/parser/tree.go b/parser/tree.go index 2d1eade..d563942 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -38,7 +38,7 @@ type Section interface { ToString (indent int) (output string) } -// Identifier represents a chain of arguments separated by a dot. +// Identifier represents a chain of names separated by a dot. type Identifier struct { locatable trail []string @@ -55,11 +55,11 @@ const ( // TypeKindPointer means it's a pointer TypeKindPointer - // TypeKindArray means it's an array. + // TypeKindArray means it's a fixed length array. TypeKindArray - // TODO: add a type kind for arrays with a variable amount of elements, - // because they are very much different concepts + // TypeKindVariableArray means it's an array of variable length. + TypeKindVariableArray ) // Type represents a type specifier @@ -69,8 +69,7 @@ type Type struct { mutable bool kind TypeKind - // only applicable for arrays. a value of zero means it has an - // undefined/dynamic length. + // only applicable for fixed length arrays. length uint64 // only applicable for basic.