xgo/compiler/ast/map_lit.go

36 lines
685 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
)
// MapLit represents a map literal.
2019-01-09 10:17:42 +03:00
type MapLit struct {
LBrace source.Pos
2019-01-09 10:17:42 +03:00
Elements []*MapElementLit
RBrace source.Pos
2019-01-09 10:17:42 +03:00
}
func (e *MapLit) exprNode() {}
// Pos returns the position of first character belonging to the node.
func (e *MapLit) Pos() source.Pos {
2019-01-09 10:17:42 +03:00
return e.LBrace
}
// End returns the position of first character immediately after the node.
func (e *MapLit) End() source.Pos {
2019-01-09 10:17:42 +03:00
return e.RBrace + 1
}
func (e *MapLit) 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
}