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
+22.2k Golang : How to run Golang application such as web server in the background or as daemon?
+8k Golang : Sort words with first uppercase letter
+6.1k Golang : How to write backslash in string?
+8.7k Golang : How to join strings?
+13.8k Golang : unknown escape sequence error
+13.7k Golang : Check if an integer is negative or positive
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+12.1k Golang : md5 hash of a string
+6k Golang : Compound interest over time example
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+32.4k Golang : Math pow(the power of x^y) example