On Friday, 16 January 2015 at 15:06:42 UTC, Ary Borenszweig wrote:
The way I did it in Descent (I copied the logic from JDT) is to parse the code into an AST, and then walk the AST in sync with a lexer.

My dfmt tool does something similar. The parser runs over the code first and makes notes on things like the location of unary operators and which braces end function/aggregate declarations. Then the formatter iterates over the tokens (including comments) and is able to correctly print "a* b;" instead of "a * b;".

Reply via email to