debug: add helper for printing AST nodes
package debug
import (
+ "bytes"
"go/ast"
+ "go/format"
"go/parser"
"go/token"
"go/types"
@@ -34,3 +36,10 @@ func TypeCheck(src string) (*ast.File, *types.Package, *types.Info, error) {
}
return f, pkg, info, nil
}
+
+func FormatNode(node ast.Node) string {
+ var buf bytes.Buffer
+ fset := token.NewFileSet()
+ format.Node(&buf, fset, node)
+ return buf.String()
+}
