Ideally, its some option to pass to, //PrintAstFile prints an ast to given writer. func PrintAstFile(w io.Writer, node *ast.File) error { fset := token.NewFileSet() return format.Node(w, fset, node) }
On Friday, January 6, 2017 at 7:57:00 PM UTC+1, mhh...@gmail.com wrote: > > Hi, > > i have a source code rendered like this, > var some = map[string]interface { > }{"b": func() { > }, "c": func() { > }, "yy": func(s string) b.SomeType { > return b.SomeType{} > }, "zz": func() { > }, "ii": func(s string) a.Tomate { > return nil > }, "uu": func(s string) *b.SomeType { > return nil > }, "g": func() template.HTML { > return template.HTML("") > }} > > See how the import declaration is clean and neat, > and how the map could be much more readable. > > This output is already the one from *go/format.Print.* > > I d prefer something like this > var some = map[string]interface {}{ > "b": func() {}, > "c": func() {}, > "yy": func(s string) b.SomeType { > return b.SomeType{} > }, > "zz": func() { > }, > "ii": func(s string) a.Tomate { > return nil > }, > "uu": func(s string) *b.SomeType { > return nil > }, > "g": func() template.HTML { > return template.HTML("") > } > } > > Is there a lib i can use to enforce a better pretty printing of the first > source code ? > > My search did not reveal any, > I d like to avoid regexp as i m not sure how far and complex this will > lead me, > i m a bit afraid to work with token.Pos values of the ast, > as i don t understand very deeply the Pos values consequence > (...There are all set to NoPos, except the import declaration). > > thanks > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.