Golang go/ast.DeclStmt type examples

package go/ast

A DeclStmt node represents a declaration in a statement list.

Golang go/ast.DeclStmt type usage examples

Example 1:

 var stmtBranches func(ast.Stmt)
 stmtBranches = func(s ast.Stmt) {
 switch s := s.(type) {
 case *ast.DeclStmt:
 if d, _ := s.Decl.(*ast.GenDecl); d != nil && d.Tok == token.VAR {
 recordVarDecl(d.Pos())
 }

Example 2:

 func NodeDescription(n ast.Node) string {
 switch n := n.(type) {
 case *ast.ArrayType:
 return "array type"
 case *ast.AssignStmt:
 return "assignment"
 case *ast.DeclStmt:
 return NodeDescription(n.Decl) + " statement"
 ...
 }

Reference :

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

Advertisement