LuaFormatter icon indicating copy to clipboard operation
LuaFormatter copied to clipboard

Syntax error from long string inside table constructor brackets

Open hugomg opened this issue 2 years ago • 1 comments
trafficstars

LuaFormatter version 1.3.6 produces invalid output if the input program contains a [[ string inside a [ ] = table constructor.

t = { [ [[abc]] ] = 1}

When we format this, the spaces are removed and the result is a syntax error

t = {[[[abc]]] = 1}

The good news is that LuaFormatter already does the right thing for array brackets such as xs[ [[abc]] ]. Perhaps whatever logic is being used there should also be used for table constructors.

hugomg avatar Oct 28 '23 05:10 hugomg

For reference, I think the parts responsible for writing arrays and fields are these ones:

https://github.com/Koihik/LuaFormatter/blob/29afe1046ad015de96ffdb6d361a21882356e801/src/visitor/var.cpp#L54-L70

https://github.com/Koihik/LuaFormatter/blob/29afe1046ad015de96ffdb6d361a21882356e801/src/visitor/table.cpp#L199-L211

hugomg avatar Oct 28 '23 20:10 hugomg