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.1k Javascript : Empty an array example
+12k Golang : Decompress zlib file example
+14.3k Golang : Simple word wrap or line breaking example
+5.4k Golang *File points to a file or directory ?
+20.6k Golang : Secure(TLS) connection between server and client
+14.4k Golang : Find network of an IP address
+7k Golang : Find the shortest line of text example
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+8.8k Golang : Accept any number of function arguments with three dots(...)
+5.2k Golang : Convert lines of string into list for delete and insert operation
+4.5k Java : Generate multiplication table example
+5.8k Unix/Linux : How to test user agents blocked successfully ?