walker

package
v0.0.0-...-d31700d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Walker

type Walker struct {
	SrcFile string
	AstFile *ast.File
	FileSet *token.FileSet
}

func New

func New(path string) *Walker
Example
New("walker_test.go")
Output:

func Parse

func Parse(path, src string) *Walker

func (*Walker) Walk

func (w *Walker) Walk(fun func(isLocal bool, node ast.Node))
Example
w := Parse("example.go", `
package testdata

import "fmt"

func Hello() {
	fmt.Println("hello")
}
`)
w.Walk(func(isLocal bool, node ast.Node) {
	if isLocal {
		fmt.Printf("local %T\n", node)
	} else {
		fmt.Printf("%T\n", node)
	}
})
Output:

*ast.File
*ast.Ident
*ast.GenDecl
*ast.ImportSpec
*ast.BasicLit
*ast.FuncDecl
*ast.Ident
*ast.FuncType
*ast.FieldList
*ast.BlockStmt
local *ast.ExprStmt
local *ast.CallExpr
local *ast.SelectorExpr
local *ast.Ident
local *ast.Ident
local *ast.BasicLit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL