Is there a standard or popular WAT formatter?

Is there a standard or popular formatter for WAT code? I realize not a lot of people are writing wat by hand, but it’d be nice to have.

I’m not aware of one. Well, you could (ab)use wabt for this purpose: Run your wat code through wat2wasm and back through wasm2wat. However, the output of that is not really designed for optimal readability, as we are used to from our standardized formatters. As far as I can tell, it produces a flat sequence of instructions without any s-expressions.

One the one hand, I think it would be very easy to implement, since the syntax has such a low surface area. On the other hand, it could be really challenging, because making a decision about what the most readable formatting is is difficult.

The best formatting for C-style languages wasn’t obvious from the first day, the standard we have now has evolved over decades.

Maybe one would have to look at what the lisp family of languages is doing in terms of formatting. The s-expressions originate there. But the semantics of most lisps and wasm are very different.

New hobby project idea…? :joy:

2 Likes

I haven’t thought about it this way, but actually why not. I’m giving it a shot, thanks!