[ create a new paste ] login | about

Link: http://codepad.org/GgHDzv75    [ raw code | output | fork ]

Lua, pasted on Aug 27:
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


Output:
1
2
3
let's see	if // breaks
key	value
otherKey	table: 0x8faf7b8


Create a new paste based on this one


Comments: