FAQ
Using templates is the easiest way to generate code. go/ast isn't bad
for analyzing go files, but it's hard to generate code from an AST or
even to transform an existing AST (at least while preserving
comments). Even if you manage to pull it off the template is going to
be much shorter and easier to debug and read.

On Sat, May 7, 2016 at 10:30 AM, Carl Mastrangelo
wrote:
In a toy project I am working on, I am trying to generate Go code
automatically to cut down on the amount of boiler plate I have to write. I
was looking at the packages under go/ in the standard library, but a lot of
them seem specific to taking existing code and interpreting it rather than
the other direction. Specifically, a lot of the API depends on having a
token.FileSet, which assumes the file already exist. Since I am making it
from scratch, I don't have a file or line number or token positions.

Is there a proper way to generate code? Looking at golang/protobuf, it
seems to print out raw strings currently too. Other projects like protobuf
would likely benefit from being able to build code using standard packages.

--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 7 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 7, '16 at 5:30p
activeMay 9, '16 at 9:34a
posts7
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase