ClangFormat does a relatively good job formatting code written in my programming language. However, one quirky problem is that it inserts whitespace (sometimes even new-line characters) between :
and =
in my assignment operator :=
, like here. That does not prevent programs from being compiled, as the tokenizer for my programming language ignores whitespace between :
and =
, but it looks ugly. Is there a way to tell ClangFormat not to do that? Or do I have to write a formatter for my programming language myself? And, if so, how?
-
$\begingroup$ If you're asking about how to configure or add support for your language to ClangFormat, I'm afraid this question may be more on-topic on Stack Overflow. A question about designing your own formatter from scratch might be better on PLDI. $\endgroup$– userCommented Jun 27, 2023 at 21:33
-
2$\begingroup$ @user I'm pretty sure we've decided at least once that questions about using language design-specific software tools is perfectly on-topic...lemme find the post(s) $\endgroup$– rydwolfCommented Jun 27, 2023 at 21:39
-
3$\begingroup$ It seems on-topic to me, but I suspect the answer is that ClangFormat is not designed for this and it is not the right tool for the job. According to the docs, ClangFormat is "A tool to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code." It does not appear to be a tool that is designed to be configurable for arbitrary other languages. $\endgroup$– kaya3Commented Jun 27, 2023 at 21:43
-
1$\begingroup$ Note to close vote reviewers: ^ is not a reason to VTC this as off-topic, just an answer of "it's not possible"/a frame challenge $\endgroup$– rydwolfCommented Jun 28, 2023 at 3:16
-
1$\begingroup$ I disagree with the meta discussion and am voting to close this question in spite of it. I think this question is too specific a question about too specific a tool to be of general use to programming language designers and implementers other than the OP, so it shouldn't be on-topic here. $\endgroup$– pxegerCommented Jul 10, 2023 at 18:14
1 Answer
According to the docs, ClangFormat is
A tool to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
It does not appear to be a tool that is designed to be configurable for arbitrary other languages, so as far as I can tell, the answer is that there isn't an intended way to tell it the syntax for your own language.
Otherwise, the answer seems to be to write your own formatter, or to fork ClangFormat in order to support your language.