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
|
|
|
)
|
|
|
|
|
2019-01-15 09:24:33 +03:00
|
|
|
// IdentList represetns a list of identifiers.
|
2019-01-09 10:17:42 +03:00
|
|
|
type IdentList struct {
|
2019-01-11 12:16:34 +03:00
|
|
|
LParen source.Pos
|
2019-01-09 10:17:42 +03:00
|
|
|
List []*Ident
|
2019-01-11 12:16:34 +03:00
|
|
|
RParen source.Pos
|
2019-01-09 10:17:42 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 09:24:33 +03:00
|
|
|
// Pos returns the position of first character belonging to the node.
|
2019-01-11 12:16:34 +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()
|
|
|
|
}
|
|
|
|
|
2019-01-11 12:16:34 +03:00
|
|
|
return source.NoPos
|
2019-01-09 10:17:42 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 09:24:33 +03:00
|
|
|
// End returns the position of first character immediately after the node.
|
2019-01-11 12:16:34 +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()
|
|
|
|
}
|
|
|
|
|
2019-01-11 12:16:34 +03:00
|
|
|
return source.NoPos
|
2019-01-09 10:17:42 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 09:24:33 +03:00
|
|
|
// NumFields returns the number of fields.
|
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, ", ") + ")"
|
|
|
|
}
|