Option to retain comments when compiling/decompiling Fennel/Lua

While working on a game in TIC I had to decompile bump.lua to Fennel with antifennel in order to include it in the Fennel version of the cart, and I had to restore comments manually, to make the code more readable and sectioned as the original.

Additionally to that, later I had to compile the Fennel cart to Lua because the current TIC-80 player on the tic-80.com doesn't support some features I used like fcollect and case which are already in the development version of TIC, and thus I had to restore all of the comments, containing sprites, waveforms, etc.

An option to keep the comments when compiling/decompiling would be very helpful.

Assigned to
9 months ago
7 months ago
antifennel enhancement

~technomancy 9 months ago

I've just pushed some changes to antifennel to support this on regular statement-level comments. Adding support for multi-line comments should be easy, but adding support for comments inside expression contexts (including tables) will undoubtedly be much more difficult. (I did the equivalent in fnlfmt, and it turned out to be one of the most difficult parts of the whole thing.) It is likely still possible to break antifennel now by putting a comment in an unexpected non-statement spot.


Doing this in fennel ... is quite hard. If you want the comments to be conveyed by the AST, then they have to take up space in the AST.

(each ; this next bit is an iterator
  [i (ipairs t)]
  (print i))

This is fine as long as all you're doing is parsing, but if the comment node exists in the AST then you'll get: "Compile error: expected binding table" because the comment node is the second element of the list.

So putting comments inside the AST will break everything. It would be necessary to find ... somewhere else for them, I guess? The metatable can't be used for this consistently across all places that comments can be, so you would need a weak table.

I have my doubts as to whether this can be done cleanly in the compiler. I would lean towards using a plugin for this.

~technomancy 9 months ago

I've pushed out further improvements on the antifennel side on the main branch; if you use antifennel please give them a try. Note that you have to include a --comments flag in the command in order to activate the new behavior.

~andreyorst 8 months ago

will check soon. Is it deployed to /see by chance?

~technomancy 7 months ago

No, I don't really trust it enough to turn it on by default yet, so See Fennel doesn't have it.

Register here or Log in to comment, or comment via email.