I need a tool to parse Lua table expression expressions. If all else fails, I end up just encoding a small Lua module for converting tables to XML, but for now I'm interested in the Ruby library, but otherwise I would accept a tool in any language if I could look at its source.
Here is an example fragment (this is the output of a WoW addon):
CT_RaidTracker_RaidLog = { { ["PlayerInfos"] = { ["Nyim"] = { ["race"] = "Orc", ["guild"] = "Excubitores Noctae", ["sex"] = 2, ["class"] = "HUNTER", ["level"] = 70, }, ["Zyrn"] = { ["race"] = "BloodElf", ["guild"] = "Excubitores Noctae", ["sex"] = 2, ["class"] = "WARLOCK", ["level"] = 70, }, ...
The main idea is nested associative arrays. Any help or pointer will be considered, any idea appreciated.
EDIT #1
Due to controversy, let me clarify what I tried. I supplemented the string / regular expression replacement chain provided by one of the participants, for example:
str.gsub(/--.+$/, "").gsub("=", ":").gsub(/[\[\]]/,"").gsub('" :','":').gsub(/,\s*\n(\s*)}/, "\n\\1}")
I (1) added the removal of Lua comments, (2) replaced one of the regex replacers: when you have the last element in the object / array, it still has a comma after it, so it should be closed and the comma removed correctly.
Have you noticed the double opening braces? JSON does not like to have anonymous objects. It looks like this:
"xxx" = { { ["aaa"} = { ["bbb"] = { "ccc" = 7 "ddd" = "a string" "eee" = "a date/time pattern" } }, ["qqq"} = { "hm" = "something" } }, { ["aaa"] = { -- ... }, ["qqq"] = { -- ... } } }
Basically, at the root level, we actually have a list / array of similar objects that have aaa and qqq sections to follow suit. However, in Lua, this is obviously allowed, but in JSON it is not. Since opening curly braces are treated as "start an object", but this object does not have a name.
I tried to detect this case with a regex and replace the curly braces with the pairs “[]”. While the resulting resulting time worked, the problem was the same: OK, we are defining an array of similar objects, but the declaration of the array is still nameless.
A possible solution would be instead of finding and replacing these curly braces with [] to baptize objects with indexes, for example: "0" = { "aaa" = {...} }, "1" = { "aaa" = {... } } etc. This (hopefully final) workaround is likely to make it work ... Will report back .;)