xgo/compiler/ast/index_expr.go

33 lines
655 B
Go
Raw Normal View History

2019-01-09 10:17:42 +03:00
package ast
2019-01-11 13:27:28 +03:00
import "github.com/d5/tengo/compiler/source"
2019-01-09 10:17:42 +03:00
// IndexExpr represents an index expression.
2019-01-09 10:17:42 +03:00
type IndexExpr struct {
Expr Expr
LBrack source.Pos
2019-01-09 10:17:42 +03:00
Index Expr
RBrack source.Pos
2019-01-09 10:17:42 +03:00
}
func (e *IndexExpr) exprNode() {}
// Pos returns the position of first character belonging to the node.
func (e *IndexExpr) Pos() source.Pos {
2019-01-09 10:17:42 +03:00
return e.Expr.Pos()
}
// End returns the position of first character immediately after the node.
func (e *IndexExpr) End() source.Pos {
2019-01-09 10:17:42 +03:00
return e.RBrack + 1
}
func (e *IndexExpr) String() string {
var index string
if e.Index != nil {
index = e.Index.String()
}
return e.Expr.String() + "[" + index + "]"
}