[SAOC 2023] dfmt rewrite - Weekly update #12

Prajwal S N snp at dlang.org
Fri Dec 8 15:47:38 UTC 2023


Hi all,

I spent this week working on adding support for storing comments 
in DMD. The lexer currently stores doc comments along with the 
token, but ignores regular comments. A new `rawComment` field in 
`struct Token` is introduced, that gets populated during lexing. 
This feature is restricted to DMD as a library (`version (DMDLIB) 
{...}`) since it is effectively useless for the compiler itself. 
Now that the lexer provides this information, the parser can 
populate the AST nodes with it (again, only while using DMD as a 
library). This should now enable us to not lose comments while 
formatting with dmdfmt, although I'm yet to figure out how these 
comments will be inserted into the formatted output, and whether 
this strategy would work for inline comments, e.g. something like 
`fn foo(int a /* Arg 1 */, int b /* Arg 2 */)`.


More information about the Digitalmars-d mailing list