Repository: boolangery/py-lua-parser

Issue:
Rendering Some Lua Tables False
**Example code:**
```lua 
local Table = {"a", "b", "c"};
```

**I have used ast.to_lua_source for turning the ast into a lua code**
**The output i got:**
```lua
local Table = {
    1 = "a",
    2 = "b",
    3 = "c",
}
;
```

**What it should be:**
```lua
local Table = {
    [1] = "a",
    [2] = "b",
    [3] = "c",
}
;
```


**Used python code:**
```py
from luaparser import ast

src = """
local Table = {"a", "b", "c"};
"""

tree = ast.parse(src)
print(ast.to_lua_source(tree))
```

Discussion:

Patch:
diff --git a/luaparser/builder.py b/luaparser/builder.py
index 490b369..f6e8289 100644
--- a/luaparser/builder.py
+++ b/luaparser/builder.py
@@ -1472,6 +1472,7 @@ class Builder:
                     for field in fields:
                         if field.key is None:
                             field.key = Number(array_like_index)
+                            field.between_brackets = True
                             array_like_index += 1
 
                 return Table(fields or [])


Test patch:
diff --git a/luaparser/tests/test_comments.py b/luaparser/tests/test_comments.py
index 177c9d5..4d4c04b 100644
--- a/luaparser/tests/test_comments.py
+++ b/luaparser/tests/test_comments.py
@@ -143,6 +143,7 @@ class CommentsTestCase(tests.TestCase):
                                         Number(1),
                                         String("foo", StringDelimiter.DOUBLE_QUOTE),
                                         comments=[Comment("-- just a value")],
+                                        between_brackets=True,
                                     ),
                                     Field(
                                         Number(2),
@@ -151,6 +152,7 @@ class CommentsTestCase(tests.TestCase):
                                             Comment("-- last"),
                                             Comment("-- toto value"),
                                         ],
+                                        between_brackets=True,
                                     ),
                                     Field(
                                         Name("Model"),
diff --git a/luaparser/tests/test_expressions.py b/luaparser/tests/test_expressions.py
index fa86b2a..0bfe6cb 100644
--- a/luaparser/tests/test_expressions.py
+++ b/luaparser/tests/test_expressions.py
@@ -454,18 +454,18 @@ class ExpressionsTestCase(tests.TestCase):
                         values=[
                             Table(
                                 [
-                                    Field(Number(1), Number(1)),
-                                    Field(Number(2), Number(2)),
-                                    Field(Number(3), Number(4)),
-                                    Field(Number(4), Number(8)),
-                                    Field(Number(5), Number(16)),
-                                    Field(Number(6), Number(32)),
-                                    Field(Number(7), Number(64)),
-                                    Field(Number(8), Number(128)),
-                                    Field(Number(9), Number(256)),
-                                    Field(Number(10), Number(512)),
-                                    Field(Number(11), Number(1024)),
-                                    Field(Number(12), Number(2048)),
+                                    Field(Number(1), Number(1), between_brackets=True),
+                                    Field(Number(2), Number(2), between_brackets=True),
+                                    Field(Number(3), Number(4), between_brackets=True),
+                                    Field(Number(4), Number(8), between_brackets=True),
+                                    Field(Number(5), Number(16), between_brackets=True),
+                                    Field(Number(6), Number(32), between_brackets=True),
+                                    Field(Number(7), Number(64), between_brackets=True),
+                                    Field(Number(8), Number(128), between_brackets=True),
+                                    Field(Number(9), Number(256), between_brackets=True),
+                                    Field(Number(10), Number(512), between_brackets=True),
+                                    Field(Number(11), Number(1024), between_brackets=True),
+                                    Field(Number(12), Number(2048), between_brackets=True),
                                 ]
                             )
                         ],
@@ -504,8 +504,9 @@ class ExpressionsTestCase(tests.TestCase):
                                     Field(
                                         Number(1),
                                         String("enabled", StringDelimiter.DOUBLE_QUOTE),
+                                        between_brackets=True,
                                     ),
-                                    Field(Number(2), Number(157)),
+                                    Field(Number(2), Number(157), between_brackets=True),
                                     Field(
                                         TrueExpr(), FalseExpr(), between_brackets=True
                                     ),