A small AST lib help accessing top-level structs/constants/functions, pleased if helpful for gophers

blov · · 739 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>This lib provide a simple way to access top-level declarations: struct/const/function, you needn&#39;t use go/{token/ast/parser}。</p> <p>It help you write tools like stringer, generate codes for structures, etc..</p> <p>Here is a test case show how simple it&#39;s: <a href="https://github.com/cosiner/gohper/blob/master/goutil/ast/ast_test.go">https://github.com/cosiner/gohper/blob/master/goutil/ast/ast_test.go</a></p> <p>Example parsing structures: <a href="https://github.com/cosiner/gomodel/blob/master/cmd/gomodel/genmodel.go#L171">github.com/cosiner/gomodel/blob/master/cmd/gomodel/genmodel.go#L171</a>.</p> <p>Documentation here: <a href="http://godoc.org/github.com/cosiner/gohper/goutil/ast">http://godoc.org/github.com/cosiner/gohper/goutil/ast</a></p> <hr/>**评论:**<br/><br/>space-llama: <pre><p>This isn&#39;t bad but you could probably clean up the code a bit. Low-hanging fruit here would be these <a href="https://github.com/cosiner/gohper/blob/master/goutil/ast/ast.go#L86" rel="nofollow">goto statements</a> which could just return the error. Then the functions above could worry about if it&#39;s a real error or not. Also, why not use a for-range loop <a href="https://github.com/cosiner/gohper/blob/master/goutil/ast/ast.go#L83" rel="nofollow">here</a> instead of this very C-esque for-loop? If you return the err, then looping will naturally stop.</p> <p>Otherwise, not bad, but not very Go-like. </p></pre>cosiner_z: <pre><p>Thanks, i use <code>defer</code> instead, and add the <code>Interface</code> option.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

739 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传