7 ms·
Yes, I read a few papers and poked around the source of gofmt, clang-format and a couple of others. They weren't as helpful as I'd hoped, but I got a few ideas
by munificent 8y ago
Yes, I read a few papers and poked around the source of gofmt, clang-format and a couple of others. They weren't as helpful as I'd hoped, but I got a few ideas from them here and there. Most of the implementation of a formatter is grunt-work stuff that's fairly specific to the grammar of the input language, the style rules it's trying to apply, and the weird vagaries of whatever parser or lexer you're using. There isn't that much I found I could take away from them.
The most useful research I did was actually around graph search algorithms. Branch-and-bound and most of the other stock pathfinding algorithms didn't work, but they gave me the pieces I needed to get to something that did.
Dynamic programming and memoization was key too. I got to use so many fundamental data structures and algorithms in this program. It was a joy.