Golang go/ast.BlockStmt type examples
package go/ast
A BlockStmt node represents a braced statement list.
Golang go/ast.BlockStmt 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.BlockStmt:
return "block"
...
}
Example 2:
var node ast.Node
...
switch n := node.(type) {
var stmt := n.Else.(type)
block := &ast.BlockStmt{
Lbrace: n.Body.End(), // Start at end of the "if" block so the covered part looks like it starts at the "else".
List: []ast.Stmt{stmt},
Rbrace: stmt.End(),
}
n.Else = block
}
...
Reference :
Advertisement
Something interesting
Tutorials
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+18.8k Golang : Implement getters and setters
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine
+16.1k Golang : Generate universally unique identifier(UUID) example
+14.5k Golang : Overwrite previous output with count down timer
+6.1k Golang : How to write backslash in string?
+10k Golang : Setting variable value with ldflags
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+6.2k PHP : Get client IP address
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+11.6k Golang : Surveillance with web camera and OpenCV
+9.2k Golang : How to check if a string with spaces in between is numeric?