<p>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 <code>:</code> and <code>=</code> in my assignment operator <code>:=</code>, like <a href="https://github.com/FlatAssembler/AECforWebAssembly/blob/9551fd35d6165040ca9b1356707bd63c99077583/analogClock/analogClock.aec#L108" rel="noreferrer">here</a>. That does not prevent programs from being compiled, as the tokenizer for my programming language ignores whitespace between <code>:</code> and <code>=</code>, 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?</p>

<llvm>
How do I explain to ClangFormat that `:=` is an assignment operator in my programming language, rather than label+assignment?
CC BY-SA 4.0
2023-06-27T21:33:34.430Z
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.
user
CC BY-SA 4.0
2023-06-27T21:39:16.523Z
@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)
rydwolf
CC BY-SA 4.0
2023-06-27T21:43:09.630Z
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](https://clang.llvm.org/docs/ClangFormat.html), 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.
kaya3
CC BY-SA 4.0
2023-06-28T03:16:21.640Z
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
rydwolf
CC BY-SA 4.0
2023-07-10T18:06:44.827Z
Since this seems to be in the VTC queue again, reminder that we've discussed this on Meta and have decided it is on-topic
rydwolf
CC BY-SA 4.0
2023-07-10T18:14:08.473Z
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.
pxeger
CC BY-SA 4.0
2023-07-10T19:52:45.583Z
@pxeger Where can I find that Meta discussion?
FlatAssembler
CC BY-SA 4.0
2023-07-10T20:01:22.053Z
@FlatAssembler https://langdev.meta.stackexchange.com/q/417
pxeger
CC BY-SA 4.0
2023-07-27T20:52:07.163Z
@pxeger I agree in principle, but I also think the question can in principle be understood more broadly: it's generally about making the tool treat two symbols as a single operator when it doesn't already have a hard-coded rule to do so. Assuming the one answer so far is correct, the warning of unsuitability will be useful information for others who sought to use the same tool to do related things.
Karl Knechtel
<p>According to <a href="https://clang.llvm.org/docs/ClangFormat.html" rel="noreferrer">the docs</a>, ClangFormat is</p>
<blockquote>
<p>A tool to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.</p>
</blockquote>
<p>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.</p>
<p>Otherwise, the answer seems to be to write your own formatter, or to fork ClangFormat in order to support your language.</p>

CC BY-SA 4.0
2023-07-27T20:44:47.450Z
2023-07-27T20:44:47.450Z
kaya3
# How do I explain to ClangFormat that `:=` is an assignment operator in my programming language, rather than label+assignment?
Posted by: username_0 on 2023-06-27
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](https://github.com/FlatAssembler/AECforWebAssembly/blob/9551fd35d6165040ca9b1356707bd63c99077583/analogClock/analogClock.aec#L108). 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?
**Tags:** llvm
> **Comments:**
> **username_1**: 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.  
> **username_2**: @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)  
> **username_3**: 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](https://clang.llvm.org/docs/ClangFormat.html), 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.  
> **username_2**: 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  
> **username_2**: Since this seems to be in the VTC queue again, reminder that we've discussed this on Meta and have decided it is on-topic  
> **username_4**: 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.  
> **username_0**: @pxeger Where can I find that Meta discussion?  
> **username_4**: @FlatAssembler https://langdev.meta.stackexchange.com/q/417  
> **username_5**: @pxeger I agree in principle, but I also think the question can in principle be understood more broadly: it's generally about making the tool treat two symbols as a single operator when it doesn't already have a hard-coded rule to do so. Assuming the one answer so far is correct, the warning of unsuitability will be useful information for others who sought to use the same tool to do related things.  
---
## 1 answers
### Answer by username_3 on 2023-07-27. Score: 6 | Accepted answer
According to [the docs](https://clang.llvm.org/docs/ClangFormat.html), 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.
---
