Josef-Friedrich / luakeys

LuaTeX package to parse key value options in Lua only, like keyval, kvsetkeys, kvoptions, xkeyval, pgfkeys but in Lua

Home Page:https://www.ctan.org/pkg/luakeys

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: Add a "recursive=true/false" option

paternal opened this issue · comments

commented

Hello,
I am using your package to parse options, and I would like to select which keys are recursively parsed, and which are not. In my use case, one of the values is to be passed as-is as options of a tikzpicture environment, so I would like luakeys not to parse it. I would like something like:

parse = luakeys.define({
  tikz = {recursive=false},
  foo = {},
  bar = {},
})

options = parse("foo={one=1, two=2}, bar=baz, tikz={scale=2, red}")

Expected value for options:

{
  ["foo"] = { -- "foo" has been recursively parsed (the default)
    ["one"] = 1,
    ["two"] = 2,
  },
  ["bar"] = baz,
  ["tikz"] = "scale=2, red", -- "tikz" has not been parsed
}

Maybe it is possible to globally disable recursive parsing using hooks? I could not manage to do so…

Thanks for your work,
Louis

commented

I dug into the code and documentation, and:

  • there is a huge Pattern to match the key/value string, and adding a recursive option might mean having two separate huge Patterns (not cool);
  • the function render(result): string might do the trick. I still wonder if there are corner case where a string processed then rendered by luakeys might have a different "meaning" than the original case.

Conclusion: if it is easy to implement, it would be nice. If it is too much work, don't bother

I'm afraid it's not easy to implement.

You can use the process hook in combination with luakeys.render() as you mentioned:

local parse = luakeys.define({
  tikz = {
    process = function(value, input, result, unknown)
      return luakeys.render(value)
    end,
  },
  foo = {},
  bar = {},
})

or simply:

options = parse('foo={one=1, two=2}, bar=baz, tikz="scale=2, red"')
commented

I have tried with luakeys.render(), and it works. I will stick to it until I stumble upon a weird corner case where it no longer works.

Thanks
-- Louis