xgo/compiler/ast/ident_list.go

55 lines
755 B
Go
Raw Normal View History

2019-01-09 10:17:42 +03:00
package ast
import (
"strings"
2019-01-11 13:27:28 +03:00
"github.com/d5/tengo/compiler/source"
2019-01-09 10:17:42 +03:00
)
type IdentList struct {
LParen source.Pos
2019-01-09 10:17:42 +03:00
List []*Ident
RParen source.Pos
2019-01-09 10:17:42 +03:00
}
func (n *IdentList) Pos() source.Pos {
2019-01-09 10:17:42 +03:00
if n.LParen.IsValid() {
return n.LParen
}
if len(n.List) > 0 {
return n.List[0].Pos()
}
return source.NoPos
2019-01-09 10:17:42 +03:00
}
func (n *IdentList) End() source.Pos {
2019-01-09 10:17:42 +03:00
if n.RParen.IsValid() {
return n.RParen + 1
}
if l := len(n.List); l > 0 {
return n.List[l-1].End()
}
return source.NoPos
2019-01-09 10:17:42 +03:00
}
func (n *IdentList) NumFields() int {
if n == nil {
return 0
}
return len(n.List)
}
func (n *IdentList) String() string {
var list []string
for _, e := range n.List {
list = append(list, e.String())
}
return "(" + strings.Join(list, ", ") + ")"
}