Feature request: option on how to process standalone values
kalekje opened this issue · comments
I think a few of us might want an option on how to process standalone values. I think under the luakeys.parse
options table, an option for standaloneastrue
might be nice--instead of storing standalone values as integer-indexed values, I would like to see them as keys with a value set to true.
Ex: a,b,c,X=1,Y=2,Z=3
would produce a table like so:
Y 2
b true
Z 3
c true
X 1
a true
I made a simple function to patch this up for my own use.
local t_new = {}
for k, v in pairs(t) do
if type(k) == 'number' then
t_new[v] = true
else
t_new[k] = v
end
end
return t_new
I added a new option called standalone_as_key
I looked through the code and I think it's actually called standalone_as_true
, something to keep in mind if you update the documentation. Thanks for adding this feature--I will have to test if it works for nested key-vals as well. To me, parsing key-val options as LaTeX options makes sense this way. But the default was is great if you want a Lua table (maybe you want to declare a table in TeX) because the syntax maps basically 1 to 1. Very nice!
Maybe standalone_as_key
or even standalone_string_as_key
is a better name for this option. standalone_as_true
should work recursively.
Maybe the following new option (a callback function / hook) is also interesting for you:
luakeys.parse(
'one,two,three={four}',
{
converter = function (key, value, depth, current_table, root_table)
if type(key) == 'number' and type(value) == 'string' then
return value, true -- the value is now key, true is now the new value
end
return key, value -- return key, value to change nothing
end
}
)
--> {one = true, two = true, three = {four = true}}
The feature still exists. Check out this lines:
Lines 461 to 463 in 6d5e676
I think there was a misunderstanding. I have added the additional option converter
that might be useful for you. I have implemented the option standalone_as_true
as you requested.
Lines 369 to 371 in 6d5e676
luakeys/test/lua/public-functions.lua
Lines 105 to 116 in 9593ab4
However, the documentation is still missing
Breaking change in v0.6
Standalone values are now interpreted as naked keys by default and set to true. To get the old behavior back us { naked_as_value = true }