Hi, I just released Depicofier, which converts PICO-8's syntax to regular Lua syntax. I looked at a couple existing solutions but they didn't work for me, so I made this. It's open source under the MIT license on Github.
It should be feature complete, but if I missed anything please let me know.
Depicofier
Converts/translates PICO-8 style Lua syntax to standard clean Lua syntax. Download the latest release here.
This tool uses a publicly available and well-tested Lua language grammar to parse PICO-8 source code, so that any enhanced or special syntax or shorthand will only be converted where it should be.
If you like this tool please consider kicking me a dollar on Patreon.
Usage
Depicofier.exe [inFile] [outFile] Or to output source to console: Depicofier.exe [inFile] -print Switches: -strict Print warnings for Lua syntax not found in Pico 8 such as binary operators, integer division, and bitwise shifts |
Interesting approach. The PICO-8 specializations are all implemented internally as a line-based preprocessing step and have line-based behaviors. Is it possible to implement line endings in these grammars? (I notice it doesn't do short-ifs yet.)
Other implementations, for comparison:
Cool to see an increased interest in using Lua processing tools with PICO-8!
It does do short-ifs and the print shorthand, but I realized it would be extremely hard to implement in the Lua grammar via ANTLR, because it cares about line endings and Lua's grammar does not. Instead I process those two cases line-by-line. I still use the Lua grammar for them, but I only look at tokens for them.
I had issues with what appeared to be if shorthand edge cases in picotool's --pure-lua flag. I'm sure with time those'll be solved but it was easier for me to create my own than try and figure out where picotool's parser was going wrong for me.
I also looked at pico8-to-lua, but noticed it uses regex so it has no context awareness, which made me incredibly nervous about using it.
Looks cool. I wonder if it would be possible the opposite: Lua to P8. I would imagine a lot of cross compilers like moonscript, fennel, teal, etc are targeting canonical lua, but could run on P8 with slight modifications. Also, some libraries take a bit of work to get running on p8. I have written small "compat" files and sed scripts before, but never got beyond a clunky manual process.
[Please log in to post a comment]