s = [[{
"key" "value"
"otherKey" { //C-style "comments" "to break?"
"moreKey" "moreValue"
{"let's see" "if // breaks" } //should it?}
} //no block comments!
"let's see" "if // breaks"
}]]
local function comment(w)
local r, m = w, w:match '(.+)//'
local t, _ = m:gsub( '"', '' )
if _ % 2 == 1 then return r else return m end
end
local function parser(x)
local r = x:gsub( "(.-)[\n\r]+",
function(w)
if w:match '//' then w = comment(w) end
w = w:gsub( '("[^"]+") {', '[%1] = {' )
w = w:gsub( '("[^"]+") ("[^"]+")', '[%1] = %2,' )
return w..'\n'
end
)
return loadstring( "return "..r:gsub('}', '},'):gsub(',$', '') )()
end
x = parser(s)
for k, v in pairs(x) do print( k, v ) end