3 ms·
Love using the template library for writing codegen utils for Go and Java
by philosopher1234 6y ago
Love using the template library for writing codegen utils for Go and Java
- everybodyknows 6y agoLooked for codegen utils on Github a while back -- but found nothing useful. Any public utils you'd recommend?
- philosopher1234 6y agoI love using text/template directly for codegen. Its really easy in my experience to create sophisticated tools using it + some go functionality. The trick is learning what gen problems are best solved in text templates and whats best solved in go functions. A big advantage of using text/template for codegen is you can just write the code you want to generate and it looks like real go code. Really easy to maintain compared to AST-style codegen.
- everybodyknows 6y agoSounds similar to my use case. Two snags to work around when generating Go source: 1. The {{}} pairs confuse editor syntax coloring (in emacs, anyway). 2. Expansions that introduce or drop line breaks will cause the runtime/dlv to report line numbers that disagree with the pre-gen source you need to correct.