I may be one of the most obsessive about the subject of source code 
layouts, partly because of the impact that especially large and 
disorganised source files (at least to the extent of the individual files, 
but packages can get really nasty too).

It took me some time to navigate to find the fork of the ast library that 
properly retains comment positioning when the AST is rewritten (in this 
case, by changing the order of the declaration blocks), and it doesn't 
fully satisfy all my requirements yet (splits all var and type blocks per 
declaration but puts all of them inside parentheses one per declaration, 
doesn't remove the parentheses completely, and doesn't touch consts because 
iota makes them order sensitive), but it works ok and saves me a lot of 
manual reformatting work.

The other thing is that probably not many Go programmers know that braces 
and brackets blocks (except for type assertions and the type switch) can 
all be multi-line split if the final line has a comma after it. I think 
that function parameters are more readable when they are lined up 
vertically so this little tool does part of that, for now only receivers 
and putting a newline after the function parameter open bracket. I would 
like it if it did the whole set so there is no manual work remaining to get 
this, but my regexp skills are not very great at this point and I'm really 
pushing it to get a project finished - that has big nasty source files over 
2000 lines in places.

https://github.com/parallelcointeam/pod/tree/master/cmd/tools/cleaner

Just for if anyone else is as crazy as me and finds complex source code 
structures doubly difficulty without any kind of sorting done on the parts 
of the file.

I'm sure that it's written terribly. The newline parts are just bulk search 
and replace as I found writing the FSM to step through it too confusing. 

I've long dreamed of writing a full blown language parser, but for now with 
my prorities this is a little step towards that, and maybe someone else 
finds this useful.

-- 
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.

Reply via email to