japhib / pico8-ls

PICO-8 Language Server
MIT License
64 stars 8 forks source link

Support one-line `while` statement #11

Open japhib opened 2 years ago

japhib commented 2 years ago

This is used in the jelpi.p8 demo cart. The line looks like this:

while (ta < a-.5) ta += 1

I think it's very similar to the single-line if statement.

miguno commented 1 year ago

I run across the same issue. PICO-8 extends standard Lua syntax with a few shorthands, including for single-line while and if statements: https://www.lexaloffle.com/dl/docs/pico-8_manual.html#PICO_8_Shorthand

Additional shorthands are operators like += and -=.

japhib commented 1 year ago

Everything else you mentioned is already supported, just the one line while loop is not yet

miguno commented 1 year ago

Yep, exactly.

rabensm commented 7 months ago

Any chance this could be prioritized? The "'do' expected" warnings are making me sad. (And yes, I'm working around it by adding do and end to my one-liners.)

I'd take a crack at a PR myself. I know Parser.parseWhileStatement‎ needs some special-case logic like this, but all the special edge cases and one-off manual finagling in there scares me a bit. A lot of that mess is dealing with the possible else block, though, so I'm guessing the logic for Parser.parseWhileStatement would be simpler.

japhib commented 7 months ago

Go for it! I haven't had much time to work on this myself but I'm happy to review PRs, and provide any pointers if you get stuck.