Adding D support to Clang format

Zachary Yedidia zyedidia at gmail.com
Fri Apr 28 23:30:37 UTC 2023


Clang format is a high quality auto-formatter developed by the 
LLVM project, mainly for use with C and C++, but it also supports 
Java, C#, JavaScript, JSON, Objective-C, Proto, TableGen, 
TextProto, and Verilog. I think it would be great to add support 
for D, and hopefully shouldn't be too difficult since it is a 
C-like language. Clang format has good support for aligning 
tokens (comments, assignments, etc), which is something important 
that existing D formatters (dfmt, sdfmt) don't support, and Clang 
format has many configuration options. Clang format also uses an 
incomplete parser, so it is relatively resilient to new language 
syntax and doesn't need a full D parser (and can format code with 
syntax errors for what it's worth).

I have started an implementation for D here: 
https://github.com/zyedidia/llvm-project/tree/clang-format-d, 
with some information about the implementation here (how to 
download/build/test): 
https://github.com/zyedidia/llvm-project/blob/clang-format-d/clang-format-d.md. There are still a number of things that are formatted incorrectly, so there is still work to do (I have added tests for the things I have noticed aren't working right). I'm not sure how much time I can dedicate to working on this, so any help would be appreciated. If we get to a point where this fork of clang-format has good support for D, then hopefully we could get these changes merged upstream into the LLVM project.


More information about the Digitalmars-d mailing list