How do I get go/ast.Package.Scope.Objects to be set?

xuanbao · · 50 次点击    
<p>To get the ast.Package, I currently use go/build.Default.Import to get the go/build.Package, then use go/parser.ParseDir with a filter function that only allows the build.Package.GoFiles files. That all seems to work, and everything seems to get parsed, but the Objects I mentioned above is nil.</p> <p>(I need the package-level objects to get the iota count for const declarations from Object.Data.)</p> <hr/>**评论:**<br/><br/>joetsai: <pre><p>You&#39;re in luck that I was working on improving godoc and I had to deal with this problem as well.</p> <p><a href="https://play.golang.org/p/mYeyUEwHGJ" rel="nofollow">https://play.golang.org/p/mYeyUEwHGJ</a></p> <p>One way is to use ast.NewPackage with a very simple package importer.</p> <p>This is based on code found in github.com/golang/tools/godoc/server.go</p></pre>MadeThisForPython: <pre><p>I&#39;d recommend you to go ask the #go-nuts channel on Freenode.</p></pre>
50 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传