SquidDev / illuaminate

Very WIP static analysis for Lua
https://squiddev.cc/illuaminate/
BSD 3-Clause "New" or "Revised" License
49 stars 2 forks source link

Redundant parens fixer should add spaces #15

Open SquidDev opened 4 years ago

SquidDev commented 4 years ago

Consider the following:

print(not(a))

While somewhat dubious Lua, it is technically valid. However, when removing the redundant parenthesis, Lua rewrites this as the following, which is clearly not the same!

print(nota)
SquidDev commented 4 years ago

Another case where this occurs is the following:

do return(x)end

This will be much harder to fix. It's times like these I wish we had a zipper list of tokens on top of our AST. Maybe I should just give up and force the pretty printer to emit correct code here.

RGFTheCoder commented 3 years ago

why not replace them with spaces, and then do a pass to see if there are any double-spaces not at the start of a line

/(?:^\s*.*)\s\s+/

replaced with a single space