Documentation
¶
Overview ¶
Package printer implements printing of AST nodes.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint "pretty-prints" an AST node to output. It calls Config.Fprint with default settings. Note that gofmt uses tabs for indentation but spaces for alignment; use format.Node (package go/format) for output that matches gofmt.
Example ¶
printSelf()
Output: funcAST, fset := parseFunc("example_test.go", "printSelf") var buf bytes.Buffer printer.Fprint(&buf, fset, funcAST.Body) s := buf.String() s = s[1 : len(s)-1] s = strings.TrimSpace(strings.ReplaceAll(s, "\n\t", "\n")) fmt.Println(s)
Types ¶
type CommentedNode ¶
type CommentedNode struct {
Node any
Comments []*ast.CommentGroup
}
A CommentedNode bundles an AST node and corresponding comments. It may be provided as argument to any of the Fprint functions.
type Config ¶
A Config node controls the output of Fprint.
func (*Config) Fprint ¶
Fprint "pretty-prints" an AST node to output for a given configuration cfg. Position information is interpreted relative to the file set fset. The node type must be *ast.File, *CommentedNode, []ast.Decl, []ast.Stmt, or assignment-compatible to ast.Expr, ast.Decl, ast.Spec, or ast.Stmt.