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
+7.5k Golang : Rot13 and Rot5 algorithms example
+6.4k CodeIgniter : form input set_value cause " to become & quot
+21.2k Golang : How to force compile or remove object files first before rebuild?
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+7k Golang : constant 20013 overflows byte error message
+30k Golang : Get time.Duration in year, month, week or day
+5.8k Javascript : How to replace HTML inside <div>?
+18.4k Golang : Read binary file into memory
+5.9k Golang : Denco multiplexer example
+18.3k Golang : Get path name to current directory or folder
+10.5k Golang : Create matrix with Gonum Matrix package example
+14k Golang : concatenate(combine) strings