Documentation ¶
Overview ¶
Package astinfo records useful AST information like node parents and such.
Example ¶
package main import ( "fmt" "go/ast" "github.com/go-toolsmith/astinfo" ) func main() { innermost := &ast.Ident{} root := &ast.ExprStmt{ X: &ast.BinaryExpr{ X: &ast.BasicLit{}, Y: &ast.UnaryExpr{X: innermost}, }, } info := astinfo.Info{Parents: make(map[ast.Node]ast.Node)} info.Origin = root info.Resolve() for p := info.Parents[innermost]; p != nil; p = info.Parents[p] { fmt.Printf("%T\n", p) } }
Output: *ast.UnaryExpr *ast.BinaryExpr *ast.ExprStmt
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { // Origin is a node that was used to collect all the // information stored inside this object. Origin ast.Node // Parents maps child AST not to its parent. // // Does not contain top-level nodes, so the lookup will // return nil for those. Parents map[ast.Node]ast.Node }
Info holds AST metadata collected during Origin field traversal.
Click to show internal directories.
Click to hide internal directories.