<p>Right now, I am using ClangFormat to format code written in my programming language, but that's not ideal, among other things, because <a href="https://langdev.stackexchange.com/q/1695/330">ClangFormat treats <code>:=</code> (assignment) as two different tokens</a>. So, how would I go about implementing the formatter for my programming language?</p>
<p>It seems to me that I cannot reuse the code from the tokenizer of my programming language, because <a href="https://sourceforge.net/p/aecforwebassembly/code/ci/master/tree/tokenizer.cpp" rel="nofollow noreferrer">the tokenizer for my programming language</a> deletes the comments, and I don't want to delete the comments from the code I am formatting. But don't I need to somehow parse the code I am formatting, to know how many tabs/spaces I should put before some token? How am I supposed to parse a code with comments in it?</p>

<tokens>
What would be the steps to implementing a formatter for your programming language?
# What would be the steps to implementing a formatter for your programming language?
Posted by: username_0 on 2023-07-13
Right now, I am using ClangFormat to format code written in my programming language, but that's not ideal, among other things, because [ClangFormat treats `:=` (assignment) as two different tokens](https://langdev.stackexchange.com/q/1695/330). So, how would I go about implementing the formatter for my programming language?

It seems to me that I cannot reuse the code from the tokenizer of my programming language, because [the tokenizer for my programming language](https://sourceforge.net/p/aecforwebassembly/code/ci/master/tree/tokenizer.cpp) deletes the comments, and I don't want to delete the comments from the code I am formatting. But don't I need to somehow parse the code I am formatting, to know how many tabs/spaces I should put before some token? How am I supposed to parse a code with comments in it?
**Tags:** tokens
---
## 0 answers
