Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 2b068e3

Browse files
committed
update luakeyval
1 parent 8e0f39c commit 2b068e3

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

build.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ packtdszip = true
2020

2121
checkconfigs = {
2222
"configfiles/config-optex",
23+
"configfiles/config-optex2",
2324
"configfiles/config-latex",
25+
"configfiles/config-latex2",
2426
"configfiles/config-plain",
2527
"configfiles/config-nil",
2628
}

luakeyval.lua

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,55 @@
55
local put_next = token.unchecked_put_next
66
local get_next = token.get_next
77
local scan_toks = token.scan_toks
8-
local scan_keyword = token.scan_keyword
8+
local scan_keyword = token.scan_keyword_cs
99

1010
local relax = token.new(token.biggest_char() + 1)
11-
local texerror, uni_char = tex.error, utf8.char
11+
local texerror, utfchar = tex.error, utf8.char
1212
local format = string.format
13-
local function check_delimiter(str1, str2, key)
13+
14+
local function check_delimiter(error1, error2, key)
1415
local tok = get_next()
1516
if tok.tok ~= relax.tok then
16-
local tok_name = tok.csname or uni_char(tok.mode)
17-
texerror(format(str1, key, tok_name),{format(str2, key, tok_name)})
17+
local tok_name = tok.csname or utfchar(tok.mode)
18+
texerror(format(error1, key, tok_name),{format(error2, key, tok_name)})
1819
put_next({tok})
1920
end
2021
end
2122

2223
local unpack, insert = table.unpack, table.insert
23-
local function process_keys(tbl, str1, str2)
24+
local function process_keys(keys, messages)
25+
local matched, vals, curr_key = true, { }
26+
local value_forbidden = messages.value_forbidden
27+
or "luakeyval: the %s key does not accept a value"
28+
local value_required = messages.value_required
29+
or "luakeyval: the %s key require a value"
30+
local error1 = messages.error1
31+
or "wrong syntax when processing keys"
32+
local error2 = messages.error2
33+
or 'the last scanned key was "%s".\nthere is a "%s" in the way.'
2434
local toks = scan_toks()
25-
insert(toks, relax)
35+
insert(toks, relax)
2636
put_next(toks)
27-
local matched, vals = true, { }
28-
local curr_key
2937
while matched do
30-
matched = false
31-
for key, param in pairs(tbl) do
32-
if scan_keyword(key) then
33-
matched = true
34-
curr_key = key
35-
local args = param.args or {}
36-
local scanner = param.scanner
37-
local val = scan_keyword('=') and
38-
(scanner and scanner(unpack(args)) or true) or
39-
(param.default or true)
40-
local func = param.func
41-
if func then func(key,val) end
42-
vals[key] = val
43-
break
44-
end
45-
end
38+
matched = false
39+
for key, param in pairs(keys) do
40+
if scan_keyword(key) then
41+
matched = true
42+
curr_key = key
43+
local args = param.args or { }
44+
local scanner = param.scanner
45+
local val = scan_keyword('=') and
46+
(scanner and scanner(unpack(args)) or texerror(format(value_forbidden, key)))
47+
or (param.default or texerror(format(value_required, key)))
48+
local func = param.func
49+
if func then func(key,val) end
50+
vals[key] = val
51+
break
52+
end
53+
end
4654
end
47-
check_delimiter(str1, str2, curr_key)
48-
return vals
55+
check_delimiter(error1, error2, curr_key)
56+
return vals
4957
end
5058

5159
local function scan_choice(...)
@@ -59,14 +67,14 @@ end
5967

6068
local function scan_bool()
6169
if scan_keyword('true') then
62-
return true
70+
return true
6371
elseif scan_keyword('flase') then
6472
return false
65-
end
73+
end
6674
end
6775

6876
return {
6977
process = process_keys,
70-
choices = scan_choice,
71-
bool = scan_bool,
78+
choices = scan_choice,
79+
bool = scan_bool,
7280
}

lualineno.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ local scan_keyword = token.scan_keyword
2525
local keyval = require('luakeyval')
2626
local scan_choice = keyval.choices
2727
local process_keys = keyval.process
28+
local messages = {
29+
error1 = "lualineno: wrong syntax in \\lualineno",
30+
value_forbidden = "lualineno: the %s key does not accept a value",
31+
value_rquired = "lualineno: the %s key require a value",
32+
}
2833

2934
local setattribute = tex.setattribute
3035
local type_attr = luatexbase and luatexbase.new_attribute('lualineno_type') or 0
@@ -101,9 +106,7 @@ the last scanned key was "%s".
101106
there is a "%s" in the way.
102107
]]
103108
local function set_defaults()
104-
local vals = process_keys(defaults_keys,
105-
"lualineno: wrong syntax when setting defaults",
106-
help_message)
109+
local vals = process_keys(defaults_keys,messages)
107110
for k,v in pairs(vals) do
108111
defaults[k] = v
109112
end
@@ -120,9 +123,7 @@ local function define_lineno()
120123
-- This function is used in the define key.
121124
-- It is very similar to the set_defaults() function,
122125
-- but it accepts a `column` and `name` keys as well.
123-
local vals = process_keys(define_keys,
124-
"lualineno: wrong syntax when defining a lineno",
125-
help_message)
126+
local vals = process_keys(define_keys,messages)
126127
-- A newly defined lualineno type must have a name
127128
local name = vals['name']
128129
if not name then
@@ -210,10 +211,10 @@ end
210211

211212
local lualineno_keys = {
212213
set = {scanner = scan_string},
213-
unset = { },
214+
unset = { default = true },
214215
define = {func = define_lineno},
215216
defaults = {func = set_defaults},
216-
anchor = { },
217+
anchor = { default = true },
217218
label = {scanner = scan_toks, args = {false, true}},
218219
line_attr = {scanner = scan_int},
219220
col_attr = {scanner = scan_int},
@@ -224,9 +225,7 @@ local find_line
224225
local function lualineno()
225226
local saved_endlinechar = tex.endlinechar
226227
tex.endlinechar = 32
227-
local vals = process_keys(lualineno_keys,
228-
"lualineno: wrong syntax in \\lualineno",
229-
help_message)
228+
local vals = process_keys(lualineno_keys,messages)
230229
tex.endlinechar = saved_endlinechar
231230
if vals.set then
232231
local attr = lineno_attr[vals.set]

0 commit comments

Comments
 (0)