dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support if (cond) do

dansanderson opened this issue · comments

Entirely by accident, Pico-8 supports an illegal variant of if (cond) then\n ... end that looks like if (cond) do\n ... end. This is a result of Pico-8's "short-if" feature accidentally accepting the multiline do block as if it were on a single line. If it's supported, people will use it (intentionally or otherwise), e.g. 16314, 16350, 16992, 16999, 17135, 17238, 17406, 17550.

Pico-8 is unlikely to remove support for this accident, so picotool should support it. Whether it needs to preserve it, I don't know. It's possible authors of old carts used this trick to reduce character count, though hopefully the relatively new emphasis on token count makes this obsolete. To preserve it, we'd need to extend the grammar. It might be easier to convert "do" to "then" and risk pushing carts over the limit, or it might not.

This is actually a result of Pico-8's implementation of short-if using a preprocessor pass. if (cond) do\n ... end becomes if (cond) then do end\n ... end, which works accidentally. If this is ever important, picotool should probably rewrite its short-if support to match Pico-8's preprocessor. I don't think it's a high priority.

picotool now supports if-do as if it were language syntax. This successfully parses carts that use this accidental syntax, though it does so differently from how Pico-8 does it.