syntax-tree-accessors #2
@ -67,8 +67,8 @@ func (what Type) Mutable () (mutable bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length returns the length of the type if the type is an array. If the result
|
// Length returns the length of the type if the type is a fixed length array.
|
||||||
// is 0, this means the array has an undefined/variable length.
|
// Otherwise, it just returns zero.
|
||||||
func (what Type) Length () (length uint64) {
|
func (what Type) Length () (length uint64) {
|
||||||
if what.kind == TypeKindArray {
|
if what.kind == TypeKindArray {
|
||||||
length = what.length
|
length = what.length
|
||||||
|
@ -34,7 +34,7 @@ func (parser *ParsingOperation) parseType () (what Type, err error) {
|
|||||||
err = parser.nextToken(lexer.TokenKindRBrace)
|
err = parser.nextToken(lexer.TokenKindRBrace)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
} else if parser.token.Is(lexer.TokenKindElipsis) {
|
} else if parser.token.Is(lexer.TokenKindElipsis) {
|
||||||
what.kind = TypeKindArray
|
what.kind = TypeKindVariableArray
|
||||||
|
|
||||||
err = parser.nextToken(lexer.TokenKindRBrace)
|
err = parser.nextToken(lexer.TokenKindRBrace)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
@ -74,12 +74,9 @@ func (what Type) ToString () (output string) {
|
|||||||
output += what.points.ToString()
|
output += what.points.ToString()
|
||||||
|
|
||||||
if what.kind == TypeKindArray {
|
if what.kind == TypeKindArray {
|
||||||
output += " "
|
output += fmt.Sprint(" ", what.length)
|
||||||
if what.length == 0 {
|
} else if what.kind == TypeKindVariableArray {
|
||||||
output += ".."
|
output += " .."
|
||||||
} else {
|
|
||||||
output += fmt.Sprint(what.length)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "}"
|
output += "}"
|
||||||
|
@ -38,7 +38,7 @@ type Section interface {
|
|||||||
ToString (indent int) (output string)
|
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 {
|
type Identifier struct {
|
||||||
locatable
|
locatable
|
||||||
trail []string
|
trail []string
|
||||||
@ -55,11 +55,11 @@ const (
|
|||||||
// TypeKindPointer means it's a pointer
|
// TypeKindPointer means it's a pointer
|
||||||
TypeKindPointer
|
TypeKindPointer
|
||||||
|
|
||||||
// TypeKindArray means it's an array.
|
// TypeKindArray means it's a fixed length array.
|
||||||
TypeKindArray
|
TypeKindArray
|
||||||
|
|
||||||
// TODO: add a type kind for arrays with a variable amount of elements,
|
// TypeKindVariableArray means it's an array of variable length.
|
||||||
// because they are very much different concepts
|
TypeKindVariableArray
|
||||||
)
|
)
|
||||||
|
|
||||||
// Type represents a type specifier
|
// Type represents a type specifier
|
||||||
@ -69,8 +69,7 @@ type Type struct {
|
|||||||
mutable bool
|
mutable bool
|
||||||
kind TypeKind
|
kind TypeKind
|
||||||
|
|
||||||
// only applicable for arrays. a value of zero means it has an
|
// only applicable for fixed length arrays.
|
||||||
// undefined/dynamic length.
|
|
||||||
length uint64
|
length uint64
|
||||||
|
|
||||||
// only applicable for basic.
|
// only applicable for basic.
|
||||||
|
Reference in New Issue
Block a user