Golang go/ast.Ellipsis type, End() and Pos() functions examples

package go/ast

An Ellipsis node stands for the "..." type in a parameter list or the "..." length in an array type.

Golang go/ast.Ellipsis type, End() and Pos() functions examples

Example 1:

  func NodeDescription(n ast.Node) string {
 switch n := n.(type) {
 case *ast.ArrayType:
 return "array type"
 case *ast.AssignStmt:
 return "assignment"
 case *ast.Ellipsis:
 return "ellipsis"
 ...
  }

Example 2:

  func checkCurrentPosition(node ast.Node) string {
 n := node.(*ast.Ellipsis)
 endpos := n.End()
 pospos := n.Pos()

 if pospos != endpos {
 return "not yet"
 }
  }

References :

http://golang.org/pkg/go/ast/#Ellipsis

http://golang.org/pkg/go/ast/#Ellipsis.End

http://golang.org/pkg/go/ast/#Ellipsis.Pos

Advertisement