xgo/compiler/ast/array_lit.go

36 lines
690 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
)
// ArrayLit represents an array literal.
2019-01-09 10:17:42 +03:00
type ArrayLit struct {
Elements []Expr
LBrack source.Pos
RBrack source.Pos
2019-01-09 10:17:42 +03:00
}
func (e *ArrayLit) exprNode() {}
// Pos returns the position of first character belonging to the node.
func (e *ArrayLit) Pos() source.Pos {
2019-01-09 10:17:42 +03:00
return e.LBrack
}
// End returns the position of first character immediately after the node.
func (e *ArrayLit) End() source.Pos {
2019-01-09 10:17:42 +03:00
return e.RBrack + 1
}
func (e *ArrayLit) String() string {
2019-01-17 12:56:05 +03:00
var elements []string
2019-01-09 10:17:42 +03:00
for _, m := range e.Elements {
2019-01-17 12:56:05 +03:00
elements = append(elements, m.String())
2019-01-09 10:17:42 +03:00
}
2019-01-17 12:56:05 +03:00
return "[" + strings.Join(elements, ", ") + "]"
2019-01-09 10:17:42 +03:00
}