dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php
MIT License
367 stars 46 forks source link

Parser should accept Lua paren-less function calls with a single string or table literal #86

Open dansanderson opened 2 years ago

dansanderson commented 2 years ago

Lua allows parentheses to be omitted from a function call if there is exactly one argument and the argument is a string or table literal. picotool does not yet support this case. PICO-8 supports it and offers a one-token discount compared to a similar call with parentheses.

function foo(arg) ... end

foo"single string argument"
foo{a=1, b=2, c=3}

I'm not sure how important this is to support, but I'm creating an issue for it just so we can track it. Upvotes and feedback welcome.

Liquidream commented 2 years ago

Alas, I do rely on this trick quite a lot in my luamin-ified code quite a lot (every token counts!) So, I would definitely be keen on this being supported.

FWIW, I thought it already did (as it seems I'm only using the string param method so far, and the minified output seems to preserve it... so far!)

dansanderson commented 2 years ago

@Liquidream It works fine with luamin! This bug is specific to the Lua parser. luamin operates directly on the token stream and doesn't use the parser.

blurble end do blah{x=1} blurble sspr

isn't valid Lua but luamin is happy to minify that to

a end do b{c=1} a sspr
Liquidream commented 2 years ago

Ah... my bad (explains why I never thought it was an issue 🤦‍♂️) *HidesInShame* 🙈