diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luakeys/luakeys-debug.sty | 2 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luakeys/luakeys.lua | 118 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luakeys/luakeys.sty | 2 |
3 files changed, 67 insertions, 55 deletions
diff --git a/Master/texmf-dist/tex/luatex/luakeys/luakeys-debug.sty b/Master/texmf-dist/tex/luatex/luakeys/luakeys-debug.sty index 1a26a664504..5f8cc808f52 100644 --- a/Master/texmf-dist/tex/luatex/luakeys/luakeys-debug.sty +++ b/Master/texmf-dist/tex/luatex/luakeys/luakeys-debug.sty @@ -17,6 +17,6 @@ % luakeys-debug.sty and luakeys-debug.tex. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{luakeys-debug}[2022/07/06 0.7.0 Debug package for luakeys.] +\ProvidesPackage{luakeys-debug}[2022/11/17 0.8.0 Debug package for luakeys.] \input luakeys-debug.tex diff --git a/Master/texmf-dist/tex/luatex/luakeys/luakeys.lua b/Master/texmf-dist/tex/luatex/luakeys/luakeys.lua index 3221fc3efdb..8b065289de8 100644 --- a/Master/texmf-dist/tex/luatex/luakeys/luakeys.lua +++ b/Master/texmf-dist/tex/luatex/luakeys/luakeys.lua @@ -172,15 +172,21 @@ local utils = { local namespace = { opts = { + assignment_operator = '=', convert_dimensions = false, debug = false, default = true, defaults = false, defs = false, format_keys = false, + group_begin = '{', + group_end = '}', hooks = {}, + list_separator = ',', naked_as_value = false, no_error = false, + quotation_begin = '"', + quotation_end = '"', unpack = true, }, @@ -224,6 +230,38 @@ local function throw_error(message) end end +--- Normalize the parse options. +--- +---@param opts? table # Options in a raw format. The table may be empty or some keys are not set. +--- +---@return table +local function normalize_opts(opts) + if type(opts) ~= 'table' then + opts = {} + end + for key, _ in pairs(opts) do + if namespace.opts[key] == nil then + throw_error('Unknown parse option: ' .. tostring(key) .. '!') + end + end + local old_opts = opts + opts = {} + for name, _ in pairs(namespace.opts) do + if old_opts[name] ~= nil then + opts[name] = old_opts[name] + else + opts[name] = default_options[name] + end + end + + for hook in pairs(opts.hooks) do + if namespace.hooks[hook] == nil then + throw_error('Unknown hook: ' .. tostring(hook) .. '!') + end + end + return opts +end + local l3_code_cctab = 10 --- Convert back to strings @@ -375,13 +413,12 @@ end --- * [TUGboat article: Parsing complex data formats in LuaTEX with LPEG](https://tug.or-g/TUGboat/tb40-2/tb125menke-Patterndf) --- ---@param initial_rule string # The name of the first rule of the grammar table passed to the `lpeg.P(attern)` function (e. g. `list`, `number`). ----@param convert_dimensions? boolean # Whether the dimensions should be converted to scaled points (by default `false`). +---@param opts? table # Whether the dimensions should be converted to scaled points (by default `false`). --- ---@return userdata # The parser. -local function generate_parser(initial_rule, - convert_dimensions) - if convert_dimensions == nil then - convert_dimensions = false +local function generate_parser(initial_rule, opts) + if type(opts) ~= 'table' then + opts = normalize_opts(opts) end local Variable = lpeg.V @@ -413,7 +450,7 @@ local function generate_parser(initial_rule, input = input:gsub('%s+', '') -- Convert the unit string into lowercase. input = input:lower() - if convert_dimensions then + if opts.convert_dimensions then return tex.sp(input) else return input @@ -458,7 +495,7 @@ local function generate_parser(initial_rule, -- '{' list '}' list_container = - ws('{') * Variable('list') * ws('}'), + ws(opts.group_begin) * Variable('list') * ws(opts.group_end), -- ( list_container / key_value_pair / value ) ','? list_item = @@ -466,11 +503,11 @@ local function generate_parser(initial_rule, Variable('list_container') + Variable('key_value_pair') + Variable('value') - ) * ws(',')^-1, + ) * ws(opts.list_separator)^-1, -- key '=' (list_container / value) key_value_pair = - (Variable('key') * ws('=')) * (Variable('list_container') + Variable('value')), + (Variable('key') * ws(opts.assignment_operator)) * (Variable('list_container') + Variable('value')), -- number / string_quoted / string_unquoted key = @@ -555,9 +592,9 @@ local function generate_parser(initial_rule, -- '"' ('\"' / !'"')* '"' string_quoted = - white_space^0 * Pattern('"') * - CaptureSimple((Pattern('\\"') + 1 - Pattern('"'))^0) * - Pattern('"') * white_space^0, + white_space^0 * Pattern(opts.quotation_begin) * + CaptureSimple((Pattern('\\' .. opts.quotation_end) + 1 - Pattern(opts.quotation_end))^0) * + Pattern(opts.quotation_end) * white_space^0, string_unquoted = white_space^0 * @@ -566,7 +603,11 @@ local function generate_parser(initial_rule, (Set(' \t')^1 * Variable('word_unquoted')^1)^0) * white_space^0, - word_unquoted = (1 - white_space - Set('{},='))^1 + word_unquoted = (1 - white_space - Set( + opts.group_begin .. + opts.group_end .. + opts.assignment_operator .. + opts.list_separator))^1 }) -- LuaFormatter on end @@ -614,7 +655,7 @@ local is = { if type(value) == 'boolean' then return true end - local parser = generate_parser('boolean_only', false) + local parser = generate_parser('boolean_only') local result = parser:match(tostring(value)) return result ~= nil end, @@ -623,7 +664,7 @@ local is = { if value == nil then return false end - local parser = generate_parser('dimension_only', false) + local parser = generate_parser('dimension_only') local result = parser:match(tostring(value)) return result ~= nil end, @@ -643,7 +684,7 @@ local is = { if type(value) == 'number' then return true end - local parser = generate_parser('number_only', false) + local parser = generate_parser('number_only') local result = parser:match(tostring(value)) return result ~= nil end, @@ -778,7 +819,10 @@ local function apply_definitions(defs, -- integer elseif def.data_type == 'integer' then if is.number(value) then - converted = math.floor(tonumber(value)) + local n = tonumber(value) + if type(n) == 'number' and n ~= nil then + converted = math.floor(n) + end end -- number elseif def.data_type == 'number' then @@ -1038,7 +1082,7 @@ end --- Parse a LaTeX/TeX style key-value string into a Lua table. --- ---@param kv_string string # A string in the TeX/LaTeX style key-value format as described above. ----@param opts table # A table containing the settings: +---@param opts? table # A table containing the settings: --- `convert_dimensions`, `unpack`, `naked_as_value`, `converter`, --- `debug`, `preprocess`, `postprocess`. -- @@ -1047,48 +1091,16 @@ end ---@return table raw # The unprocessed, raw result of the LPeg parser. local function parse(kv_string, opts) if kv_string == nil then - return {} + return {}, {}, {} end - --- Normalize the parse options. - --- - ---@param opts table # Options in a raw format. The table may be empty or some keys are not set. - --- - ---@return table - local function normalize_opts(opts) - if type(opts) ~= 'table' then - opts = {} - end - for key, _ in pairs(opts) do - if namespace.opts[key] == nil then - throw_error('Unknown parse option: ' .. tostring(key) .. '!') - end - end - local old_opts = opts - opts = {} - for name, _ in pairs(namespace.opts) do - if old_opts[name] ~= nil then - opts[name] = old_opts[name] - else - opts[name] = default_options[name] - end - end - - for hook in pairs(opts.hooks) do - if namespace.hooks[hook] == nil then - throw_error('Unknown hook: ' .. tostring(hook) .. '!') - end - end - return opts - end opts = normalize_opts(opts) if type(opts.hooks.kv_string) == 'function' then kv_string = opts.hooks.kv_string(kv_string) end - local result = generate_parser('list', opts.convert_dimensions):match( - kv_string) + local result = generate_parser('list', opts):match(kv_string) local raw = clone_table(result) local function apply_hook(name) @@ -1218,7 +1230,7 @@ local result_store = {} -- @section local export = { - version = { 0, 7, 0 }, + version = { 0, 8, 0 }, namespace = namespace, diff --git a/Master/texmf-dist/tex/luatex/luakeys/luakeys.sty b/Master/texmf-dist/tex/luatex/luakeys/luakeys.sty index d0917f1d9d5..68c3892ee43 100644 --- a/Master/texmf-dist/tex/luatex/luakeys/luakeys.sty +++ b/Master/texmf-dist/tex/luatex/luakeys/luakeys.sty @@ -17,5 +17,5 @@ % luakeys-debug.sty and luakeys-debug.tex. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{luakeys}[2022/07/06 0.7.0 Parsing key-value options using Lua.] +\ProvidesPackage{luakeys}[2022/11/17 0.8.0 Parsing key-value options using Lua.] \directlua{luakeys = require('luakeys')} |