Golang go/ast.BinaryExpr type examples

package go/ast

A BinaryExpr node represents a binary expression.

Golang go/ast.BinaryExpr type usage 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.BinaryExpr:
 return fmt.Sprintf("binary %s operation", n.Op)
 ...
 }

Example 2:

 func isBinary(expr ast.Expr) bool {
 _, ok := expr.(*ast.BinaryExpr)
 return ok
 }

Reference :

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

Advertisement