Re: [go-nuts] Re: Generating go code using go templates

2021-09-20 Thread Denis Cheremisov
Trees although better in general than template still have one critical disadvantage: it is hard to control a code they produces.I tried approaches with templates, line by line and trees. Line by line is generally the best of them. понедельник, 20 сентября 2021 г. в 23:15:22 UTC+3,

Re: [go-nuts] Re: Generating go code using go templates

2021-09-20 Thread Chetan Gowda
Yes. Generating large portions of code via templates is going to be hard. Especially reusing and maintaining it. There is an excellent library called jennifer - https://github.com/dave/jennifer that lets you generate Go code by building the syntax tree. The examples make it super simple to get

Re: [go-nuts] Re: Generating go code using go templates

2021-09-20 Thread Vasiliy Tolstov
I'm writing a code generator from protobuf via templates and i can say - debugging it is very hard. When you have big files you can't check syntax easily, don't know how it looks and if you have errors in the template it is really hard to fix them. So the protoc-gen-go case is preferable. вс, 19

[go-nuts] Re: Generating go code using go templates

2021-09-18 Thread Denis Cheremisov
Templates is the worst approach to code generation IMO. Take a look how they do this in protoc-gen-go: https://github.com/protocolbuffers/protobuf-go/blob/b92717ecb630d4a4824b372bf98c729d87311a4d/cmd/protoc-gen-go/internal_gengo/main.go#L83 I am using very similar approach, albeit I prefer