mult-chk.lua /size: 2483 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
mult-chk
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to mult-chk.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
format
=
string
.
format
10
local
lpegmatch
=
lpeg
.
match
11
local
type
=
type
12 13
local
make_settings_to_hash_pattern
=
utilities
.
parsers
.
make_settings_to_hash_pattern
14
local
settings_to_set
=
utilities
.
parsers
.
settings_to_set
15
local
allocate
=
utilities
.
storage
.
allocate
16 17
local
report_interface
=
logs
.
reporter
(
"
interface
"
,
"
checking
"
)
18 19
local
interfaces
=
interfaces
20
local
implement
=
interfaces
.
implement
21 22
interfaces
.
syntax
=
allocate
{
23
test
=
{
keys
=
table
.
tohash
{
"
a
"
,
"
b
"
,
"
c
"
,
"
d
"
,
"
e
"
,
"
f
"
,
"
g
"
}
}
24
}
25 26
function
interfaces
.
invalidkey
(
category
,
key
)
27
report_interface
(
"
invalid key %a for %a in line %a
"
,
key
,
category
,
tex
.
inputlineno
)
28
end
29 30
function
interfaces
.
setvalidkeys
(
category
,
list
)
31
local
s
=
interfaces
.
syntax
[
category
]
32
if
not
s
then
33
interfaces
.
syntax
[
category
]
=
{
34
keys
=
settings_to_set
(
list
)
35
}
36
else
37
s
.
keys
=
settings_to_set
(
list
)
38
end
39
end
40 41
function
interfaces
.
addvalidkeys
(
category
,
list
)
42
local
s
=
interfaces
.
syntax
[
category
]
43
if
not
s
then
44
interfaces
.
syntax
[
category
]
=
{
45
keys
=
settings_to_set
(
list
)
46
}
47
else
48
settings_to_set
(
list
,
s
.
keys
)
49
end
50
end
51 52
implement
{
53
name
=
"
setvalidinterfacekeys
"
,
54
actions
=
interfaces
.
setvalidkeys
,
55
arguments
=
"
2 strings
"
56
}
57 58
implement
{
59
name
=
"
addvalidinterfacekeys
"
,
60
actions
=
interfaces
.
addvalidkeys
,
61
arguments
=
"
2 strings
"
62
}
63 64
-- weird code, looks incomplete ... probably an experiment
65 66
local
prefix
,
category
,
keys
67 68
local
setsomevalue
=
context
.
setsomevalue
69
local
invalidkey
=
interfaces
.
invalidkey
70 71
local
function
set
(
key
,
value
)
72
if
keys
and
not
keys
[
key
]
then
73
invalidkey
(
category
,
key
)
74
else
75
setsomevalue
(
prefix
,
key
,
value
)
76
end
77
end
78 79
local
pattern
=
make_settings_to_hash_pattern
(
set
,
"
tolerant
"
)
80 81
function
interfaces
.
getcheckedparameters
(
k
,
p
,
s
)
82
if
s
and
s
~
=
"
"
then
83
prefix
,
category
=
p
,
k
84
keys
=
k
and
k
~
=
"
"
and
interfaces
.
syntax
[
k
]
.
keys
85
lpegmatch
(
pattern
,
s
)
86
end
87
end
88 89
implement
{
90
name
=
"
getcheckedinterfaceparameters
"
,
91
actions
=
interfaces
.
getcheckedparameters
,
92
arguments
=
"
3 strings
"
93
}
94