1 Star 0 Fork 0

bughou / go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
walker.go 648 Bytes
一键复制 编辑 原始数据 按行查看 历史
bughou 提交于 2022-03-21 20:37 . save
package walker
import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
)
type Walker struct {
SrcFile string
AstFile *ast.File
FileSet *token.FileSet
}
func New(path string) *Walker {
src, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
return Parse(path, string(src))
}
func Parse(path, src string) *Walker {
fileSet := token.NewFileSet()
astFile, err := parser.ParseFile(fileSet, path, src, parser.ParseComments)
if err != nil {
panic(err)
}
return &Walker{SrcFile: src, AstFile: astFile, FileSet: fileSet}
}
func (w *Walker) Walk(fun func(isLocal bool, node ast.Node)) {
ast.Walk(visitor{fun: fun}, w.AstFile)
}
Go
1
https://gitee.com/bughou/go.git
git@gitee.com:bughou/go.git
bughou
go
go
d31700df43a9

搜索帮助