lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi list,

I'm working about convert Excel file into Lua table. And I
found xlsx.lua[1] module. I found it use a xmlize
module[2], to simplify process the complex structure of
nesting Lua tables.

If you have a table have very complex structure, to select
something from it become very difficult. Some code about
this:

```
    -- we want select all values in sheetData
    local result = {}
    for _, child in ipairs(sheetData) do
        if child.tag == "row" then
            for _, child in ipairs(child) do
                if child.tag == "c" then
                    result[#result+1] = child
                end
            end
        end
    end
```

In my code lifetime, these things are very normal in
writing Lua codes, but with something about Json Path[3],
it could be done in a very simple way:

```
    local result = table.match(sheetData,
        [[ $[?(@.tag=="row")][?(@.tag=="c")] ]])
```

It just like patterns, but using on tables. You can make
iteration, filtering, reduce and DFS/BFS algorithm on
table using Json Path. So I think a module like
lua-jsonpath may useful: and we already have one[4].

But as we know Json Path is designed for Json, not for
Lua.  Lua patterns are beautiful and powerful than PCRE,
maybe we could discuss a better syntax about it? Could we
make it's syntax more fit to Lua?

First it may implemented into a 3rd module, just like
struct module[5]. After we prove it's useful, it could
merge into table standard library, just like the
string.(un)pack[6] routines.

Any feedback are welcome :-)


[1]: https://github.com/jjensen/lua-xlsx
[2]: https://github.com/jjensen/lua-xmlize
[3]: http://goessner.net/articles/JsonPath/
[4]: https://github.com/mrpace2/lua-jsonpath
[5]: http://www.inf.puc-rio.br/~roberto/struct/
[6]: https://www.lua.org/manual/5.3/manual.html#6.4.2

-- 
regards,
Xavier Wang.