title: I need a tool to parse Lua tables, preferrably in Ruby or Java
body: <p>I need a tool to parse Lua table expressions. If all else fails, I will eventually just code a small Lua module to convert tables to XML, but for the time being, I am interested in a Ruby library doing that, but failing that, I would accept tool in any language, provided I can look at its source.</p>
  
  <p>Here is an example snippet (it's a WoW addon output):</p>
  
  <pre><code>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,
          },
  ...
  </code></pre>
  
  <p>Basic idea is, nested associative arrays. Any help or pointer will be examined, any idea is appreciated. </p>
  
  <p><code>EDIT #1</code></p>
  
  <p>Due to the disputes, let me clarify what did I try. I complemented the string/regex replacing chain provided by one of the participants, like so:</p>
  
  <pre><code>str.gsub(/--.+$/, "").gsub("=", ":").gsub(/[\[\]]/,"").gsub('" :','":').gsub(/,\s*\n(\s*)}/, "\n\\1}")
  </code></pre>
  
  <p>I (1) added removal of Lua comments, (2) replaced one of the regex replacers: when you have the last element in an object/array, it still has a comma after it, so that must be covered and the comma properly removed.</p>
  
  <p>Do you notice the <em>double opening curly braces</em>? JSON doesn't like having anonymous objects. It looks like that:</p>
  
  <pre><code>"xxx" = {
    {
      ["aaa"} = {
        ["bbb"] = {
          "ccc" = 7
          "ddd" = "a string"
          "eee" = "a date/time pattern"
        }
      },
      ["qqq"} = {
        "hm" = "something"
      }
    },
    {
      ["aaa"] = {
      -- ...
      },
      ["qqq"] = {
      -- ...
      }
    }
  }
  </code></pre>
  
  <p>Basically on the root level, we actually have a list/array of similar objects, both having "aaa" and "qqq" section, to follow the example. However, in Lua that is obviously allowed, while in JSON it isn't. Because the opening curly braces are treated like "start an object" but that object doesn't have a name.</p>
  
  <p>I tried to detect that case with regex and replace curly braces with "[]" pairs. While the resulting regex worked, the problem was the same: OK, we define an array of similar objects instead, but the declaration of the array is still nameless.</p>
  
  <p>A possible solution would be instead of detecting and replacing those braces with [], to christen the objects with indexes, like: <code>"0" = { "aaa" = {...} }, "1" = { "aaa" = {... } }</code>, etc. That (hopefully final) workaround will probably make it work... Will report back again. ;)</p>