AntLR, Golang and HOCON

xuanbao · · 1000 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi! </p> <p>I&#39;m experimenting with the parser generator (<a href="http://www.antlr.org/" rel="nofollow">Antlr</a>) and Go. I used to leverage <a href="https://github.com/typesafehub/config" rel="nofollow">Typesafe Config</a> widely adopted by Scala community, and I find it really interesting to port <a href="https://github.com/typesafehub/config/blob/master/HOCON.md" rel="nofollow">HOCON</a> to Go.</p> <p>I started from this project <a href="https://github.com/jdevelop/go-hocon" rel="nofollow">go-hocon</a> .</p> <p>So far it can parse some reference configs from Akka, also is able to build a simple config tree.</p> <p>I&#39;d like to get some feedback/patches from more experienced Go developers to familiarize myself with the best practices on something breathing and useful (at least for me). </p> <p>Thanks!</p> <hr/>**评论:**<br/><br/>shovelpost: <pre><p>A couple of thoughts.</p> <p>Go and its community tends to stay close to simplicity and pragmatism. First you should ask yourself if such a generalized, powerful and complex configuration system is really needed. I believe the existing configuration &#34;solutions&#34; like using JSON, TOML, YAML in combination with flags and environmental variables can get the job done just fine. Also take a look at how the Upspin team use a very simple, custom <a href="https://github.com/upspin/upspin/blob/master/config/initconfig.go#L103-L110" rel="nofollow">configuration format</a>. On the other hand if you feel passionate about this project or if it is a learning exercise then that&#39;s a different case. In the end, from the Go community&#39;s perspective, any port from X to Go is always nice to have.</p> <p>Going away from the &#34;if you should&#34; question, my advice is to avoid &#34;translating&#34; the Java implementation to Go. They are very different languages with very different programming styles. Something that might be relevant and could probably give you some inspiration is Rob Pike&#39;s <a href="https://talks.golang.org/2011/lex.slide#1" rel="nofollow">talk</a> on <a href="https://www.youtube.com/watch?v=HxaD_trXwRE" rel="nofollow">lexical scanning</a>.</p> <p>Cheers.</p></pre>statistmonad: <pre><p>Looks like a cool project to me. You can probably reduce the amount of code duplication for the 3 different anltr entrypoints by using a single function for lexing onwards as the streams are all the same interface. I would also restructure the project a little bit so that you can keep generated code separate from regular code, and you probably don&#39;t need tests for the generated code only how you use it.</p> <p>It might also be worth looking at hand writing a parser for something like this at a later point, though I appreciate that is a pain. Take a look at the go template library implementation for a novel way of doing it. I think the other comment on this topic mentions a talk about it as well. </p></pre>

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

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